How to use rotation of an object as the input to a color ramp?

Hello everybody.

I am trying to construct a node setup for cycles that uses the rotation of an object to determine the color of its shader. It should work something like the example below, only for rotation instead of location.



I want to use it for a scripted construction and animation of something like this:

Is there any node I have overlooked or does anybody have an idea for a workaround?

Thanks in advance,

After some digging, the only thing I could come up with is the Attribute node and ‘N’, which provides an object normal vector. We can convert that to a World vector and then take the dot-product of the two and have a rotation-derived scalar. But the normal vector is calculated based on the shading point, so, we can’t affect the whole model evenly. Plugged into our color ramp the model indeed changes color based on rotation, but surfaces orthogonal to the axis of rotation don’t change, so, your objects will be multiple colors.

Workarounds… can you not drive the value of the fac input of your color ramp the same way you are driving rotation?

Aha, we can drive the color ramp directly from object rotation. They key property here is rotation_euler[0] which corresponds to the rotation of our object on the x axis.

The math nodes are a quick & dirty absolute value and normalization for the color ramp. This will place an object with 0 rotation in the middle of the ramp, rotating negative degrees will take it toward blue, positive toward red…

If your rotation is not axis aligned, you’ll need to drive all three properties and do the necessary math with them :smiley:
I attached the blend if you like to take a look.


rotation_driven_color.blend (535 KB)

Hi Daniel,

thanks a lot, the workaround with the driver works nicely for my case.

One problem that remains is that, if I understand it correctly, there has do be a driver for each object. This means that I can’t easily create the lattice shown in my example by using a single material. For now I can live with that, since I will only animate one of the objects above the lattice, but I hope the rotation info will be added to the object info node in the future.

Please let me know if you have an idea of how to link the value driver to the object the material is assigned to.


PS: Rotation-based color driver at work: