Condition is a utility node that allows you to switch
between two colors or textures, depending on a simple mathematical
relationship between two input values. If the relationship
(Greater Than, Less Than, Equals, Is Not Equal To, etc) is
true, then the first color or texture is output. If the relationship
is false, then the second color or texture is output.
You can use Condition nodes for many different purposes.
See the Rendering Book for more in-depth examples.
Note: The Condition node is completely unrelated to the
"condition" command found in the MEL scripting language.
In general, the operation of the Condition Node is this:
- You could create a shader that changes to a different
color when an object goes above a certain height. To do this,
connect the Translate Y attribute of the object to First Term,
set Second Term to the desired height, and set Operation to
"Greater Than". Set ColorIfTrue to red and ColorIfFalse to blue,
and connect the OutColor attribute to the object's shader. Now, when the
Y value of the object goes above the desired height, it will change
color from blue to red.
- In a slight variation, you can create a texture where
the parts of the texture above a certain height are one color,
and the parts below are another color. Create a Sampler
Info utility node, and connect its Point World Y attribute to
This will give you the position of each point on
the texture, rather than the position of the whole object.
Set Second Term to the desired height, and set
Operation to "Greater Than".
- You could create a texture that is like a marble texture, but
turns black in all the areas where the marble is too red. To do this,
connect the Marble's Out Color R attribute to First Term, and set
Second term to the desired red threshold value (say, 0.75).
Connect the Out Color attribute of a marble texture to
ColorIfFalse, and set ColorIfTrue to black. Set Operation to
"Greater Than". Connect the OutColor of the Condition
node to your shader.
IF ( First Term OPERATION Second Term ) THEN
Out Color = Color If True
Out Color = Color If False
In the table below, important attributes have their names
listed in bold in the description column.
This node is MP safe
|Node name||Parents||Classification||MFn type||Compatible function sets|
colorIfFalse, colorIfFalseB, colorIfFalseG, colorIfFalseR, colorIfTrue, colorIfTrueB, colorIfTrueG, colorIfTrueR, firstTerm, operation, outColor, outColorB, outColorG, outColorR, secondTerm
|Long name (short name)||Type||Default||Flags|
|float3||0.0, 0.0, 0.0|
|float3||1.0, 1.0, 1.0|
|float3||0.0, 0.0, 0.0|