Create a new group
- Click on the group node to enter group view.
- Select Hw Shader Nodes > Math > Add and Hw Shader Nodes > Value > Color to create an Add node and a Color node, respectively.
- Connect the nodes as follows:
- Connect the RGB attribute of Color to the Value attribute of Add.
- Connect the Result attribute of Multiply to the Value attribute of Add.
- Connect the Result attribute of Add to the Diffuse Color attribute of the group node.
- Select the newly created Color node. In the Attribute Editor, enter the name OffsetColor and the ordering number 3.
OffsetColor now appears in the group node Attribute Editor.
Convert a group into a function
- Select Multiply and Add, then select Group > Create Group.
- Click on the newly created group. In the group view, select the group node, and enter MyColorFunction in the Name field in the Attribute Editor.
- In the Attribute Editor, enable Group is a function so that the output of these nodes are encapsulated as a function in the shader code.
- Give your group node ports unique names. Currently, all ports are named Value, and thus shader is invalid and appears red in Viewport 2.0.
In the Attribute Editor, complete the following information:
-
Active socket: 0 and Active socket label: ColorA
-
Active socket: 1 and Active socket label: Multiplier
-
Active socket: 2 and Active socket label: ColorB
Note: When converting a group into a function, all group node ports must have unique names. Otherwise, the shader becomes invalid.
- Exit the group view and select Tools > Compute Graph.
Save your shader file and examine the shader code
- Select the Material node and enter a filename for your shader file in the Attribute Editor and press , then click HwShader/Save to Disk.
The path to which your shader file is saved appears as a tooltip in the ShaderFx editor window.
- Examine your shader file and search for MyColorFunction.
MyColorFunction is defined as a function in the shader file. The SHADERDATA struct is listed as an input. This is the default setting.
- To disable this setting for cleaner code, enter the group view of your MyColorFunction group, select the group node and enable Don't add DATA struct as function input in the Attribute Editor.
Resave your shader file to see that the SHADERDATA struct is no longer listed as an input parameter.