|
1 | | -# Custom Interpolators |
| 1 | +# Add a custom interpolator |
2 | 2 |
|
3 | | -## Description |
| 3 | +To pass custom data from the vertex shader to the fragment shader, add a custom interpolator to the vertex context of the Master Stack. |
4 | 4 |
|
5 | | -The Custom Interpolator feature provides fine-grained control over the specific calculations Shader Graph uses to bring data from the vertex stage to the pixel stage. |
6 | | - |
7 | | -There are two target audiences for Custom Interpolators: |
| 5 | +There are two target audiences for custom interpolators: |
8 | 6 |
|
9 | 7 | * Technical Directors and Lead Technical Artists setting up environments for their teams. |
10 | 8 | * Graphics programmers helping artists to optimize content performance. |
11 | 9 |
|
| 10 | +**Note:** If you use the Built-In Render Pipeline, refer to [Input vertex data into a shader](https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html) instead. |
12 | 11 |
|
13 | 12 | ## Supported data types |
14 | | -Custom interpolators support float, vec2, vec3, and vec4 options. |
| 13 | + |
| 14 | +Custom interpolators support float, vector 2, vector 3, and vector 4 types. |
15 | 15 |
|
16 | 16 | ## Channel limits |
17 | | -The Custom Interpolator feature supports a maximum of 32 channels. A channel is equivalent to four floats. Each float is an interpolator variable. |
18 | | -Different platforms and GPUs have different interpolator variable limits. Exceeding the interpolator limitations of your target platform prevents your shaders from compiling. For detailed information about the number of interpolators supported by common interfaces, see the Unity documentation on [Shader semantics](https://docs.unity3d.com/Manual/SL-ShaderSemantics.html), and view the section **Interpolator count limits**. Test your Custom Interpolators on your target configuration to ensure that your content compiles properly. |
19 | | -Technical directors can set warnings and errors to help their team members avoid creating graphs with too many channels to be compatible with their target pipeline, platform, or GPU. See **Creating channel warnings and errors** below. |
20 | 17 |
|
21 | | -## How to use |
22 | | -To use this feature, create a Custom Interpolator block in the Vertex context of the Master Stack and set a name and a data type. Create a vertex node to write data to that interpolator. Use the interpolator in your graph, then connect your graph to the relevant block in the Fragment context. |
23 | | -These instructions include a contextual example illustrating the process of using a Custom Interpolator to fetch per-vertex data from a texture. |
24 | | -To read the HLSL you use to replicate this behavior with the Built In Render Pipeline, see the Unity documentation on [Shader semantics](https://docs.unity3d.com/Manual/SL-ShaderSemantics.html) and view the section **Vertex ID: SV_VertexID**. |
| 18 | +A custom interpolator supports a maximum of 32 channels. A channel is equivalent to four floats. Each float is an interpolator variable. |
25 | 19 |
|
26 | | -### Creating channel warnings and errors |
| 20 | +Different platforms and GPUs may have different limits, which might prevent your shaders compiling. Test your custom interpolators on your build targets to make sure your shaders compile properly. For more information, refer to the **Interpolator count limits** section in [Input vertex data into a shader](https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html). |
27 | 21 |
|
28 | | -It is not possible to limit the number of channels a user can create in a Shader Graph. However, it is possible to create alerts to let users know when they are close to or exceeding a certain number of channels. |
29 | | -The **Warning Threshold** lets users know that they are approaching the channel limit, and the **Error Threshold** informs them if they have reached or surpassed that limit. The **Warning Threshold** value must be between 8 and 32 channels. The **Error Threshold** value must be higher than the **Warning Threshold**, and has a minimum value of 8 channels. |
30 | | -To configure these parameters, go to the Unity Editor [Project Settings](https://docs.unity3d.com/Manual/comp-ManagerGroup.html) menu and open the **Custom Interpolator Channel Settings**. |
| 22 | +You can't limit the number of channels another user creates in a shader graph. However, to warn users about the limits, go to [Project Settings](https://docs.unity3d.com/Manual/comp-ManagerGroup.html) and set the following: |
31 | 23 |
|
32 | | -### Adding a Custom Interpolator block to the Master Stack |
| 24 | +- **Warning Threshold** to tell users when they approach the channel limit. The range is 8 to 32 channels. |
| 25 | +- **Error Threshold** to tell users when they reach or exceed the channel limit. The minimum value is 8 channels, and it must be higher than the **Warning Threshold**. |
33 | 26 |
|
34 | | -  |
| 27 | +## Add a custom interpolator block to the Master Stack |
35 | 28 |
|
36 | | -1. Right-click in the **Vertex** contex to create a block node. |
| 29 | +1. Right-click in the **Vertex** context to create a block node. |
37 | 30 | 2. Select **Custom Interpolator**. |
38 | | -3. Select a data type. |
39 | | -4. Enter a name for this interpolator. |
| 31 | +3. In the **Node Settings** tab of the **Graph Inspector** window, select a data type, for example **Vector 4**. |
| 32 | +4. In the same tab, enter a name for the interpolator. |
40 | 33 |
|
41 | | -In the illustrated example, you use the Vector 4 (vec4) data type. |
| 34 | +## Write data to the interpolator |
42 | 35 |
|
43 | | -### Writing data to the interpolator |
| 36 | +1. Right-click in your graph to create a node. |
| 37 | +2. Select the type, for example **Vertex ID**. |
44 | 38 |
|
45 | | -  |
| 39 | + Custom interpolator blocks support many types of data, so you can connect the data from many other nodes including UV nodes and color nodes. |
46 | 40 |
|
47 | | -1. Right-click in your graph to create a node. |
48 | | -2. Select the type **Vertex ID**. |
49 | | -3. Connect this node to the Custom Interpolator block. |
| 41 | +3. Connect the node to the custom interpolator block. |
50 | 42 |
|
51 | | -In the example, you write Vertex ID values from your graph into the Custom Interpolator. |
| 43 | +The graph now writes Vertex ID values into the custom interpolator. |
52 | 44 |
|
53 | | -### Reading data from the interpolator |
| 45 | +## Read data from the interpolator |
54 | 46 |
|
55 | 47 | 1. Right-click in your graph to create a node. |
56 | 48 | 2. Select **Custom Interpolator**. |
57 | | -3. Connect the Custom Interpolator node to the relevant block in the Fragment context. |
58 | | - |
59 | | -  |
60 | | - |
61 | | -In this example, you connect to the **Base Color** block in order to pass the Vertex ID from the vertex shader to the fragment shader and use it as color output. |
| 49 | +3. Connect the **Custom Interpolator** node to the relevant block in the **Fragment** context, for example **Base Color** to use the Vertex ID as color output. |
62 | 50 |
|
63 | | -### Deleting the block from the Master Stack |
| 51 | +## Delete a custom interpolator |
64 | 52 |
|
65 | | -If you delete a Custom Interpolator which is associated with nodes that are still in your graph, Unity displays an alert. If you want to keep using these nodes, you can create a new Custom Interpolator and associate them with it. This prevents the alert from appearing. |
| 53 | +If you delete a custom interpolator that's associated with nodes that are still in your graph, Unity displays an alert. If you want to keep using these nodes, you can create a new custom interpolator and associate the nodes with it. This prevents the alert from appearing. |
0 commit comments