Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CallToAdventure · Apr 19, 2011 at 12:18 PM · textureoffsetbumpmap

Texture Offset - bump AND main color

I am trying to animate a texture - well, I do animate it but the bump map on the texture stays behind. Here's what I tried (and nothing happens);

float diff = 0.2f;          
if(localVelocity.z < 0)
    {
        cog.material.mainTextureOffset += new Vector2(0.0f, velocity * (1-localVelocity.x*diff));
        cog.renderer.material.SetTextureOffset("_BumpMap", new Vector2(0.0f, velocity * (1+localVelocity.x*diff)));

The documentation is rather sparse on examples, and the code is a tad more complex than I am used to play with (artist - not coder, please understand : )

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Owen-Reynolds · Apr 19, 2011 at 03:04 PM

One problem, maybe not all of them. Your MainTex line adds velocity, but your BumpMap line says the offset IS the veocity. A speedometer rather than an odometer. You should be seeing the bumpMap wiggle a tiny bit as you change speed. There's no += for secondary textures, but you can do it the long way:

Vector2 bOff = cog.renderer.material.GetTextureOffset("_BumpMap");
bOff.y += velocity * (1-localVelocity.x*diff); // same thing you were adding to mainTex
// throw in a multiplier, above, if the textures aren't scaled the same
cog.renderer.material.SetTextureOffset("_BumpMap", bOff);
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image taoa · Apr 19, 2011 at 03:09 PM 0
Share

I think you nailed it! :)

avatar image CallToAdventure · Apr 19, 2011 at 06:05 PM 0
Share

yes sir, works awesomely! Is it possible to also rotate a third cog based on the same velocity? I know - it's a weird setup :)

avatar image Owen-Reynolds · Apr 21, 2011 at 02:43 AM 0
Share

Seems that trick would work on any texture in a material (ins$$anonymous$$d of _Bump$$anonymous$$ap.) I believe materials are copied, so someone else with the same material could use similar code to move theirs a different way.

avatar image
0
Best Answer

Answer by Kourosh · Apr 19, 2011 at 12:25 PM

I'm not sure, just guessing, maybe your shader uses a different name instead of "_BumpMap". If so, then you need to open up your shader and check the name.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CallToAdventure · Apr 19, 2011 at 02:24 PM 0
Share

its a default shader from stock unity. I am applying it on both because there's a difference (two cogs - left and right) and at some point one texture is offset more rapidly;

avatar image
2

Answer by taoa · Apr 19, 2011 at 12:49 PM

Assuming you're using one of Unity's built-in shaders, this will mean you have different UV sets for each texture. So it makes sense to do what you did and apply the offset on both.

I'm actually surprised from your code that it works on the main texture because you don't even go through the renderer to reach your material. Have you tried doing the same thing for the bump map, removing .render completely?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CallToAdventure · Apr 19, 2011 at 01:09 PM 0
Share

with/without .renderer I get the same result: no offset. However initially in the else part I had to put in what does :

cog.material.mainTextureOffset -= new Vector2(0.0f, velocity * (1-localVelocity.x*diff));

I tried completing the bit of code there, no result.

avatar image taoa · Apr 19, 2011 at 02:44 PM 0
Share

Could you tell us what shader you use? I'll try it here, see what I can get.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

can't offset normal map 1 Answer

What do the texture tiling and offset values relate too? 3 Answers

Using Rpg maker XP Tiles (2D Tile System) 2 Answers

Assigning UV Map to model at runtime 0 Answers

Texture offsetting it's self 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges