4
$\begingroup$

I want to drive a property in a Cycles material based on the current Render Layer or Scene being rendered. Is there any such property? If not, is this something that could be made as an addon, or is there some technical limitation that prevents it?

$\endgroup$
  • $\begingroup$ Might be a job for a handler instead blender.org/api/blender_python_api_current/…. Drivers and nodes sometimes don't play nicely with each other. $\endgroup$ – batFINGER Jun 28 '16 at 20:54
  • $\begingroup$ Interesting. How do I find out more about how to use these? $\endgroup$ – Ascalon Jun 29 '16 at 10:20
  • 1
    $\begingroup$ Can you provide an example case? $\endgroup$ – Leon Cheung Jul 3 '16 at 8:44
  • $\begingroup$ Avoid drivers inside nodes, it causes only trouble and does not update or work properly. As batFINGER wrote, this is job for handler (which is dirty for this usecase but the only sane option). $\endgroup$ – Jaroslav Jerryno Novotny Jul 3 '16 at 11:56
  • $\begingroup$ Ditto on @LeonCheung forgot to request same.. The which scene part is quite simple I'm not sure on the render_layers. $\endgroup$ – batFINGER Jul 3 '16 at 17:50
4
+50
$\begingroup$

You can use Animation Nodes addon to control both:

Basic setup for driving by active render layer:

enter image description here

Explanation:

  • Scene Input node: Used for reading scene data. (Note: this node can only be found by searching via Ctrl + A. And, considering the huge amount of all kinds of nodes in AN, as a beginner, you may want to create the following nodes by searching as well.)
  • Expression node: This is a very powerful node, which can do a lot of things. In this case, it is used for reading the name of the active render layer from data path.
  • Compare node: It outputs the comparison result between A and B. In this case it means: if A is equal to B, or more specific: if the active render layer name is RenderLayer.2, then it outputs True, a boolean value, otherwise False.
  • Switch node: It outputs either one of the two values based on the condition input from the previous node.
  • Cycles Material Output node: Used for controlling Cycles material parameters, very intuitive to understand I bet.

Basic setup for driving by selected scene:

enter image description here

Explanation:

  • Mostly the same as above.

You can download the addon here. More info see here. If you really want to drive things like that without coding yourself, it is worth learning it a bit.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Ah, great. Could I trouble you to add a bit of explanation on what exactly these setups are doing? Thank you! $\endgroup$ – Ascalon Jul 4 '16 at 3:30
  • $\begingroup$ Sure, updated. Be free to ask. :) $\endgroup$ – Leon Cheung Jul 4 '16 at 5:43
  • $\begingroup$ Finally getting around to setting this up, but I've run into a problem: This drives the property based on my current selected render layer in the UI, not based on the render layer that is actually rendering. Is there a way to change this? I also discovered that you need to set the expression type to String, and also change the compare node to String in Advanced Node settings. $\endgroup$ – Ascalon Dec 8 '16 at 2:38
  • $\begingroup$ Unfortunately Cycles material is kinda global data, which means few variables can be applied to different users (objects) based on the same material. However you can still use some tricks to have different look on different objects that use the same mat. One trick is by setting different object index number for objects in different render layers, then use the Object Index value (located on Object Info node within Cycles) as the variable. This is quite doable with or without AN. $\endgroup$ – Leon Cheung Dec 8 '16 at 3:49
  • $\begingroup$ Sorry if I am misunderstanding, but i'm not having an issue within the Cycles material. The issue is that the data path driving the expression is linked the layer i have actively selected in the UI, not the layer that is actually being rendered. $\endgroup$ – Ascalon Dec 8 '16 at 3:55

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.