# Offset textures individually into specific world directions

I am new to Unity and experimenting a bit with shaders, but now I’m stuck. So I hope you nice people can help me out.

My Scene has a simple cube with a texture assigned to it. So what I am doing is changing the offset of the texture over time, so the texture is moving down (easy, I know). But in that situation I do NOT want the top and bottom texture of the cube to move, only those on the side which are affected by lets say “world gravity”, that drags them down. Is it possible to make some textures at the sides move and some (at top and bottom) not?

This even gets more complicated, when the cube is being rotated. The “gravity” effect would need to change for the textures, so they are being dragged into the right (world) direction (that means still down). (On the other hand, I don’t want the textures to rotate with the object, but that’s far less important to me at the moment. But any hint is also appreciated.) I thought it would be better to illustrate what I mean.

So I have no idea how to make the texture behave different for each side of the cube. Any help is appreciated!

It is posible to do it in several ways:

First: simply keep a single “offset” vector and then project that offset on each plane in the vertex shader. Simply taking normal of each vertex into account will give you an offset of UV on the vertex. It is easy to implement, but it might be nor exactly what you want, because each plane will be unable to keep it’s ofset once the object rotates.

Second: put different materials on each side and calculate texture offset in the script. Offset of each side is calcualted in the same way. This will allow you to keep offset on each side.

OK I think I’ve got it, at least it looks correct. Was even easier than I thought.

``````float3 dir = normalize(mul( _World2Object, float4(0, 1, 0, 0) ).xyz);
temp.xyzw = v.vertex.xyzw + Offset * float4(dir,0);
``````