How to change texture's offset speed based on custom rotation?

Any material pros here? Sigh, I cannot figure out how to change texture’s offset speed and direction depending on which angle the texture is rotated. Is it even possible to do it in shader? I have a custom texture rotation that will be changed via script and according to that rotation I need the shader to tweak the offset values every time the rotation changes. I am not sure how to do that, I have been sitting on this the whole day looking at vector math and I am already in tears :sob:

I’m using Shadergraph in Unity but anything will help, thanks.

1 Like

I want this post to flame because I know I’ll probably want to do something similar in the future :sweat_smile:

By the way how are you feeding the Texture Rotation into the shader? Are you using Rotate Node?

1 Like

I had help from a developer who understands maths… Here it is! I used Amplify though.

So basically what happens is that you convert an angle to a heading vector.

If you have an angle (A), in radians, in the range -Pi to Pi, then convert it to a vector (V) with:

V.x = cos(A)
V.y = sin(A)

Math taken from this link.

So you get a vector from the angle and then you multiply it with speed. I then further did multiplication with W so that the texture scroll would happen always from the same place and not start at a random position since it infinitely scrolls. There is also another branch from the vector which is multiplication with offset values since I want to offset the texture a bit as it is also being rotated. Also at the start we also add additional 90 degrees to offset the vector because we are using the same value in the rotator.

Prayers have been answered :pray: