Search Tips

Search is based on keyword.

`Ex: "Procedures"`

Do not search with natural language

`Ex: "How do I write a new procedure?"`

Give Feedback Support Portal

# Conditional Behavior

You can make the behavior of user parameters within a macro or group conditional, dependent on any user parameter values. For example, create a group, containing a scene that includes 3Delight and Arnold shaders. Select which shader to use from a pop-up menu, then show and hide shader options using conditional behavior.

# Conditional Visibility Example

First, follow the steps below to set up a scene you can use to learn about conditional visibility.

| 1. | Create a Katana scene with a PrimitiveCreate node, a Material node, a CameraCreate node, and a Merge node.

| 2. | Connect the outputs of the PrimitiveCreate, Material, and CameraCreate nodes to inputs on the Merge node.

| 3. | Create a MaterialAssign node, and place it downstream of the Merge node.

| 4. | Add GafferThree and RenderSettings nodes in a series, downstream of the MaterialAssign node. Finally, add a Render node at the end of the chain.

Note: You can overload Material and GafferThree nodes with more than one shader type. For example, a Material node can hold both 3Delight and Arnold shaders.
At render time, only shaders relevant to the selected renderer are considered.

| 5. | In the Material node, add a 3Delight surface shader of type Material3Delight, and an Arnold surface shader of type standard.

| 6. | In the GafferThree node, add both a 3Delight spotlight, and an Arnold spot_light, switching profiles to do so.

Note: For more information on how to add lights and assign shaders to them, refer to Getting to Grips with the GafferThree Node.

| 7. | Position the lights.

| 8. | Select all of the nodes except for Render, and press G to group all of the selected nodes together. The result is a Group node with a single output, connected to a Render node.

Once you've set up the scene, you can go into the Group node and change the RenderSettings node renderer parameter to switch between your available renderers. However, you can also use conditional visibility to streamline this operation by adding a pop-up menu to the UI of the Group node and linking to the renderer parameter on the RenderSettings node by expression.

Follow the steps below to switch between 3Delight and Arnold rendering options using conditional visibility:

| 1. | Select the Group and click > Edit User Parameters.

| 2. | Select Add > String and then select Widget Type > Popup Menu from the new parameter’s menu.

| 3. | Select Widget Options... from the new parameter’s menu.

| 4. | In the widget options dialog, select Add > New Entry, so there are two entries in the menu. Edit one entry to read "dl" and the other to read "arnold", then click OK.

| 5. | In the Group node’s Parameters tab, right-click on the pop-up menu widget and select Copy.

| 6. | Expand the contents of the Group node in the node graph. Select the RenderSettings node and press Alt+E to edit the parameters in the Parameters tab. Right-click on the node’s renderer parameter, and select Paste Expression.

The background of the renderer parameter turns blue, to indicate that it’s driven by an expression.

The value of the RenderSettings node renderer parameter is linked by expression to the selected entry in the Group node’s pop-up menu. If you select > Finish Editing User Parameters from the group’s Parameters tab, the pop-up menu now displays as a parameter.

# Create New User Parameters for Conditional Visibility

The state of the pop-up menu can also conditionally affect visibility of other user parameters in the Group node. Using the examples scene you've already set up from Conditional Visibility Example, create new user parameters on the group to control the diffuse color values on the 3Delight and Arnold shaders contained within it.

This example also shows how to add conditional behavior so that only the color controls for shaders relevant to the selected renderer are shown:

| 1. | In the Group node’s Parameters tab, select the > Edit User Parameters, then click Add > Color, RGB twice.

| 2. | Right-click on the first Color, RGB user parameter and select Copy. Expand the contents of the group in the node graph, then Shift+middle-click and drag the Material node to the Parameters tab to view it.

| 3. | Expand the parameters for the Material3Delight, right-click on the color parameter (base layer), and select Paste Expression.

| 4. | In the Group node’s Parameters tab, right-click on the second Color, RGB user parameter and select Copy.

| 5. | Expand the parameters for the Material node's arnoldSurfaceShader, right-click on the kd_color parameter, and select Paste Expression.

The diffuse color values of the 3Delight and Arnold shaders are linked by expression to the color widgets in the group's parameters. If you select Finish Editing User Parameters from the group’s menu, the color widgets display in the group’s Parameters tab. Their values affect the diffuse colors of the 3Delight and Arnold shaders.

# Hide Conditional Visibility Options

Only one shader at a time is considered, so it would be useful to hide the settings for the shader not applicable to the selected renderer.

| 1. | In the Group node’s Parameters tab, click > Edit User Parameters. Select > Conditional Visibility Options... for the first Color, RGB widget.

The Conditional Visibility Options dialog opens.

The conditional visibility options editor sets "and/or" conditions for showing the selected widget. Conditions are evaluated against a specified user parameter, in the format:

if <selected parameter> is <selected condition> relative to an entered value, then show the widget.

| 2. | In the Conditional Visibility Options dialog, select Add Condition > contains. In the text entry field, enter "dl".

The condition in this case is if <the pop-up menu> contains < the string dl> then show the target user parameter.

| 3. | In the Conditional Visibility Options window, click on the icon to choose the user parameter to test against, and select the pop-up menu from the list.

| 4. | Repeat the process above for the second Color, RGB widget, and the Arnold entry in the pop-up menu.

If you select the group’s > Finish Editing User Parameters, and view the completed Group node’s Parameters tab, only one color widget at a time displays in the group’s Parameters tab. Which one is dependent on the value chosen in the pop-up menu.