This is a visual cheat-sheet for the Unity Shader Graph. This tool is used to create custom shaders material in Unity, a popular game engine.
We are using
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector3 |
Provides vertex position |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector3 |
Provides surface normal |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector3 |
World space position |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector3 |
Local space position |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector4 |
Screen space position |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector3 |
Camera world space position |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Float |
Time (T) - The total elapsed time since the start of the shader | |
Float |
Sin Time (T/8π) - A sine wave based on time | |
Float |
Cos Time (T/8π) - A cosine wave based on time | |
Float |
Delta Time - Time passed between the previous frame and the current frame |
Inputs
- | - | - |
---|---|---|
Float Vector |
First value | |
Float Vector |
Second value |
Outputs
- | - | - |
---|---|---|
SAIT | Sum of the two inputs |
Inputs
- | - | - |
---|---|---|
Float Vector |
Minuend | |
Float Vector |
Subtrahend |
Outputs
- | - | - |
---|---|---|
SAIT | Difference of the two inputs |
Inputs
- | - | - |
---|---|---|
Float Vector Matrix |
First value | |
Float Vector Matrix |
Second value |
Outputs
- | - | - |
---|---|---|
SAIT | The product of the two inputs |
Inputs
- | - | - |
---|---|---|
Float |
Base | |
Float |
Exponent |
Outputs
- | - | - |
---|---|---|
Float |
Result of base raised to the power of the exponent |
Inputs
- | - | - |
---|---|---|
Float |
Input value |
Outputs
- | - | - |
---|---|---|
Float |
Square root of the input |
Inputs
- | - | - |
---|---|---|
Float Vector |
Input value |
Outputs
- | - | - |
---|---|---|
SAIT | Absolute value of the input |
Inputs
- | - | - |
---|---|---|
Vector3 Vector4 |
First vector | |
Vector3 Vector4 |
Second vector |
Outputs
- | - | - |
---|---|---|
Float |
Dot product result |
Inputs
- | - | - |
---|---|---|
Vector3 |
First vector | |
Vector3 |
Second vector |
Outputs
- | - | - |
---|---|---|
Vector3 |
Cross product result |
Inputs
- | - | - |
---|---|---|
Float |
Input in radians |
Outputs
- | - | - |
---|---|---|
Float |
Sine of the input |
Inputs
- | - | - |
---|---|---|
Float |
Input in radians |
Outputs
- | - | - |
---|---|---|
Float |
Cosine of the input |
Inputs
- | - | - |
---|---|---|
Float Vector |
Start value | |
Float Vector |
End value | |
Float Vector |
Interpolation factor (T) |
Outputs
- | - | - |
---|---|---|
SAIT | Interpolated result |
Inputs
- | - | - |
---|---|---|
Float Vector |
Threshold | |
Float Vector |
Input |
Outputs
- | - | - |
---|---|---|
SAIT | Step result |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector4 |
RGBA color value |
Inputs
- | - | - |
---|---|---|
Vector4 |
First color | |
Vector4 |
Second color |
Outputs
- | - | - |
---|---|---|
Vector4 |
Sum of the two colors |
Inputs
- | - | - |
---|---|---|
Vector4 |
First color | |
Vector4 |
Second color |
Outputs
- | - | - |
---|---|---|
Vector4 |
Product of the two colors |
Inputs
- | - | - |
---|---|---|
Vector4 |
Start color | |
Vector4 |
End color | |
Float |
Interpolation factor (T) |
Outputs
- | - | - |
---|---|---|
Vector4 |
Interpolated color |
Inputs
- | - | - |
---|---|---|
Vector4 |
Input color | |
Float |
Saturation factor |
Outputs
- | - | - |
---|---|---|
Vector4 |
Adjusted color |
Inputs
- | - | - |
---|---|---|
Vector4 |
Input color | |
Float |
Contrast factor |
Outputs
- | - | - |
---|---|---|
Vector4 |
Adjusted color |
Inputs
- | - | - |
---|---|---|
Vector4 |
Input color | |
Float |
Hue shift amount |
Outputs
- | - | - |
---|---|---|
Vector4 |
Color with shifted hue |
Inputs
- | - | - |
---|---|---|
Vector4 |
Input color |
Outputs
- | - | - |
---|---|---|
Vector4 |
Inverted color |
Inputs
- | - | - |
---|---|---|
Vector4 |
Input color | |
Vector4 |
Target color | |
Vector4 |
Replacement color |
Outputs
- | - | - |
---|---|---|
Vector4 |
Color with replaced values |
Inputs
- | - | - |
---|---|---|
Vector4 |
Input color | |
Float |
Temperature value | |
Float |
Tint value |
Outputs
- | - | - |
---|---|---|
Vector4 |
Adjusted color |
Inputs
- | - | - |
---|---|---|
Vector4 |
Input color | |
Float |
Red channel multiplier | |
Float |
Green channel multiplier | |
Float |
Blue channel multiplier |
Outputs
- | - | - |
---|---|---|
Vector4 |
Modified color |
Inputs
- | - | - |
---|---|---|
Texture (sampler) |
Texture input | |
Vector2 |
UV coordinates |
Outputs
- | - | - |
---|---|---|
Vector4 |
Color data from the texture |
Inputs
- | - | - |
---|---|---|
/ | No inputs |
Outputs
- | - | - |
---|---|---|
Vector2 |
UV coordinates |
Inputs
- | - | - |
---|---|---|
Vector2 |
Tiling values | |
Vector2 |
Offset values |
Outputs
- | - | - |
---|---|---|
Vector2 |
Modified UV coordinates |
Inputs
- | - | - |
---|---|---|
Float |
Distortion strength | |
Vector2 |
UV coordinates |
Outputs
- | - | - |
---|---|---|
Vector2 |
Warped UV coordinates |
Inputs
- | - | - |
---|---|---|
Texture (sampler) | Input texture | |
Vector2 |
UV coordinates | |
Float |
Depth value |
Outputs
- | - | - |
---|---|---|
Vector2 |
Adjusted UV coordinates |
Inputs
- | - | - |
---|---|---|
Vector3 |
View direction | |
Float |
Power of the effect |
Outputs
- | - | - |
---|---|---|
Float |
Fresnel effect value |
Inputs
- | - | - |
---|---|---|
Texture (sampler) |
Input texture | |
Float |
Dissolve threshold |
Outputs
- | - | - |
---|---|---|
Vector4 |
Dissolve effect output |
Inputs
- | - | - |
---|---|---|
Vector3 |
Incident direction | |
Vector3 |
Surface normal |
Outputs
- | - | - |
---|---|---|
Vector3 |
Reflected direction |
Step 1: Add Custom Function Node in Shader Graph
Step 2: Configure the Node in Shader Graph
Set the name of the node.
If using "File", ensure the external HLSL file name exactly matches the function name defined in the HLSL file. This ensures the function is correctly referenced in the Shader Graph pipeline.
CustomFunction.hlsl
, the function inside it should also be named CustomFunction
.
Step 3: Add Inputs/Outputs in Shader Graph
Define the required Inputs
and Outputs
for the custom function in Shader Graph. These will automatically generate ports for you to connect other nodes.
Float
(time), Vector3
(position)Vector3
(new position)In the custom HLSL code, the in
and out
parameters correspond to these inputs and outputs:
in
represents the data coming into the function (e.g., time
, position
).out
defines the return value (e.g., modified position
).Step 4: Write HLSL Code
If using the "String" option:
Directly write the HLSL code inside the custom function node editor in Shader Graph.
Ensure that the in
and out
parameters match the inputs and outputs you defined in Shader Graph.
float3 CustomPosition(in float time, in float3 position, out float3 newPosition) {
newPosition = position + float3(sin(time), cos(time), 0.0);
return newPosition;
}
If using the "File" option:
Write the HLSL code in an external .hlsl
file and reference the file in Shader Graph.
1. Create an HLSL file named CustomPosition.hlsl
.
2. Write the custom function inside the file. The in
and out
parameters should match the Shader Graph inputs and outputs.
float3 CustomPosition(in float time, in float3 position, out float3 newPosition) {
newPosition = position + float3(sin(time), cos(time), 0.0);
return newPosition;
}
3. Save the file in your project directory, for example, Assets/Shaders/CustomPosition.hlsl
.
4. Link the file in Shader Graph:
CustomPosition.hlsl
.Step 5: Use the Node in Shader Graph
Connect the custom function node’s input ports to other nodes, such as Time
and Position
, to feed data into the custom function.
Connect the output port to apply the function result in the Shader Graph pipeline.
Time
(as a float) and Position
(as a vector)Modified Position
(vector with new position)This would make the custom node update an object's position based on time in the shader.