I have a field of ellipsoids with various rotations. I'd like to colour them by their rotation. Is it possible to get an object's rotation in a cycles material node?
You can insert a "Value" node (under Input) into your Cycles shader, then add a driver to it (right-click the parameter and select Add Driver); get the driver to copy the rotation axis of whatever object you want to use:
- With the Value node selected, go to the Graph Editor.
- Switch mode from F-Curves to Drivers.
- On the left hand side of the editor, find the "Value" inside Material > Shader Nodetree and click on it.
At this point you might need to reveal the panel at the right hand side of the editor - hit N if you can't see it.
- In the "Drivers" panel, change "Type" to "Averaged value".
- In the variable panel, make sure "Transform channel" is selected, then specify your Object from the input by name, change Type to "X Rotation" (or Y rotation, etc) and you should see its current value appear.
You can then attach the output of your Value node in Cycles to a Hue/Saturation node, or to the Fac of a Mix node to alter the colour. If you want each rotation axis to be available in the material, add a separate value for each rotation axis.
If you want to do something like map each axis directly to a part of the colour - e.g. X becomes R, Y becomes G, Z becomes B - add an RGB input node instead, right click the colour and add a driver to that. You can then find it under "Drivers" the way you might have found the value, and you can drive the four different components of the colour (R G B and A) individually.
Worth noting: the rotation value will hit the driver as radians, not degrees. It's also possible that the driver will get an input which is less than zero - you can get around this to an extent by setting the Type to Scripted Expression and using an expression like "abs(var) % pi" to keep the colour away from black.
There's an annoying drawback to this method though: as far as I know, you'll need to set the driver and material up separately for each object - so you'll end up having as many copies of the material as you have colour-changing ellipses. If your Cycles node setup is particularly complicated and you still want to be able to tweak it, you might try Grouping all the nodes in your material except for the Value, but use the Value as an input to your group. If the Object Node had X/Y/Z Location/Rotation/Scale, this wouldn't be necessary.