4

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?

Ascalon
  • 6,579
  • 8
  • 55
  • 121

1 Answers1

4

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.

Leon Cheung
  • 27,718
  • 11
  • 89
  • 161
  • Ah, great. Could I trouble you to add a bit of explanation on what exactly these setups are doing? Thank you! – Ascalon Jul 04 '16 at 03:30
  • Sure, updated. Be free to ask. :) – Leon Cheung Jul 04 '16 at 05:43
  • 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. – Ascalon Dec 08 '16 at 02:38
  • 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. – Leon Cheung Dec 08 '16 at 03:49
  • 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. – Ascalon Dec 08 '16 at 03:55
  • I see. But what if a object is on both render layers? What should the material look like in such case anyway? – Leon Cheung Dec 08 '16 at 04:53
  • When it is rendering layer 1, it should be mix fac 0. When it is rendering layer 2, it should be mix fac 1. Currently I can do this by clicking on layer one, rendering, then clicking on layer 2, and re-rendering it by hitting the button on the render layer node in the compositor. But manually doing this wouldn't work so well if I add more layers, or if I want to leave it rendering for awhile.(The secondary layers are for masks based on textures and geometry inputs already setup within the material.) – Ascalon Dec 08 '16 at 06:48
  • In that case, things will become much more complicated I bet. Additional coding will be inevitable, with which I can hardly help. Sorry man. – Leon Cheung Dec 09 '16 at 07:39
  • How would I achieve the same with Blender 2.8? – bummzack Jan 23 '20 at 15:55