- Home /
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!
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);
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 :)
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.
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.
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;
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?
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.
Could you tell us what shader you use? I'll try it here, see what I can get.
Your answer
Follow this Question
Related Questions
can't offset normal map 1 Answer
Normal maps problem 1 Answer
mainTextureOffset not updating via script 1 Answer
bump maping and texturing 2 Answers
Any way to export generated bump map from the Editor? 1 Answer