Convert a group to a function and inspect the shader code

Create a new group

  1. Click on the group node to enter group view.
  2. Select Hw Shader Nodes > Math > Add and Hw Shader Nodes > Value > Color to create an Add node and a Color node, respectively.
  3. 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.
  4. 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

  1. Select Multiply and Add, then select Group > Create Group.
  2. 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.
  3. 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.
  4. 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.
  5. Exit the group view and select Tools > Compute Graph.

Save your shader file and examine the shader code

  1. 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.

  2. 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.

  3. 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.