Material Lerp Depending on orientation?

Is there a way to get an object’s yaw value in a material- and use it to change the colour of the material? I tried using the object orientation node and masking out the blue value but couldn’t get it to work how I needed. I was trying to have my lerp change from 0 to 1 when rotated 90 deg. along yaw, and then from 1 to 0 when rotated another 90 deg. -If that makes any sense.
Thankyou for any help

You should check out the FoliageZRotation node. Even though it says it’s for foliage, it seems to work fine on non-foliage materials. It outputs a 0 to 1 value based on the current Z rotation. I made a test material and the only change I made to the newly created asset was setting the Base Color to the output of the FoliageZRotation, like this:

Here are the test results:

Z rotation = 0

Z rotation = 45

Z rotation = 275

Since this outputs a 0-1 value, you can easily flip it for a 1-0 value using the OneMinus node. For the difference at each 90 degree interval, you’d probably be best off using if nodes to check those. Do note that the output is only smooth when rotating clockwise around Z. If you go from 0 to -359 by rotating counterclockwise, it will be a harsh jump from 0 to 1 rather than a smooth increase.

I hope this helps!

So a quick update, I looked inside the FoliageZRotation function and found it’s actually really simple, so you can probably modify this setup for getting other axis rotations if you need them:

If I’m reading this correctly, all this function does is transform the forward vector from local to world space, then converts it to an angle, which has the value range of 0-1.

Thank you so much for the help

The foliage z rotation node was exactly what I needed.