9.8 KiB
title, date, background, label, tags, categories, intro
| title | date | background | label | tags | categories | intro | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Unity Shader Graph | 2024-08-10 12:15:05 | bg-[#7c7c7c] |
|
|
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. |
Shader Graph Nodes
We are using SAIT to indicate the output type is "same as the input type". {.col-span-2}
Basic Nodes
Position - provides vertex position {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - Vector3Provides vertex position {.shortcuts .marker-round .cols-2}
-
Normal - supplies surface normal direction {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - Vector3Provides surface normal {.shortcuts .marker-round .cols-2}
-
Time - outputs time values {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - FloatOutputs time values {.shortcuts .marker-round .cols-2}
-
Multiply - multiplies two values {.cols-2}
- Inputs
-
- - Float,Vector,MatrixFirst value Float,Vector,MatrixSecond value
-
- Outputs
-
- - SAIT The product of the two inputs {.shortcuts .marker-round .cols-2}
-
Lerp - linear interpolation between two values {.cols-2}
- Inputs
-
- - FloatStart value FloatEnd value FloatInterpolation factor (T)
-
- Outputs
-
- - FloatInterpolated result {.shortcuts .marker-round .cols-2}
-
Step - creates a step between two thresholds {.cols-2}
- Inputs
-
- - FloatThreshold FloatInput
-
- Outputs
-
- - FloatStep result {.shortcuts .marker-round .cols-2}
-
Math Nodes
Add - adds two values {.cols-2}
- Inputs
-
- - FloatorVectorFirst value FloatorVectorSecond value
-
- Outputs
-
- - SAIT Sum of the two inputs {.shortcuts .marker-round .cols-2}
-
Subtract - subtracts one value from another {.cols-2}
- Inputs
-
- - FloatorVectorMinuend FloatorVectorSubtrahend
-
- Outputs
-
- - SAIT Difference of the two inputs {.shortcuts .marker-round .cols-2}
-
Sin - outputs sine of input {.cols-2}
- Inputs
-
- - FloatInput in radians
-
- Outputs
-
- - FloatSine of the input {.shortcuts .marker-round .cols-2}
-
Cos - outputs cosine of input {.cols-2}
- Inputs
-
- - FloatInput in radians
-
- Outputs
-
- - FloatCosine of the input {.shortcuts .marker-round .cols-2}
-
Power - raises input to a power {.cols-2}
- Inputs
-
- - FloatBase FloatExponent
-
- Outputs
-
- - FloatResult of base raised to the power of the exponent {.shortcuts .marker-round .cols-2}
-
Sqrt - square root of input {.cols-2}
- Inputs
-
- - FloatInput value
-
- Outputs
-
- - FloatSquare root of the input {.shortcuts .marker-round .cols-2}
-
Abs - outputs absolute value {.cols-2}
- Inputs
-
- - FloatorVectorInput value
-
- Outputs
-
- - SAIT Absolute value of the input {.shortcuts .marker-round .cols-2}
-
Texture Nodes
Sample Texture - retrieves color data from texture {.cols-2}
- Inputs
-
- - Texture (sampler) Texture input Vector2UV coordinates
-
- Outputs
-
- - Vector4Color data from the texture {.shortcuts .marker-round .cols-2}
-
UV - provides UV coordinates for texture mapping {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - Vector2UV coordinates {.shortcuts .marker-round .cols-2}
-
Tiling Offset - adjusts tiling and offset of texture {.cols-2}
- Inputs
-
- - Vector2Tiling values Vector2Offset values
-
- Outputs
-
- - Vector2Modified UV coordinates {.shortcuts .marker-round .cols-2}
-
Effects Nodes
Fresnel Effect - creates a glow effect on object edges {.cols-2}
- Inputs
-
- - Vector3View direction FloatPower of the effect
-
- Outputs
-
- - FloatFresnel effect value {.shortcuts .marker-round .cols-2}
-
Dissolve - generates a dissolve transition effect {.cols-2}
- Inputs
-
- - Texture (sampler) Input texture FloatDissolve threshold
-
- Outputs
-
- - Vector4Dissolve effect output {.shortcuts .marker-round .cols-2}
-
Distortion - warps the surface of the object {.cols-2}
- Inputs
-
- - FloatDistortion strength Vector2UV coordinates
-
- Outputs
-
- - Vector2Warped UV coordinates {.shortcuts .marker-round .cols-2}
-
Reflection - reflects based on surface normal direction {.cols-2}
- Inputs
-
- - Vector3Incident direction Vector3Surface normal
-
- Outputs
-
- - Vector3Reflected direction {.shortcuts .marker-round .cols-2}
-
Advanced Nodes
World Position - returns the object's world space position {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - Vector3World space position {.shortcuts .marker-round .cols-2}
-
Object Position - returns the object's local space position {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - Vector3Local space position {.shortcuts .marker-round .cols-2}
-
Screen Position - returns the object's screen space position {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - Vector4Screen space position {.shortcuts .marker-round .cols-2}
-
Parallax - simulates depth using parallax mapping {.cols-2}
- Inputs
-
- - Texture (sampler) Input texture Vector2UV coordinates FloatDepth value
-
- Outputs
-
- - Vector2Adjusted UV coordinates {.shortcuts .marker-round .cols-2}
-
Camera Position - returns the camera's world space position {.cols-2}
- Inputs
-
- - None No inputs
-
- Outputs
-
- - Vector3Camera world space position {.shortcuts .marker-round .cols-2}
-
Custom Function Node
Steps to Create a Custom Function Node:
-
Add Custom Function Node
- Right-click in Shader Graph and choose "Create Node" > "Custom Function".
-
Configure the Node
- Set a name and choose between "String" (inline code) or "File" (external HLSL file).
-
Add Inputs/Outputs: Define inputs (e.g., float, vector) and outputs. Example:
- Inputs: Float (time), Vector3 (position)
- Outputs: Vector3 (new position)
-
Write Shader Code: Enter the custom HLSL code. Example:
float3 CustomPosition(float time, float3 position) { return position + float3(sin(time), cos(time), 0.0); } -
Use the Node: Integrate the custom node into your shader graph.
{.marker-timeline}
Also see
- Unity Shader Graph documentation (docs.unity3d.com)
- Tianle Yuan's Unity Visual Effect notes (yuantianle.com)