Table Of Contents
Overview
The Shader Switch can be used to switch the input of a shader based on user attribute data like per-object id.
Frequently this is used for adding shading variation, such as colors or textures, across multiple different objects with one material shading graph. For example, instead of having a different material for each object, a shader switch could be used to control which textures are connected to which objects all through one material. Depending on the requirements of your scene, this can greatly simplify material management.
A shader switch can be chained together with additional shader switch nodes when 10 variations are not enough.
Example
Create a shader switch node and connect it to something that you want to drive variation in, then drive the shader selector parameter with a per object attribute or per vertex attribute node.
More than 10 shaders
When more than 10 shaders variations are required this can be accomplished by nesting another shader switch into the Default Shader input of another shader switch. The selector parameter of each shader switch should be driven by the same input and the offset value of each shader switch should be set appropriately.
For example, if 30 variations are required then 3 shader switch nodes should be used. The first shader switch should have an offset of 0, and the second and third shader switches should have an offset value of 10 and 20 respectively.
Parameters
In the example images below there are numbers beneath each sphere, for example 0=0. The first number refers to the sphere's object ID value that is being used to drive the shader switch and the second number refers to the shader input slot that is being used. The object ID remains the same but the output shader value can change depending on the shader selector and offset value.
This value determines which shader from the list of inputs to use. This value typically comes from an integer or scalar stored per-object and is commonly driven by using a
Integer User Data or
Scalar User Data node.
Shader selector can not be driven by bit-map textures. It is limited to per-object or per-vertex data.
Shader Selector: Object ID via User Integer Data | 0 | 2 |
10 (out of range resulting in default shader) |
The offset shifts the shader input values for a shader switch and is most useful when nesting shader switches to achieve a shading variation greater than 10.
By default the inputs range from 0-9 with an offset value of 0. However, when an offset value of 10 is used the 0-9 shader inputs then correspond to a range from 10-19. Offset 20 results in 20-29 and so on.
When multiple shader switches are connected each offset value only applies to itself and does not affect the other shader switches down the line.
These are the shader input slots, each input corresponds to a value from 0 to 9 when used with the default offset value of 0. These slots can have colors, textures, or even materials connected to them.
What will ultimately determine what should be connected to each input is dependent on what the shader switch output is connected to. For example, if a shader switch is connected to a bump map then the shader inputs should be filled with bump map compatible inputs.
Shader Inputs: Color and textures into one material | Different materials types |
This is the default color or shader that is used when the resulting shader selector value does not match with any of the available shader inputs and it goes out of range (i.e. less than 0 or greater than 9 with default settings).