mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 05:24:10 +03:00
Merge pull request #600 from yuantianle/main
Formatted Unity Shader Graph module and added svg for main page
This commit is contained in:
2 files changed
+319
-46
No files matched your search
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Unity Shader Graph
|
||||
title: 🕹️ Unity Shader Graph
|
||||
date: 2024-08-10 12:15:05
|
||||
background: bg-[#7c7c7c]
|
||||
label:
|
||||
@@ -14,74 +14,346 @@ intro: |
|
||||
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
|
||||
## Shader Graph Nodes {.cols-2}
|
||||
|
||||
### Basic Nodes
|
||||
<code>We are using <yel>**SAIT**</yel> to indicate the output type is "same as the input type".</code> {.col-span-2}
|
||||
|
||||
| Node | Action |
|
||||
| ------------- | ----------------------------------------- |
|
||||
| `Position` | Provides vertex position |
|
||||
| `Normal` | Supplies surface normal direction |
|
||||
| `Time` | Outputs time values |
|
||||
| `Multiply` | Multiplies two values |
|
||||
| `Lerp` | Linear interpolation between two values |
|
||||
| `Step` | Creates a step between two thresholds |
|
||||
### Basic Nodes
|
||||
|
||||
{.shortcuts}
|
||||
<yel>Position</yel> - provides vertex position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3`| Provides vertex position|
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Normal</yel> - supplies surface normal direction {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3`| Provides surface normal |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Time</yel> - outputs time values {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Outputs time values |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Multiply</yel> - multiplies two values {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float`, `Vector`, `Matrix` | First value |
|
||||
| `Float`, `Vector`, `Matrix` | Second value|
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | The product of the two inputs |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Lerp</yel> - linear interpolation between two values {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Start value |
|
||||
| `Float` | End value |
|
||||
| `Float` | Interpolation factor (T)|
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Interpolated result |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Step</yel> - creates a step between two thresholds {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Threshold |
|
||||
| `Float` | Input |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Step result |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Math Nodes
|
||||
|
||||
| Node | Action |
|
||||
| -------------- | ----------------------------------------- |
|
||||
| `Add` | Adds two values |
|
||||
| `Subtract` | Subtracts one value from another |
|
||||
| `Sin` | Outputs sine of input |
|
||||
| `Cos` | Outputs cosine of input |
|
||||
| `Power` | Raises input to a power |
|
||||
<yel>Add</yel> - adds two values {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` or `Vector` | First value |
|
||||
| `Float` or `Vector` | Second value |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Sum of the two inputs |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Subtract</yel> - subtracts one value from another {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` or `Vector` | Minuend |
|
||||
| `Float` or `Vector` | Subtrahend |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Difference of the two inputs |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Sin</yel> - outputs sine of input {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input in radians |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Sine of the input |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Cos</yel> - outputs cosine of input {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input in radians |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Cosine of the input |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Power</yel> - raises input to a power {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Base |
|
||||
| `Float` | Exponent |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Result of base raised to the power of the exponent |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Sqrt</yel> - square root of input {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input value |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Square root of the input |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Abs</yel> - outputs absolute value {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` or `Vector` | Input value |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Absolute value of the input |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Texture Nodes
|
||||
|
||||
| Node | Action |
|
||||
| ----------------- | ---------------------------------------- |
|
||||
| `Sample Texture` | Retrieves color data from texture |
|
||||
| `UV` | Provides UV coordinates for texture |
|
||||
| `Tiling Offset` | Adjusts tiling and offset of texture |
|
||||
<yel>Sample Texture</yel> - retrieves color data from texture {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| Texture (sampler) | Texture input |
|
||||
| `Vector2` | UV coordinates |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Color data from the texture |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>UV</yel> - provides UV coordinates for texture mapping {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | UV coordinates |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Tiling Offset</yel> - adjusts tiling and offset of texture {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Tiling values |
|
||||
| `Vector2` | Offset values |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Modified UV coordinates |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Effects Nodes
|
||||
|
||||
| Node | Action |
|
||||
| --------------- | --------------------------------------- |
|
||||
| `Fresnel Effect`| Creates a glow effect on object edges |
|
||||
| `Dissolve` | Generates a dissolve transition effect |
|
||||
| `Distortion` | Warps object surface |
|
||||
<yel>Fresnel Effect</yel> - creates a glow effect on object edges {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | View direction |
|
||||
| `Float` | Power of the effect |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Fresnel effect value |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
{.shortcuts}
|
||||
<yel>Dissolve</yel> - generates a dissolve transition effect {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| Texture (sampler) | Input texture |
|
||||
| `Float` | Dissolve threshold |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Dissolve effect output |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
## Custom Function Node
|
||||
<yel>Distortion</yel> - warps the surface of the object {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Distortion strength |
|
||||
| `Vector2` | UV coordinates |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Warped UV coordinates |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Steps to Create a Custom Function Node:
|
||||
<yel>Reflection</yel> - reflects based on surface normal direction {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Incident direction |
|
||||
| `Vector3` | Surface normal |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Reflected direction |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
|
||||
### Advanced Nodes
|
||||
|
||||
<yel>World Position</yel> - returns the object's world space position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | World space position |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Object Position</yel> - returns the object's local space position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Local space position |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Screen Position</yel> - returns the object's screen space position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Screen space position |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Parallax</yel> - simulates depth using parallax mapping {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| Texture (sampler) | Input texture |
|
||||
| `Vector2` | UV coordinates |
|
||||
| `Float` | Depth value |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Adjusted UV coordinates|
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Camera Position</yel> - returns the camera's world space position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Camera world space position |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
### Custom Function Node
|
||||
|
||||
#### Steps to Create a Custom Function Node:
|
||||
|
||||
- **Add Custom Function Node**
|
||||
|
||||
**Step 1. Add Custom Function Node**
|
||||
|
||||
- Right-click in Shader Graph and choose **"Create Node"** > **"Custom Function"**.
|
||||
|
||||
**Step 2. Configure Node**
|
||||
- Set a name for the node and choose between **"String"** (inline code) or **"File"** (external HLSL file).
|
||||
- **Configure the Node**
|
||||
- Set a name and choose between **"String"** (inline code) or **"File"** (external HLSL file).
|
||||
|
||||
**Step 3. Add Inputs/Outputs**
|
||||
- Define inputs (e.g., float, vector) and outputs as needed.
|
||||
- **Add Inputs/Outputs**: Define inputs (e.g., float, vector) and outputs. Example:
|
||||
- **Inputs**: Float (time), Vector3 (position)
|
||||
- **Outputs**: Vector3 (new position)
|
||||
|
||||
**Step 4. Write Shader Code**
|
||||
- Enter the custom HLSL code in the appropriate field.
|
||||
- **Write Shader Code**: Enter the custom HLSL code. Example:
|
||||
|
||||
**Step 5. Utilize the Node**
|
||||
- Integrate the custom node into your shader graph for custom behavior.
|
||||
```hlsl
|
||||
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 {.cols-1}
|
||||
|
||||
- [Unity Shader Graph documentation](https://docs.unity3d.com/Manual/shader-graph-overview.html)
|
||||
_(docs.unity3d.com)_
|
||||
- [Unity Shader Graph documentation](https://docs.unity3d.com/Manual/shader-graph-overview.html) _(docs.unity3d.com)_
|
||||
- [Tianle Yuan's Unity Visual Effect notes](https://yuantianle.github.io/11_Game_Development/Unity/)
|
||||
_(yuantianle.com)_
|
||||
@@ -0,0 +1 @@
|
||||
<svg enable-background="new 0 0 2480 2417" viewBox="0 0 2480 2417" xmlns="http://www.w3.org/2000/svg"><path d="m1973.2 1682.9v-274.9l238.3-137.9 268.5-1001.6-1001.7-268.5-238.3 137.9-238.3-137.9-1001.7 268.5 267.5 997.1 1.8 5.5 237.4 137v275.8l733.3 733.1 729.6-729.6zm-733.2-1518.5 818.1 219.1-818.1 472.1-818.1-471.2zm-709.5 1230.8-219.1-819 818.1 472.1v945.1zm820-347 819.1-473-219.1 818.1-599.9 599.9v-945z"/><path d="m1129.5 1483.8v-436.5l-298.6 173.5z" fill="#dce5f4"/><path d="m830.9 1220.8-300.4 174.4 599 598.1v-509.5z" fill="#74a9c6"/><path d="m753.3 831.8 377.1 218.2-299.5 171.7z" fill="#7ca8c7"/><path d="m830.9 1221.7-300.4 172.6-219.1-817.2 441.9 254.8z" fill="#187da5"/><path d="m1351.4 1048.2 376.2-217.3-77.6 389.9z" fill="#5095be"/><path d="m1676.5 1265.6h-.9zm-.9 0h.9l-300.4 263" fill="#fff" stroke="#fff" stroke-miterlimit="10" stroke-width=".931"/><path d="m1650.9 1220.8h-.9l77.6-389.9 441.9-254.8-219.1 818.1z" fill="#185e86"/><path d="m1347.7 1047.3v436.5l304.1-262.1z" fill="#c3def4"/><path d="m1650 1219.9-.9-.9-298.6 262.1v510.4l598.1-597.2z" fill="#428eb6"/><path d="m1240 856.5 377.1-217.3-377.1-127.9z" fill="#f7d4c7"/><path d="m1240 510.4v.9l377.1 127.8 441-254.8-818.1-219.9z" fill="#f68b5c"/><path d="m1240.9 855.6-377.1-218.2 377.1-126z" fill="#f8a37a"/><path d="m1240.9 510.4v.9l-377.1 126-441.9-255.6 820-216.4z" fill="#ed5a2a"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
Reference in new issue
Block a user