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$
6
  • $\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
    Commented Jun 28, 2016 at 20:54
  • $\begingroup$ Interesting. How do I find out more about how to use these? $\endgroup$
    – Ascalon
    Commented Jun 29, 2016 at 10:20
  • 1
    $\begingroup$ Can you provide an example case? $\endgroup$ Commented Jul 3, 2016 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$ Commented Jul 3, 2016 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
    Commented Jul 3, 2016 at 17:50

1 Answer 1

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.

$\endgroup$
9
  • $\begingroup$ Ah, great. Could I trouble you to add a bit of explanation on what exactly these setups are doing? Thank you! $\endgroup$
    – Ascalon
    Commented Jul 4, 2016 at 3:30
  • $\begingroup$ Sure, updated. Be free to ask. :) $\endgroup$ Commented Jul 4, 2016 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
    Commented Dec 8, 2016 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$ Commented Dec 8, 2016 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
    Commented Dec 8, 2016 at 3:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .