|
| 1 | +## Custom Material Property Drawers sample |
| 2 | + |
| 3 | +Learn how to use custom attributes in Shader Graph to improve the display and usability of property controls in the material's Inspector window. |
| 4 | + |
| 5 | +The Custom Material Property Drawers sample includes a shader graph based material set up for adjustable color gradient and noise. This example shows how to achieve the following in the material Inspector UI with Shader Graph: |
| 6 | + |
| 7 | +* Hide or display a basic material color property. |
| 8 | +* Display a Vector2 property as a min/max slider. |
| 9 | +* Display a help box for a property. |
| 10 | + |
| 11 | +## Before you start |
| 12 | + |
| 13 | +To access the Custom Material Property Drawers sample, follow these steps: |
| 14 | + |
| 15 | +1. [Import](ShaderGraph-Samples-Import.md) the Custom Material Property Drawers sample in your project. |
| 16 | + |
| 17 | +1. In the Project window, open the `Assets/Samples/Shader Graph/<your version>/Custom Material Property Drawers` folder. |
| 18 | + |
| 19 | +1. Open the `RemapDrawerExample` shader graph asset. |
| 20 | + |
| 21 | +## Hide or display a property in the material Inspector UI |
| 22 | + |
| 23 | +To hide or display a material property from the shader graph in the material Inspector UI, follow these steps: |
| 24 | + |
| 25 | +1. In the [Shader Graph window](Shader-Graph-Window.md), in the [Blackboard](Blackboard.md), select a property, for example **InnerColor**. |
| 26 | + |
| 27 | +1. In the [Graph Inspector](Internal-Inspector.md), in the **Node Settings** tab, disable **Show in Inspector**. |
| 28 | + |
| 29 | +1. Save the graph. |
| 30 | + |
| 31 | +1. In the Project window, select the `RemapDrawerExample` material variant asset. |
| 32 | + |
| 33 | +1. In the Inspector window, notice that the **InnerColor** property isn't displayed, contrarily to the other properties of the graph. |
| 34 | + |
| 35 | +1. In the [Shader Graph window](Shader-Graph-Window.md), re-enable **Show in Inspector** for the **InnerColor** property. |
| 36 | + |
| 37 | +1. Save the graph. |
| 38 | + |
| 39 | +1. In the Inspector window, notice that the **InnerColor** property is now displayed. |
| 40 | + |
| 41 | +## Display a material property as a min/max range slider |
| 42 | + |
| 43 | +To learn how to display a material property as a min/max range slider in the material Inspector UI, follow these steps: |
| 44 | + |
| 45 | +1. In the [Shader Graph window](Shader-Graph-Window.md), in the [Blackboard](Blackboard.md), select the **Range** property. |
| 46 | + |
| 47 | +1. In the [Graph Inspector](Internal-Inspector.md), in the **Node Settings** tab, notice the following: |
| 48 | + |
| 49 | + * The **Custom Attributes** include an entry named **Remap**, which modifies the **Range** property's appearance in the material UI based on a script provided with the sample. |
| 50 | + * The attribute includes no parameter values for the called function. For more information, refer to the sticky note besides the **Range** property instance in the graph. |
| 51 | + |
| 52 | +1. In the Project window, open the `Editor` subfolder. |
| 53 | + |
| 54 | +1. Select the `RemapDrawer` C# file. |
| 55 | + |
| 56 | +1. In the Inspector window, notice the following: |
| 57 | + |
| 58 | + * The C# file includes a set of custom functions named `RemapDrawer` to display a Vector2 as a min/max slider. |
| 59 | + * The function names include a `Drawer` suffix while in the shader graph the **Range** property excludes this suffix to call the functions. |
| 60 | + |
| 61 | +## Display a help box in the material Inspector UI |
| 62 | + |
| 63 | +To learn how to display a help box in the material Inspector UI, follow these steps: |
| 64 | + |
| 65 | +1. In the [Shader Graph window](Shader-Graph-Window.md), in the [Blackboard](Blackboard.md), select the **NoiseRange** property. |
| 66 | + |
| 67 | +1. In the [Graph Inspector](Internal-Inspector.md), in the **Node Settings** tab, notice the following: |
| 68 | + |
| 69 | + * The **Custom Attributes** include an entry named **Remap** (previously described) and a second one named **HelpBox**, which adds a help box to the **NoiseRange** property in the material UI based on a second script provided with the sample. |
| 70 | + * The two attributes include specific parameter values for the called functions. For more information, refer to the sticky note under the **NoiseRange** property instance in the graph. |
| 71 | + |
| 72 | +1. In the Project window, still in the `Editor` subfolder, select the `HelpBoxDecorator` C# file. |
| 73 | + |
| 74 | +1. In the Inspector window, notice the following: |
| 75 | + |
| 76 | + * The C# file includes a set of custom functions named `HelpBoxDecorator` to draw a message box in the material UI. |
| 77 | + * The function names include a `Decorator` suffix while in the shader graph the **NoiseRange** property excludes this suffix to call the functions. |
| 78 | + |
| 79 | +## Additional resources |
| 80 | + |
| 81 | +* [Property attribute reference](Property-Types.md) |
0 commit comments