3
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ AFAIK, For controlling via location, you can use Object Info node. But via rotation... It would be a nice feature too. A new vector type for object Info node. :) I bet currently you have to script for batch control. $\endgroup$ – Leon Cheung May 25 '14 at 8:31
  • $\begingroup$ I wonder if adding it would be trivial.. I might have to see if I can get myself on the development team :) $\endgroup$ – ajwood May 26 '14 at 13:18
4
$\begingroup$

Sort of..

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:

  1. With the Value node selected, go to the Graph Editor.
  2. Switch mode from F-Curves to Drivers.
  3. 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.

  1. In the "Drivers" panel, change "Type" to "Averaged value".
  2. 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.

$\endgroup$
  • $\begingroup$ I can't get this to work. I've tried using rotations between -1000 to several thousand degrees to see if range was a problem and there is no difference in the output. Oddly enough, if I change the slider for the Value node, the rendered output changes even though I get a message saying "Cannot edit a driven value, see graph editor for the driver setup." $\endgroup$ – MarcClintDion May 24 '14 at 9:00
  • $\begingroup$ Well it works.. the annoying drawback to pointed out is going to make this impossible though (I'm applying the material to a couple hundred or so objects), so I'll have to script it. $\endgroup$ – ajwood May 24 '14 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.