Adaug proiectul Unity

This commit is contained in:
2026-11-01 23:39:55 +02:00
parent cb14d9d37d
commit 863eac8f2c
23463 changed files with 5412601 additions and 0 deletions
@@ -0,0 +1,13 @@
artifacts/**
build/**
/Editor/Testing*
/.collabignore
/.gitignore
/.gitmodules
.npmignore
upm-ci~/**
.Editor/**
.yamato/**
*.zip*
TestRunnerOptions.json
.idea/**
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d652dd37e32b64cc9b4e36a1e7ddf1b8
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
# Absolute Node
## Description
Returns the absolute value of the input **In**. Components of the input Dynamic Vector that are positive will remain positive and components that are negative will be inverted and become positive.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Absolute_float4(float4 In, out float4 Out)
{
Out = abs(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,47 @@
# Add inputs and outputs to a Sub Graph
To pass data in and out of a [Sub Graph](Sub-graph.md), create input and output ports.
## Create an input port
To create an input port, add a property to the blackboard of the Sub Graph. Follow these steps:
1. Open the Sub Graph asset.
2. In the Blackboard, click the **+** button and select the type of property you want to add.
3. Drag the property from the Blackboard into the graph area to create a Property Node.
When you add the Sub Graph to a shader graph, the property appears as an input port on the Sub Graph Node.
To display a float input as a slider or dropdown, or set an input value on the node instead of a port, refer to [Change how Sub Graph inputs appear on a node](Sub-Graph-Input-Display.md).
## Create an output port
To create an output port, add a port to the **Output** Node of the Sub Graph. Follow these steps:
1. Open the Sub Graph asset.
1. Select the **Output** node.
1. In the **Graph Inspector** window, select the **Node Settings** tab.
1. Under **Inputs**, select the Add (**+**) button.
1. Use the dropdown to select the output type.
When you add the Sub Graph to a shader graph, the property appears as an output port on the Sub Graph node.
## Avoid preview errors
The Preview window uses the first output port to generate the preview image. To avoid an error, ensure the first output port is one of the following data types:
- `Boolean`
- `Float`
- `Vector 2`
- `Vector 3`
- `Vector 4`
- `Matrix 2`
- `Matrix 3`
- `Matrix 4`
For more information, refer to [Custom Port Menu](Custom-Port-Menu.md).
## Additional resources
- [Change how sub graph inputs appear on a node](Sub-Graph-Input-Display.md)
- [Branch On Input Connection node](Branch-On-Input-Connection-Node.md)
@@ -0,0 +1,28 @@
# Add Node
## Description
Returns the sum of the two input values **A** and **B**.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| A | Input | Dynamic Vector | First input value |
| B | Input | Dynamic Vector | Second input value |
| Out | Output | Dynamic Vector | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Add_float4(float4 A, float4 B, out float4 Out)
{
Out = A + B;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,20 @@
# Add a Sub Graph to a shader graph
To add a [Sub Graph](Sub-graph.md) to a shader graph, use one of the following approaches:
- Drag the Sub Graph asset from the Project window into the Shader Graph window.
- In the Shader Graph window, right-click to open the context menu, then select **Create Node** > **Sub Graph** and the name of your Sub Graph.
Unity adds a Sub Graph node to the shader graph. For more information, refer to [Sub Graph Node](Sub-graph-Node.md).
## Change the location in the Create Node menu
To change the location of the Sub Graph in the **Create Node** menu, follow these steps:
1. Open the Sub Graph asset.
2. In the blackboard, select the gray **Sub Graphs** label.
3. Type the name of another folder from the **Create Node** menu, for example **Artistic**.
## Additional resources
- [Sub Graph node](Sub-graph-Node.md)
@@ -0,0 +1,27 @@
# All Node
## Description
Returns true if all components of the input **In** are non-zero. This is useful for [Branching](Branch-Node.md).
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| In | Input | Dynamic Vector | None | Input value |
| Out | Output | Boolean | None | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_All_float4(float4 In, out float Out)
{
Out = all(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,38 @@
# Ambient Node
## Description
Provides access to the Scene's **Ambient** color values. When Environment Lighting Source is set to **Gradient** [Port](Port.md) **Color/Sky** returns the value **Sky Color**. When Environment Lighting Source is set to **Color** [Port](Port.md) **Color/Sky** returns the value **Ambient Color**. [Ports](Port.md) **Equator** and **Ground** always return the values **Equator Color** and **Ground Color** regardless of the current Environment Lighting Source.
Note: Values of this [Node](Node.md) are only updated when entering Play mode or saving the current Scene/Project.
Note: The behavior of this [Node](Node.md) is undefined globally. Shader Graph does not define the function of the node. Instead, each Render Pipeline defines what HLSL code to execute for this [Node](Node.md).
Different Render Pipelines may produce different results. If you're building a shader in one Render Pipeline that you want to use in both, try checking it in both pipelines before production. A [Node](Node.md) might be defined in one Render Pipeline and undefined in the other. If this [Node](Node.md) is undefined, it returns 0 (black).
#### Unity Render Pipelines Support
- Universal Render Pipeline
The High Definition Render Pipeline does **not** support this Node.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Color/Sky | Output | Vector 3 | None | Color (Color) or Sky (Gradient) color value |
| Equator | Output | Vector 3 | None | Equator (Gradient) color value |
| Ground | Output | Vector 3 | None | Ground (Gradient) color value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
float3 _Ambient_ColorSky = SHADERGRAPH_AMBIENT_SKY;
float3 _Ambient_Equator = SHADERGRAPH_AMBIENT_EQUATOR;
float3 _Ambient_Ground = SHADERGRAPH_AMBIENT_GROUND;
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,26 @@
# And Node
## Description
Returns true if both the inputs **A** and **B** are true. This is useful for [Branching](Branch-Node.md).
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| A | Input | Boolean | None | First input value |
| B | Input | Boolean | None | Second input value |
| Out | Output | Boolean | None | Output value |
## Generated Code Example
```
void Unity_And(float A, float B, out float Out)
{
Out = A && B;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Any Node
## Description
Returns true if any of the components of the input **In** are non-zero. This is useful for [Branching](Branch-Node.md).
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| In | Input | Dynamic Vector | None | Input value |
| Out | Output | Boolean | None | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Any_float4(float4 In, out float Out)
{
Out = any(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,51 @@
# Append Node
## Description
Creates a new vector **Out** by combining the channels of input **A** followed by the channels of input **B**.
Inputs **A** and **B** can have up to **three** channels.
**Out** can have **two** to **four** channels, depending on the combination of channels of the inputs.
Input **A** channels take priority over input **B** to combine up to a maximum of **four** in the output.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| A | Input | Dynamic | None | First input value |
| B | Input | Dynamic | None | Second input value |
| Out | Output | Dynamic | None | Combined vector from A and B |
## Example graph usage
In the following example, an **Append** node combines a **Vector 2** and a **Float**. The resulting output vector has the following 3 channels:
- The first channel is the **X** from the **Vector 2**.
- The second channel is the **Y** from the **Vector 2**.
- The third channel is the **X** from the **Float**.
Notice that with an Append node, you don't need to use a Split node to break up the Vector 2 into individual channels, then a Combine node to combine the 3 separate channels.
![An image of the Graph window that shows a Vector 2 node and a Float node with their outputs connected to the inputs of an Append node.](images/sg-append-node-example.png)
## Generated Code Example
The following example code represents one possible outcome of this node for different inputs combinations.
### Vector2 and Float
```
float3 Append_Out = float3( A.xy, B.x);
```
### Float and Vector3
```
float4 Append_Out = float4( A.x, B.xyz);
```
### Vector3 and Vector2
```
float4 Append_Out = float4( A.xyz, B.x);
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Arccosine Node
## Description
Returns the arccosine of each component of the input **In** as a vector of the same dimension and equal length. Each component should be within the range of -1 to 1.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | The arccosine of the input value, in radians |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Arccosine_float4(float4 In, out float4 Out)
{
Out = acos(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Arcsine Node
## Description
Returns the arcsine of each component of the input **In** as a vector of the same dimension and equal length. Each component should be within the range of -Pi/2 to Pi/2.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | The arcsine of the input value, in radians |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Arcsine_float4(float4 In, out float4 Out)
{
Out = asin(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Arctangent Node
## Description
Returns the arctangent of the value of input **In**. Each component should be within the range of -Pi/2 to Pi/2.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | The arctangent of the input value, in radians |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Arctangent_float4(float4 In, out float4 Out)
{
Out = atan(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,28 @@
# Arctangent2 Node
## Description
Returns the arctangent of the values of both input **A** and input **B**. The signs (whether they are positive or negative values) of the input values are used to determine whether the output components, or channels, are positive or negative within a range of -Pi to Pi.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| A | Input | Dynamic Vector | First input value |
| B | Input | Dynamic Vector | Second input value |
| Out | Output | Dynamic Vector | The arctangent of both inputs, in radians |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Arctangent2_float4(float4 A, float4 B, out float4 Out)
{
Out = atan2(A, B);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,56 @@
# Artistic nodes
Adjust colors, blend layers, filter images, mask regions, manipulate normal maps, and convert color spaces.
## Adjustment
| **Topic** | **Description** |
|:---------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Channel Mixer](Channel-Mixer-Node.md) | Controls the amount each of the channels of input In contribute to each of the output channels. |
| [Contrast](Contrast-Node.md) | Adjusts the contrast of input In by the amount of input Contrast. |
| [Hue](Hue-Node.md) | Offsets the hue of input In by the amount of input Offset. |
| [Invert Colors](Invert-Colors-Node.md) | Inverts the colors of input In on a per channel basis. |
| [Replace Color](Replace-Color-Node.md) | Replaces values in input In equal to input From to the value of input To. |
| [Saturation](Saturation-Node.md) | Adjusts the saturation of input In by the amount of input Saturation. |
| [White Balance](White-Balance-Node.md) | Adjusts the temperature and tint of input In by the amount of inputs Temperature and Tint respectively. |
## Blend
| **Topic** | **Description** |
|:-----------------------|----------------------------------------------------------------------------------------------------|
| [Blend](Blend-Node.md) | Blends the value of input Blend onto input Base using the blending mode defined by parameter Mode. |
## Filter
| **Topic** | **Description** |
|:-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Dither](Dither-Node.md) | Dither is an intentional form of noise used to randomize quantization error. It is used to prevent large-scale patterns such as color banding in images.. |
## Mask
| **Topic** | **Description** |
|--------------------------------------|---------------------------------------------------------------------|
| [Channel Mask](Channel-Mask-Node.md) | Masks values of input In on channels selected in dropdown Channels. |
| [Color Mask](Color-Mask-Node.md) | Creates a mask from values in input In equal to input Mask Color. |
## Normal
| **Topic** | **Description** |
|--------------------------------------------------|---------------------------------------------------------------------------------------------|
| [Normal Blend](Normal-Blend-Node.md) | Blends two normal maps defined by inputs A and B together. |
| [Normal From Height](Normal-From-Height-Node.md) | Creates a normal map from a height map defined by input Texture. |
| [Normal Strength](Normal-Strength-Node.md) | Adjusts the strength of the normal map defined by input In by the amount of input Strength. |
| [Normal Unpack](Normal-Unpack-Node.md) | Unpacks a normal map defined by input In. |
## Utility
| **Topic** | **Description** |
|--------------------------------------------------------|----------------------------------------------------------------------------------------------|
| [Colorspace Conversion](Colorspace-Conversion-Node.md) | Returns the result of converting the value of input In from one colorspace space to another. |
@@ -0,0 +1,44 @@
# Baked GI Node
## Description
Provides access to the **Baked GI** values at the vertex or fragment's position. Requires **Position** and **Normal** input for light probe sampling, and lightmap coordinates **Static UV** and **Dynamic UV** for all potential lightmap sampling cases.
Note: The behavior of this [Node](Node.md) is undefined globally. Shader Graph does not define the function of the node. Instead, each Render Pipeline defines what HLSL code to execute for this [Node](Node.md).
Different Render Pipelines may produce different results. If you're building a shader in one Render Pipeline that you want to use in both, try checking it in both pipelines before production. A [Node](Node.md) might be defined in one Render Pipeline and undefined in the other. If this [Node](Node.md) is undefined, it returns 0 (black).
### Unity Render Pipelines Support
This node is compatible with both the High Definition Render Pipeline (HDRP) and the Universal Render Pipeline (URP). However, this node does not work within unlit shaders for either pipeline.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Position | Input | Vector 3 | Position (world space) | Mesh vertex/fragment's **Position** |
| Normal | Input | Vector 3 | Normal (world space) | Mesh vertex/fragment's **Normal** |
| Static UV | Input | Vector 2 | UV1 | Lightmap coordinates for the static lightmap |
| Dynamic UV | Input | Vector 2 | UV2 | Lightmap coordinates for the dynamic lightmap |
| Out | Output | Vector 3 | None | Output color value |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| Apply Lightmap Scaling | Toggle | True, False | If enabled lightmaps are automatically scaled and offset. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_BakedGI_float(float3 Position, float3 Normal, float2 StaticUV, float2 DynamicUV, out float Out)
{
Out = SHADERGRAPH_BAKED_GI(Position, Normal, StaticUV, DynamicUV, false);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,25 @@
# Bitangent Node
## Description
Provides access to the mesh vertex or fragment's **Bitangent Vector**, depending on the effective [Shader Stage](Shader-Stage.md) of the graph section the [Node](Node.md) is part of.
The bitangent vector is derived from the normal and tangent vectors and is orthogonal to both. The three vectors provide a reference frame to perform complex light calculations, for example.
You can select the coordinate space of the output with the **Space** dropdown parameter.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Out | Output | Vector 3 | None | **Bitangent Vector** for the Mesh Vertex/Fragment. |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| Space | Dropdown | Object, View, World, Tangent | Selects coordinate space of **Bitangent Vector** to output. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,78 @@
# Blackboard
## Description
You can use the Blackboard to define, order, and categorize the [Properties](Property-Types.md) and [Keywords](Keywords.md) in a graph. From the Blackboard, you can also edit the path for the selected Shader Graph Asset or Sub Graph.
![The blackboard layout with properties, keywords, and categories.](images/blackboardcategories1.png)
## Accessing the Blackboard
The Blackboard is visible by default, and you cannot drag it off the graph and lose it. However, you are able to position it anywhere in the [Shader Graph Window](Shader-Graph-Window.md). It always maintains the same distance from the nearest corner, even if you resize the window.
## Adding properties and keywords to the Blackboard
To create a new property or keyword, click the **Add (+)** button on the Blackboard's title bar and select a type. For a full list of property types, see [Property Types](Property-Types.md).
## Editing properties and keywords
Select a property or keyword in the Blackboard or graph to modify its settings in the Node Settings Menu.
| Setting | Description |
|-----------|-------------|
| Name | The property's display name. The Editor strips quotation marks from display names and replaces them with underscores. Rename an item via the Blackboard by double-clicking on its name. |
| Reference | The name that Shader Graph uses internally for this property. Although the Editor populates this value by default, you can modify it. To revert to the original reference name, right-click on the word **Reference** (not the entry field) and select **Reset Reference** in the context menu. If the Reference Name contains any characters that HLSL does not support, the Editor replaces those characters with underscores. |
| Default | The default value of this property in any Material based on this Shader Graph. For example, if you have a Shader Graph for grass and expose the grass color as a property, you might set the default to Green.|
| Precision | Set the precision mode for the property. See [Precision Modes](Precision-Modes.md). |
| Exposed | Enable this setting to make the property available for you to edit via the C# API. Enabled by default. |
## Modifying and selecting keywords and properties
* To reorder items listed on the Blackboard, drag and drop them.
* To delete items, use the Delete key on Windows or Command + Backspace keys on macOS.
* To select multiple items, hold down the Ctrl key while making your selections.
* To cancel the selection of one or multiple items, hold down the Ctrl key while clicking on the items you want to remove from the selection.
## Using Blackboard categories
To make the properties in your shader more discoverable, organize them into categories. Expand and collapse categories to make the Blackboard easier to navigate.
### Creating, renaming, moving, and deleting categories
* To add a category, use **+** on the Blackboard.
* To rename a category, double-click on the category name, or right-click and select **Rename**.
* To move a category within the Blackboard, select and drag it.
* To remove a category, select it and press **Delete**, or right-click and select **Delete**. Deleting a category also deletes the properties within it, so move those you wish to keep.
### Adding, removing, and reordering properties and keywords
* To add a property or keyword to a category, expand the category with the foldout (⌄) symbol, then drag and drop the property or keyword onto the expanded category.
* To remove a property or keyword, select it and press **Delete**, or right-click and select **Delete**.
* To re-order properties or keywords, drag and drop them within a category or move them into other categories.
### Creating a category for specific properties and keywords
Select multiple properties or keywords and use **+** on the Blackboard to create a category that contains all of the items you have selected.
### Copying and pasting categories, with or without properties
You can paste empty categories, categories with all of their properties, and categories with some of their properties into one or more graphs. To copy a category with all of its properties:
1. Select the property.
2. Copy it with **Ctrl+C**.
3. Paste it into your target graph with **Ctrl+V**.
To copy a specific set of properties:
1. Select the category.
2. Hold down the Ctrl key.
3. Click the properties you do not want to include to remove them from the selection.
4. Copy the property with **Ctrl+C**.
5. Paste it into your target graph with **Ctrl+V**.
### Using categories in the Material Inspector
To modify a material you have created with a Shader Graph, you can adjust specific property or keyword values in the Material Inspector, or edit the graph itself.
#### Working with Streaming Virtual Textures
[Streaming Virtual Texture Properties](https://docs.unity3d.com/Documentation/Manual/svt-use-in-shader-graph.html) sample texture layers. To access these layers in the Material Inspector, expand the relevant **Virtual Texture** section with the ⌄ symbol next to its name. You can add and remove layers via the Inspector.
## Exposing properties and keywords
Unity exposes properties and keywords by default. This enables write access from scripts, so that you can edit them via the C# API, in addition to the graph. Exposed items have a green dot in their label. Enable or disable this feature in the **Node Settings** menu.
If you disable the **Exposed** setting of a property, the property reverts to the default value and no longer uses the custom value you set.
## Creating nodes
Drag a property or keyword from the Blackboard into the graph to create a node of that kind. Settings for a node in the graph are identical to those for the related property or keyword in the Blackboard. Expand these nodes to use a sub-member of the property value.
Property node names include a green dot if the property is exposed.
@@ -0,0 +1,37 @@
# Blackbody Node
## Description
Samples a **Gradient** that simulates the effect of black body radiation.
The calculations in this node are based on data gathered by Mitchell Charity.
This node outputs color in linear RGB space and preforms the conversion using a D65 whitepoint and a CIE 1964 10 degree color space.
For more information, see [What color is a blackbody?](http://www.vendian.org/mncharity/dir3/blackbody/)
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Temperature | Input | Float | None | Temperature or temperature map in Kelvin to sample. |
| Out | Output | Vector 3 | None | Intensity represented by color in Vector 3. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Blackbody_float(float Temperature, out float3 Out)
{
float3 color = float3(255.0, 255.0, 255.0);
color.x = 56100000. * pow(Temperature,(-3.0 / 2.0)) + 148.0;
color.y = 100.04 * log(Temperature) - 623.6;
if (Temperature > 6500.0) color.y = 35200000.0 * pow(Temperature,(-3.0 / 2.0)) + 184.0;
color.z = 194.18 * log(Temperature) - 1448.6;
color = clamp(color, 0.0, 255.0)/255.0;
if (Temperature < 1000.0) color *= Temperature/1000.0;
Out = color;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,261 @@
# Blend Node
## Description
Blends the value of input **Blend** onto input **Base** using the blending mode defined by the **Mode** parameter. The strength of the blend is defined by input **Opacity**. An **Opacity** value of 0 will return the input **Base**, unaltered.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Base | Input | Dynamic Vector | None | Base layer value |
| Blend | Input | Dynamic Vector | None | Blend layer value |
| Opacity | Input | Float | None | Strength of blend |
| Out | Output | Dynamic Vector | None | Output value |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| Mode | Dropdown | Burn, Darken, Difference, Dodge, Divide, Exclusion, HardLight, HardMix, Lighten, LinearBurn, LinearDodge, LinearLight, LinearLightAddSub, Multiply, Negation, Overlay, PinLight, Screen, SoftLight, Subtract, VividLight, Overwrite | Blend mode to apply |
## Generated Code Example
The following example code represents one possible outcome of this node per blend mode.
**Burn**
```
void Unity_Blend_Burn_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = 1.0 - (1.0 - Blend)/Base;
Out = lerp(Base, Out, Opacity);
}
```
**Darken**
```
void Unity_Blend_Darken_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = min(Blend, Base);
Out = lerp(Base, Out, Opacity);
}
```
**Difference**
```
void Unity_Blend_Difference_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = abs(Blend - Base);
Out = lerp(Base, Out, Opacity);
}
```
**Dodge**
```
void Unity_Blend_Dodge_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Base / (1.0 - Blend);
Out = lerp(Base, Out, Opacity);
}
```
**Divide**
```
void Unity_Blend_Divide_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Base / (Blend + 0.000000000001);
Out = lerp(Base, Out, Opacity);
}
```
**Exclusion**
```
void Unity_Blend_Exclusion_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Blend + Base - (2.0 * Blend * Base);
Out = lerp(Base, Out, Opacity);
}
```
**HardLight**
```
void Unity_Blend_HardLight_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
float4 result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
float4 result2 = 2.0 * Base * Blend;
float4 zeroOrOne = step(Blend, 0.5);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
```
**HardMix**
```
void Unity_Blend_HardMix_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = step(1 - Base, Blend);
Out = lerp(Base, Out, Opacity);
}
```
**Lighten**
```
void Unity_Blend_Lighten_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = max(Blend, Base);
Out = lerp(Base, Out, Opacity);
}
```
**LinearBurn**
```
void Unity_Blend_LinearBurn_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Base + Blend - 1.0;
Out = lerp(Base, Out, Opacity);
}
```
**LinearDodge**
```
void Unity_Blend_LinearDodge_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Base + Blend;
Out = lerp(Base, Out, Opacity);
}
```
**LinearLight**
```
void Unity_Blend_LinearLight_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Blend < 0.5 ? max(Base + (2 * Blend) - 1, 0) : min(Base + 2 * (Blend - 0.5), 1);
Out = lerp(Base, Out, Opacity);
}
```
**LinearLightAddSub**
```
void Unity_Blend_LinearLightAddSub_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Blend + 2.0 * Base - 1.0;
Out = lerp(Base, Out, Opacity);
}
```
**Multiply**
```
void Unity_Blend_Multiply_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Base * Blend;
Out = lerp(Base, Out, Opacity);
}
```
**Negation**
```
void Unity_Blend_Negation_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = 1.0 - abs(1.0 - Blend - Base);
Out = lerp(Base, Out, Opacity);
}
```
**Overlay**
```
void Unity_Blend_Overlay_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
float4 result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
float4 result2 = 2.0 * Base * Blend;
float4 zeroOrOne = step(Base, 0.5);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
```
**PinLight**
```
void Unity_Blend_PinLight_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
float4 check = step (0.5, Blend);
float4 result1 = check * max(2.0 * (Base - 0.5), Blend);
Out = result1 + (1.0 - check) * min(2.0 * Base, Blend);
Out = lerp(Base, Out, Opacity);
}
```
**Screen**
```
void Unity_Blend_Screen_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = 1.0 - (1.0 - Blend) * (1.0 - Base);
Out = lerp(Base, Out, Opacity);
}
```
**SoftLight**
```
void Unity_Blend_SoftLight_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
float4 result1 = 2.0 * Base * Blend + Base * Base * (1.0 - 2.0 * Blend);
float4 result2 = sqrt(Base) * (2.0 * Blend - 1.0) + 2.0 * Base * (1.0 - Blend);
float4 zeroOrOne = step(0.5, Blend);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
```
**Subtract**
```
void Unity_Blend_Subtract_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = Base - Blend;
Out = lerp(Base, Out, Opacity);
}
```
**VividLight**
```
void Unity_Blend_VividLight_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
float4 result1 = 1.0 - (1.0 - Blend) / (2.0 * Base);
float4 result2 = Blend / (2.0 * (1.0 - Base));
float4 zeroOrOne = step(0.5, Base);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
```
**Overwrite**
```
void Unity_Blend_Overwrite_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
Out = lerp(Base, Blend, Opacity);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,11 @@
# Block node reference
Block nodes are a specific type of node for the [Master Stack](Master-Stack.md). Each Block represents one piece of surface or vertex data that Shader Graph uses in the final shader output.
| Page | Description |
| :--- | :--- |
| [Built-In Blocks](Built-In-Blocks.md) | Block nodes that are always available, regardless of the active render pipeline. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,29 @@
# Boolean Node
## Description
Defines a constant **Boolean** value in the [Shader Graph](index.md), although internally to the shader this is treated as a constant **float** value that is ether 0 or 1, similar to Shaderlab's [Toggle](https://docs.unity3d.com/ScriptReference/MaterialPropertyDrawer.html) property. Can be converted to a **Boolean** type [Property](Property-Types.md) via the [Node's](Node.md) context menu.
## Ports
| Name | Direction | Type | Binding | Description |
|:--- |:---|:---|:---|:---|
| Out | Output | Boolean | None | Output value |
## Controls
| Control | Description |
|:---|:---|
| (Checkbox) | Defines the output value. |
## Generated Code Example
The following basic test code represents one possible outcome of this node with the Boolean value set to 0:
```
float _Boolean = 0;
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,29 @@
# Branch node
The Branch node adds a dynamic branch to the shader, which outputs a different value depending on whether the input is true or false.
Both sides of the branch are evaluated in the shader, and the output from the unused path is discarded.
## Ports
| **Name** | **Direction** | **Type** | **Binding** | **Description** |
|:----------|:----------|:---------------|:--------|:------------|
| **Predicate** | Input | Boolean | None | The input to test the value of. If you input a float, all values are evaluated as `true` except `0`. |
| **True** | Input | Dynamic Vector | None | The value to output as **Out** if **Predicate** is true. |
| **False** | Input | Dynamic Vector | None | The value to output as **Out** if **Predicate** is false. |
| **Out** | Output | Dynamic Vector | None | Outputs either **True** or **False**. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Branch_float4(float Predicate, float4 True, float4 False, out float4 Out)
{
Out = Predicate ? True : False;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,41 @@
# Branch On Input Connection node
The Branch On Input Connection node allows you to change the behavior of a [Sub Graph](Sub-graphs.md) based on the connected state of an input property in the parent shader graph. Use the Branch On Input Connection node to create a default input for a port.
For more information, refer to [Set default inputs for a Sub Graph](Sub-Graph-Default-Property-Values.md).
The node generates branching HLSL source code, but during compilation Unity optimizes the branch out of your shader.
You can only use a Branch on Input Connection node in a [Sub Graph](Sub-graphs.md).
## Inputs
The Branch On Input Connection [!include[nodes-inputs](./snippets/nodes-inputs.md)] <!-- MULTIPLE INPUT PORTS INCLUDE -->
| **Name** | **Type** | **Description** |
| :--- | :------ | :---------- |
| **Input** | Property | The property that determines the branching logic in the node, based on its connection state in the parent Shader Graph. |
| **Connected** | Dynamic Vector | The value to send to the **Out** port when **Input** is connected in the parent Shader Graph. |
| **NotConnected** | Dynamic Vector | The value to send to the **Out** port when **Input** isn't connected in the parent Shader Graph. |
## Outputs
The Branch On Input Connection [!include[nodes-single-output](./snippets/nodes-single-output.md)] <!-- SINGLE OUTPUT PORT INCLUDE -->
| **Name** | **Type** | **Description** |
| :------ | :------- | :------------- |
| **Out** | Dynamic Vector | Outputs the value of either **Connected** or **NotConnected**, based on the **Input** property's connection state in the parent Shader Graph. |
## Related nodes
<!-- OPTIONAL. Any nodes that may be related to this node in some way that's worth mentioning -->
[!include[nodes-related](./snippets/nodes-related.md)] Branch On Input Connection node:
- [Branch node](Branch-Node.md)
- [Subgraph node](Sub-graph-Node.md)
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,37 @@
# Built-In Blocks
Define standard inputs and outputs for the Master Stack.
## Vertex Blocks
Set per-vertex attributes and pass data to fragments.
| Name | Type | Binding | Description |
|:--------------------|:---------|:----------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Position | Vector 3 | Object Space Position | Defines the absolute object space vertex position per vertex. |
| Normal | Vector 3 | Object Space Normal | Defines the absolute object space vertex normal per vertex. |
| Tangent | Vector 3 | Object Space Tangent | Defines the absolute object space vertex tangent per vertex. |
| Color | Vector 4 | Vertex Color | Defines vertex color. Expected range 0 - 1. |
| Custom Interpolator | Vector 4, vector 3, vector 2, or float | Custom Interpolator | Passes custom data from the vertex stage to the fragment stage. |
## Fragment Blocks
Specify per-pixel material properties used for shading.
| Name | Type | Binding | Description |
|:-----------------------|:---------|:---------------------|:-----------------------------------------------------------------------------------------------|
| Base Color | Vector 3 | None | Defines material's base color value. Expected range 0 - 1. |
| Normal (Tangent Space) | Vector 3 | Tangent Space Normal | Defines material's normal value in tangent space. |
| Normal (Object Space) | Vector 3 | Object Space Normal | Defines material's normal value in object space. |
| Normal (World Space) | Vector 3 | World Space Normal | Defines material's normal value in world space. |
| Emission | Vector 3 | None | Defines material's emission color value. Expects positive values. |
| Metallic | Float | None | Defines material's metallic value, where 0 is non-metallic and 1 is metallic. |
| Specular | Vector 3 | None | Defines material's specular color value. Expected range 0 - 1. |
| Smoothness | Float | None | Defines material's smoothness value. Expected range 0 - 1. |
| Ambient Occlusion | Float | None | Defines material's ambient occlusion value. Expected range 0 - 1. |
| Alpha | Float | None | Defines material's alpha value. Used for transparency and/or alpha clip. Expected range 0 - 1. |
| Alpha Clip Threshold | Float | None | Fragments with an alpha below this value are discarded. Expected range 0 - 1. |
## Additional resources
[Add a custom interpolator](Custom-Interpolators.md)
@@ -0,0 +1,73 @@
# Calculate Level Of Detail Texture 2D node
The Calculate Level of Detail Texture 2D node takes an input **Texture 2D** and outputs the mip level of a Texture sample. This node is useful in situations where you need to know the mip level of a Texture, such as when you might want to modify the mip level before sampling in your shader.
![An image of the Graph window, that shows a Calculate Level of Detail Texture 2D node.](images/sg-calculate-level-detail-Texture-2d-node.png)
The Calculate Level of Detail Texture 2D node also has a clamped and unclamped mode:
- **Clamped**: The node clamps the returned mip level to the actual mips available on the Texture. The node uses the [CalculateLevelOfDetail](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-calculate-lod) HLSL intrinsic function. Use this mode when you want to know which mip to sample your Texture from and restrict the result to an existing mip.
- **Unclamped**: The node returns the ideal mip level, based on an idealized Texture with all its mips present. The node uses the [CalculateLevelOfDetailUnclamped](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-calculate-lod-unclamped) HLSL intrinsic function. Use this mode when you need a more generic value for your mip level.
For example, a Texture might only have 3 mips: a 64×64 mip, a 32×32 mip, and a 16×16 mip. When you use the Calculate Level Of Detail Texture 2D node in its **Clamped** mode, the node restricts the **LOD** output to one of the 3 mips on the Texture, even if the ideal mip level might be a smaller resolution, such as an 8×8 version. In its **Unclamped** mode, the node outputs the ideal 8×8 mip level, even though it doesn't exist on the Texture.
> [!NOTE]
> On platforms where these HLSL functions don't exist, Shader Graph determines an appropriate approximation to use, instead.
## Create Node menu category
The Calculate Level of Detail Texture 2D node is under the **Input** &gt; **Texture** category in the Create Node menu.
## Limitations
The Calculate Level of Detail Texture 2D [!include[nodes-fragment-only](./snippets/nodes-fragment-only.md)] <!-- FRAGMENT ONLY INCLUDE -->
## Inputs
The Calculate Level of Detail Texture 2D [!include[nodes-inputs](./snippets/nodes-inputs.md)]
| **Name** | **Type** | **Binding** | **Description** |
| :--- | :------ | :------ | :---------- |
| **Texture** | Texture 2D | None | The Texture to use in the mip level calculation. |
| **UV** | Vector 2 | UV | The UV coordinate to use to calculate the Texture's mip level. |
| **Sampler** | SamplerState | None | The Sampler State and corresponding settings to use to calculate the Texture's mip level. |
## Controls
The Calculate Level of Detail Texture 2D [!include[nodes-single-control](./snippets/nodes-single-control.md)]
| **Name** | **Type** | **Options** | **Description** |
| :--- | :--- | :------ | :---------- |
| **Clamp** | Toggle | True, False | When enabled, Shader Graph clamps the output mip level to the actual mips present on the provided **Texture** input. When disabled, Shader Graph returns an ideal mip level, based on an idealized Texture with all its mips present. |
## Outputs
The Calculate Level of Detail Texture 2D [!include[nodes-single-output](./snippets/nodes-single-output.md)] <!-- SINGLE OUTPUT PORT INCLUDE -->
| **Name** | **Type** | **Description** |
| :------ | :------- | :------------- |
| **LOD** | Float | The final calculated mip level of the Texture. |
## Example graph usage
In the following example, a Calculate Level of Detail Texture 2D node calculates the mip level of the **Leaves_Albedo** Texture for a set of UV coordinates and a specific Sampler State. It sends the calculated mip level for the Texture to the **LOD** input port on a Sample Texture 2D LOD node, which samples the same Texture:
![An image of the Graph window, that displays a Texture 2D asset node connected to a Calculate Level of Detail Texture 2D node. The node sends the calculated mip level as an input to the LOD input port on a Sample Texture 2D LOD node.](images/sg-calculate-level-detail-Texture-2d-node-example.png)
## Related nodes
<!-- OPTIONAL. Any nodes that may be related to this node in some way that's worth mentioning -->
[!include[nodes-related](./snippets/nodes-related.md)] Calculate Level of Detail Texture 2D node:
- [Sample Texture 2D LOD node](Sample-Texture-2D-LOD-Node.md)
- [Sampler State node](Sampler-State-Node.md)
- [Gather Texture 2D node](Gather-Texture-2D-Node.md)
- [Texture 2D Asset node](Texture-2D-Asset-Node.md)
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,42 @@
# Camera Node
## Description
Provides access to various parameters of the **Camera** currently being used for rendering. This is comprised of values the **Camera**'s GameObject, such as Position and Direction, as well as various projection parameters.
#### Unity Render Pipelines Support
- Universal Render Pipeline
The High Definition Render Pipeline does **not** support this Node.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Position | Output | Vector 3 | None | Position of the Camera's GameObject in world space |
| Direction | Output | Vector 3 | None | The Camera's forward vector direction |
| Orthographic | Output | Float | None | Returns 1 if the Camera is orthographic, otherwise 0 |
| Near Plane | Output | Float | None | The Camera's near plane distance |
| Far Plane | Output | Float | None | The Camera's far plane distance |
| Z Buffer Sign | Output | Float | None | Returns -1 when using a reversed Z Buffer, otherwise 1 |
| Width | Output | Float | None | The Camera's width if orthographic |
| Height | Output | Float | None | The Camera's height if orthographic |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
float3 _Camera_Position = _WorldSpaceCameraPos;
float3 _Camera_Direction = -UNITY_MATRIX_V[2].xyz;
float _Camera_Orthographic = unity_OrthoParams.w;
float _Camera_NearPlane = _ProjectionParams.y;
float _Camera_FarPlane = _ProjectionParams.z;
float _Camera_ZBufferSign = _ProjectionParams.x;
float _Camera_Width = unity_OrthoParams.x;
float _Camera_Height = unity_OrthoParams.y;
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Ceiling Node
## Description
Returns the smallest integer value, or whole number, that is greater than or equal to the value of input **In**.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Ceiling_float4(float4 In, out float4 Out)
{
Out = ceil(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,45 @@
# Change the behavior of a Sub Graph with a dropdown
To set up a [Sub Graph](Sub-graph.md) so you can change its behavior using a dropdown menu in shader graphs, use a **Dropdown** node. You can specify the number of options that appear in the dropdown menu, and their names.
## Create a dropdown
Follow these steps:
1. From the **Project** window, open a Sub Graph asset.
2. In the Blackboard, select **Add** (+), then select **Dropdown**.
**Note**: The **Dropdown** property appears only in the Blackboard for Sub Graphs, not regular shader graphs.
3. Drag the new **Dropdown** property from the Blackboard to the Sub Graph. Unity creates a **Dropdown** node.
When you add the Sub Graph to a shader graph, the **Sub Graph** node now has a dropdown menu with **A** and **B** options.
## Customize the dropdown options
To customize the options in the dropdown menu, follow these steps:
1. In the Sub Graph, select the **Dropdown** property in the Blackboard window.
2. In the **Graph Inspector** window, select the **Node Settings** tab.
3. Next to **Entries**, select the **Add** (**+**) button to add a new option, or the **Remove** (**-**) button to remove an option. The minimum number of options is two.
Each option you add adds a corresponding input port to the **Dropdown** node.
## Set up the output for each option
To set up the output for each option in the dropdown menu, follow these steps:
1. Connect a node or set of nodes to each input port on the **Dropdown** node. Each input becomes active when the corresponding option is selected in the dropdown menu.
2. Connect the **Out** port to the **Output** node.
Each input port has the Dynamic Vector type, which allows you to connect any Vector type. For more information, refer to [Dynamic Data Types](Data-Types.md#dynamic-data-types).
## Example
In the following example, a Subgraph Dropdown node changes the UV channel it sends to the Subgraph's Output node. The selection on the Subgraph node in the parent graph changes whether the Subgraph outputs **UV1** or **UV0**. If the Subgraph is used in multiple Shader Graphs, the Subgraph Dropdown node can change the UV channel output without changing the Subgraph:
![An image of the Graph window. The first input port on a Subgraph Dropdown node connects to a UV node and receives UV0. The second input port connects to a UV node and receives UV1. The Subgraph Dropdown node sends its output to the Subgraph's Output node.](images/sg-subgraph-dropdown-node-example-2.png)
## Additional resources
- [Sub Graphs](Sub-graph.md)
@@ -0,0 +1,33 @@
# Channel Mask Node
## Description
Masks values of input **In** on channels selected in dropdown **Channels**. Outputs a vector of the same length as the input vector but with the selected channels set to 0. Channels available in the dropdown **Channels** will represent the amount of channels present in input **In**.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| In | Input | Dynamic Vector | None | Input value |
| Out | Output | Dynamic Vector | None | Output value |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| Channels | Mask Dropdown | Dynamic | Selects any number of channels to mask |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_ChannelMask_RedGreen_float4(float4 In, out float4 Out)
{
Out = float4(0, 0, In.b, In.a);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,42 @@
# Channel Mixer Node
## Description
Controls the amount each of the channels of input **In** contribute to each of the channels of output **Out**. The slider parameters on the node control the contribution of each of the input channels. The toggle button parameters control which of the output channels is currently being edited. Slider controls for editing the contribution of each input channnel range between -2 and 2.
## Ports
| Name | Direction | Type | Binding | Description |
|:---|:---|:---|:---|:---|
| In | Input | Vector 3 | None | Input value |
| Out | Output | Vector 3 | None | Output value |
## Controls
| Control | Description |
|:---|:---|
| **R**, **G**, **B** (toggle buttons) | Selects the output channel to edit with the sliders. |
| **R** (slider) | Controls the contribution of the input red channel to the selected output channel. |
| **G** (slider) | Controls the contribution of the input green channel to the selected output channel. |
| **B** (slider) | Controls the contribution of the input blue channel to the selected output channel. |
## Shader Function
## Generated Code Example
The following example code represents one possible outcome of this node.
```
_ChannelMixer_Red = float3 (OutRedInRed, OutRedInGreen, OutRedInBlue);
_ChannelMixer_Green = float3 (OutGreenInRed, OutGreenInGreen, OutGreenInBlue);
_ChannelMixer_Blue = float3 (OutBlueInRed, OutBlueInGreen, OutBlueInBlue);
void Unity_ChannelMixer_float(float3 In, float3 _ChannelMixer_Red, float3 _ChannelMixer_Green, float3 _ChannelMixer_Blue, out float3 Out)
{
Out = float3(dot(In, _ChannelMixer_Red), dot(In, _ChannelMixer_Green), dot(In, _ChannelMixer_Blue));
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,11 @@
# Channel nodes
Combine, split, reorder, or flip vector and color channels.
| **Topic** | **Description** |
|----------------------------|-------------------------------------------------------------------------------------|
| [Append](Append-Node.md) | Combine two float or vector inputs into a single new vector of variable dimensions. |
| [Combine](Combine-Node.md) | Creates new vectors from the four inputs R, G, B and A. |
| [Flip](Flip-Node.md) | Flips the individual channels of input In selected by the node's parameters. |
| [Split](Split-Node.md) | Splits the input vector In into four Float outputs R, G, B and A. |
| [Swizzle](Swizzle-Node.md) | Creates a new vector from the reordered elements of the input vector. |
@@ -0,0 +1,39 @@
# Checkerboard Node
## Description
Generates a checkerboard of alternating colors between inputs **Color A** and **Color B** based on input **UV**. The checkerboard scale is defined by input **Frequency**.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| UV | Input | Vector 2 | UV | Input UV value |
| Color A | Input | Color RGB | None | First checker color |
| Color B | Input | Color RGB | None | Second checker color |
| Frequency | Input | Vector 2 | None | Scale of checkerboard per axis |
| Out | Output | Vector 2 | None | Output UV value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Checkerboard_float(float2 UV, float3 ColorA, float3 ColorB, float2 Frequency, out float3 Out)
{
UV = (UV.xy + 0.5) * Frequency;
float4 derivatives = float4(ddx(UV), ddy(UV));
float2 duv_length = sqrt(float2(dot(derivatives.xz, derivatives.xz), dot(derivatives.yw, derivatives.yw)));
float width = 1.0;
float2 distance3 = 4.0 * abs(frac(UV + 0.25) - 0.5) - width;
float2 scale = 0.35 / duv_length.xy;
float freqLimiter = sqrt(clamp(1.1f - max(duv_length.x, duv_length.y), 0.0, 1.0));
float2 vector_alpha = clamp(distance3 * scale.xy, -1.0, 1.0);
float alpha = saturate(0.5f + 0.5f * vector_alpha.x * vector_alpha.y * freqLimiter);
Out = lerp(ColorA, ColorB, alpha.xxx);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,23 @@
# Circle Pupil Animation Node
This node applies a deformation to a normalized IrisUV coordinate to simulate the opening and closure of the pupil.
## Render pipeline compatibility
| **Node** | **Universal Render Pipeline (URP)** | **High Definition Render Pipeline (HDRP)** |
| ------------------------------- | ----------------------------------- | ------------------------------------------ |
| **Circle Pupil Animation Node** | No | Yes |
## Ports
| name | **Direction** | type | description |
| -------------------------- | ------------- | ------- | ------------------------------------------------------------ |
| **Iris UV** | Input | Vector2 | Normalized UV coordinates that can be used to sample either a texture or procedurally generate an Iris Texture. |
| **Pupil Radius** | Input | float | Radius of the pupil in the iris texture as a percentage. |
| **Pupil Aperture** | Input | float | Set the current diameter of the pupil opening. |
| **Maximal Pupil Aperture** | Input | float | Define the largest size the pupil opening can reach. |
| **Minimal Pupil Aperture** | Input | float | Define the smallest size the pupil opening can reach. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,29 @@
# Clamp Node
## Description
Returns the input **In** clamped between the minimum and maximum values defined by inputs **Min** and **Max** respectively.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Unclamped input value |
| Min | Input | Dynamic Vector | Minimum value |
| Max | Input | Dynamic Vector | Maximum value |
| Out | Output | Dynamic Vector | Clamped output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Clamp_float4(float4 In, float4 Min, float4 Max, out float4 Out)
{
Out = clamp(In, Min, Max);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,31 @@
# Color Mask Node
## Description
Creates a mask from values in input **In** equal to input **Mask Color**. Input **Range** can be used to define a wider range of values around input **Mask Color** to create the mask. Colors within this range will return 1, otherwise the node will return 0. Input **Fuzziness** can be used to soften the edges around the selection similar to anti-aliasing.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| In | Input | Vector 3 | None | Input value. |
| Mask Color | Input | Vector 3 | Color | Color to use for mask. |
| Range | Input | Float | None | Select colors within this range from input **Mask Color**. |
| Fuzziness | Input | Float | None | Feather edges around selection. Higher values result in a softer selection mask. |
| Out | Output | Float | None | Output mask value. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_ColorMask_float(float3 In, float3 MaskColor, float Range, float Fuzziness, out float4 Out)
{
float Distance = distance(MaskColor, In);
Out = saturate(1 - (Distance - Range) / max(Fuzziness, 1e-5));
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,124 @@
# Color Modes
## Description
Shader Graph can display colors on nodes in your graph to improve readability. This feature uses **Color Modes** to change which colors to display in the graph. Use the **Color Mode:** drop-down menu in the top right corner of the [Shader Graph Window](Shader-Graph-Window.md) to change the **Color Modes**.
## Modes
| Name | Description |
|:-------------|:------------|
| **None** | Does not display colors on the nodes. All nodes use the default gray. |
| **Category** | Displays colors on the nodes based on their assigned category. Refer to [Category colors](#category-colors). |
| **Heatmap** | Displays colors on the nodes based on the nodes relative performance cost. By default, dark colored nodes contribute very little to the overall GPU performance cost of the shader and brighter colored nodes require more GPU computation to run. Refer to [Heatmap colors](#heatmap-colors). |
| **Precision** | Displays colors on the nodes based on the current [Precision Mode](Precision-Modes.md) in use. Refer to [Precision colors](#precision-colors). |
| **User Defined** | Lets you set the display colors on a per-node basis. These are custom colors for your graph. Refer to [User Defined colors](#user-defined-colors). |
### Category colors
This mode displays colors on the nodes based on their category. See the [Node Library](Node-Library.md) to learn about the different categories available.
![A screenshot of Unity's Shader Graph in Category Color Mode, where each node is color-coded based on its function. Artistic nodes appear in orange, #DB773B, channel-related nodes in green, #97D13D, input nodes in red, #CB3022, math operations in blue, #4B92F3, procedural elements in purple, #9C4FFF, utility nodes in gray, #AEAEAE, and UV-related nodes in teal, #08D78B.](images/Color-Mode-Category.png)
The table below lists current categories and their corresponding colors.
| Name | Color Hex Value |
|:-----------|:----------------|
| Artistic | #DB773B |
| Channel | #97D13D |
| Input | #CB3022 |
| Math | #4B92F3 |
| Procedural | #9C4FFF |
| Utility | #AEAEAE |
| UV | #08D78B |
[Sub Graph](Sub-Graph.md) nodes in a main [Shader Graph](index.md) fall in the Utility category. If you select **Category** mode, all Sub Graphs use the Utility color.
**Note:** You can [override the Category colors](#override-category-and-precision-default-colors) according to your needs.
### Heatmap colors
This mode displays colors on the nodes based on their relative performance cost:
* Darker colored nodes (black to purple-red) have a lower impact on the overall GPU performance of the shader.
* Brighter colored nodes (red to yellow) require more GPU computation to run.
* Nodes colored in light blue have an unknown impact on the GPU performance.
You can use this color mode to identify and adjust the most expensive parts of the shader graph if your shader's overall performance is low.
**Note:** Platforms and hardware profiles may introduce variations in the costs of specific nodes and operations. You should consider the Heatmap color mode as an indication to help start the shader optimization process rather than a precise and exact measurement of final results. The best way to measure shader performance is still to run the shader on the target platform in the context of your project.
#### The default Heatmap colors
The default Heatmap color set includes 10 colors.
![The 10 default colors of the Heatmap mode, in a gradient from the left to the right: from black through purple, red, and orange, to yellow.](images/HeatMapGradient.png)
Each color corresponds to a range of GPU cycle numbers that would be required to run the node's code once compiled, and the scale is exponential. For example, black corresponds to 0-3 GPU cycles, red corresponds to 64-127 cycles, and yellow corresponds to 1024 cycles and more.
An additional color, light blue by default, is reserved for the unknown impact.
A few considerations to better understand the default node color assignment in the Heatmap color mode:
* Many nodes have no performance cost. This includes nodes that bring in data from outside the shader without performing any math, or straightforward math nodes such as Absolute and Saturate.
* The node color assignments are broad estimates, as some nodes produce a variable number of cycles depending on the input data type or the various parameters you've set up.
* The unknown impact color is for nodes that do texture samples or whose results can vary widely. Texture samples take a long time and some factors such as filtering settings and texture resolution can also change their performance cost a lot.
### Precision colors
This mode displays colors on the nodes based on their current precision.
If you set a node to **Inherit Precision**, the display color reflects the currently active precision. See [Precision Modes](Precision-Modes.md) for more information about inheritance.
**Note:** You can [override the Precision colors](#override-category-and-precision-default-colors) according to your needs.
### User-defined colors
This mode displays colors on the nodes based on user preferences. In this mode, the user defines colors for each node. If a custom color is not set, the node displays in the default gray.
To set a custom color for a node, right-click on the target node to bring up the the context menu, and select **Color**.
| Option | Description |
|:------- |:------------|
| Change... |Brings up a color picker menu and lets you set your own custom color on the node. |
| Reset | Removes the currently selected color and sets it to the default gray. |
## Customize the predefined color modes
For each project, you can customize the predefined color modes according to your needs.
<a name="override-category-and-precision-default-colors"></a>
### Override the Category and Precision default colors
You can override preset colors in the **Category** and **Precision** modes. Unity uses a `.uss` style sheet and Hex color codes to set colors. The default style sheet in your project is `Packages/com.unity.shadergraph/Editor/Resources/Styles/ColorMode.uss`.
The best practice is to create a copy of this file to override the presets. Under your project's **Assets** folder, create a new `Editor/Resources/Styles` folder structure, and place a copy of `ColorMode.uss` in the `Styles` folder. Change the Hex color codes in this `.uss` file to override the presets and use your own custom colors for the **Category** and **Precision** modes.
### Customize the Heatmap color mode
You can customize the whole Heatmap color mode, which includes the number of available colors, the color assignment for all available nodes and sub graphs, and the colors themselves. For this, you have to create a custom Shader Graph Heatmap Values asset and then reference it in the [Project Settings](Shader-Graph-Project-Settings.md#heatmap-color-mode-settings).
To create and apply a custom Shader Graph Heatmap Values asset in your project, follow these steps:
1. In the Project window, right-click in any folder, select **Create** > **Shader Graph** > **Custom Heatmap Values**.
1. Choose between **Heatmap with Default Values** or **Empty Heatmap** depending on your needs.
1. Give your new asset a name and select it.
1. In the inspector:
* In the **Categories** section, define the colors and the number of colors you need in your custom color set. Use **+** (plus) or **-** (minus) at the bottom of the list to add or remove colors.
* In the **Subgraphs** and **Nodes** sections, assign each listed sub graph and node a color based on the category indexes listed in the **Categories** section.
* In the **Subgraphs** section, you can add sub graphs of your project that aren't listed and also assign them a color.
1. From the Editor's main menu, select **Edit** > **Project Settings**, and select **Shader Graph**.
1. Under **Heatmap Color Mode Settings**, in **Custom Values**, select the Shader Graph Heatmap Values asset you just configured.
**Note**: When you assign color category values to **Nodes** and **Subgraphs** in the Shader Graph Heatmap Values asset, make sure to only use values that correspond to category indexes that exist in the **Category** list.
#### Beyond the configuration
If you need to roll back to the default Heatmap color mode setup, in the **Project Settings**, under **Heatmap Color Mode Settings**, in **Custom Values**, select **None**.
You can create multiple custom Shader Graph Heatmap Values assets and alternatively use them based on the current needs of the project. You can only select one Custom Heatmap Values asset at a time in the [Project Settings](Shader-Graph-Project-Settings.md#heatmap-color-mode-settings).
When you set up a custom Shader Graph Heatmap Values asset, you can completely change the purpose of the Heatmap color mode and define a color set that represents a totally different kind of information. For example, a technical director could decide to use only two colors, green and red, and inform the team that green nodes are available to use while red nodes are off limits.
@@ -0,0 +1,32 @@
# Color Node
## Description
Defines a constant **Vector 4** value in the shader using a **Color** field. Can be converted to a **Color** [Property Type](Property-Types.md) via the [Node's](Node.md) context menu. The value of the **Mode** parameter will also respected when generating the [Property](Property-Types.md).
NOTE: In versions prior to 10.0, Shader Graph assumed that HDR colors from the Color Node were in gamma space. Version 10.0 corrected this behavior, and Shader Graph now interprets HDR colors in linear space. HDR Color nodes that you created with older versions maintain the old behavior, but you can use the [Graph Inspector](Internal-Inspector.md) to upgrade them. To mimic the old behavior on a new HDR Color node, you can use a [Colorspace Conversion Node](Colorspace-Conversion-Node.md) to convert the HDR color from **RGB** to **Linear**.
## Ports
| Name | Direction | Type | Binding | Description |
|:--- |:---|:---|:---|:---|
| Out | Output | Vector 4 | None | Output value |
## Controls
| Control | Description |
|:---|:---|
| (Color) | Defines the output value. |
| **Mode** | Sets properties of the Color field. The options are:<ul><li>**Default**</li><li>**HDR**</li></ul> |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
float4 _Color = IsGammaSpace() ? float4(1, 2, 3, 4) : float4(SRGBToLinear(float3(1, 2, 3)), 4);
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,132 @@
# Colorspace Conversion Node
## Description
Returns the result of converting the value of input **In** from one colorspace space to another. The spaces to transform from and to are defined by the values of the dropdowns on the node.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Vector 3 | Input value |
| Out | Output | Vector 3 | Output value |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| From | Dropdown | RGB, Linear, HSV | Selects the colorspace to convert from |
| To | Dropdown | RGB, Linear, HSV | Selects the colorspace to convert to. Returns values in the range 0 to 1, or higher if the color space is HDR. |
## Generated Code Example
The following example code represents one possible outcome of this node per from/to permutation.
**RGB > RGB**
```
void Unity_ColorspaceConversion_RGB_RGB_float(float3 In, out float3 Out)
{
Out = In;
}
```
**RGB > Linear**
```
void Unity_ColorspaceConversion_RGB_Linear_float(float3 In, out float3 Out)
{
float3 linearRGBLo = In / 12.92;;
float3 linearRGBHi = pow(max(abs((In + 0.055) / 1.055), 1.192092896e-07), float3(2.4, 2.4, 2.4));
Out = float3(In <= 0.04045) ? linearRGBLo : linearRGBHi;
}
```
**RGB > HSV**
```
void Unity_ColorspaceConversion_RGB_HSV_float(float3 In, out float3 Out)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 P = lerp(float4(In.bg, K.wz), float4(In.gb, K.xy), step(In.b, In.g));
float4 Q = lerp(float4(P.xyw, In.r), float4(In.r, P.yzx), step(P.x, In.r));
float D = Q.x - min(Q.w, Q.y);
float E = 1e-10;
Out = float3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
}
```
**Linear > RGB**
```
void Unity_ColorspaceConversion_Linear_RGB_float(float3 In, out float3 Out)
{
float3 sRGBLo = In * 12.92;
float3 sRGBHi = (pow(max(abs(In), 1.192092896e-07), float3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - 0.055;
Out = float3(In <= 0.0031308) ? sRGBLo : sRGBHi;
}
```
**Linear > Linear**
```
void Unity_ColorspaceConversion_Linear_Linear_float(float3 In, out float3 Out)
{
Out = In;
}
```
**Linear > HSV**
```
void Unity_ColorspaceConversion_Linear_HSV_float(float3 In, out float3 Out)
{
float3 sRGBLo = In * 12.92;
float3 sRGBHi = (pow(max(abs(In), 1.192092896e-07), float3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - 0.055;
float3 Linear = float3(In <= 0.0031308) ? sRGBLo : sRGBHi;
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 P = lerp(float4(Linear.bg, K.wz), float4(Linear.gb, K.xy), step(Linear.b, Linear.g));
float4 Q = lerp(float4(P.xyw, Linear.r), float4(Linear.r, P.yzx), step(P.x, Linear.r));
float D = Q.x - min(Q.w, Q.y);
float E = 1e-10;
Out = float3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
}
```
**HSV > RGB**
```
void Unity_ColorspaceConversion_HSV_RGB_float(float3 In, out float3 Out)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 P = abs(frac(In.xxx + K.xyz) * 6.0 - K.www);
Out = In.z * lerp(K.xxx, saturate(P - K.xxx), In.y);
}
```
**HSV > Linear**
```
void Unity_ColorspaceConversion_HSV_Linear_float(float3 In, out float3 Out)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 P = abs(frac(In.xxx + K.xyz) * 6.0 - K.www);
float3 RGB = In.z * lerp(K.xxx, saturate(P - K.xxx), In.y);
float3 linearRGBLo = RGB / 12.92;
float3 linearRGBHi = pow(max(abs((RGB + 0.055) / 1.055), 1.192092896e-07), float3(2.4, 2.4, 2.4));
Out = float3(RGB <= 0.04045) ? linearRGBLo : linearRGBHi;
}
```
**HSV > HSV**
```
void Unity_ColorspaceConversion_HSV_HSV_float(float3 In, out float3 Out)
{
Out = In;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,34 @@
# Combine Node
## Description
Creates new vectors from the four inputs **R**, **G**, **B** and **A**. Output **RGBA** is a **Vector 4** composed of inputs **R**, **G**, **B** and **A**. Output **RGB** is a **Vector 3** composed of inputs **R**, **G** and **B**. Output **RG** is a **Vector 2** composed of inputs **R** and **G**.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| R | Input | Float | None | Defines red channel of output |
| G | Input | Float | None | Defines green channel of output |
| B | Input | Float | None | Defines blue channel of output |
| A | Input | Float | None | Defines alpha channel of output |
| RGBA | Output | Vector 4 | None | Output value as **Vector 4** |
| RGB | Output | Vector 3 | None | Output value as **Vector 3** |
| RG | Output | Vector 2 | None | Output value as **Vector 2** |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Combine_float(float R, float G, float B, float A, out float4 RGBA, out float3 RGB, out float2 RG)
{
RGBA = float4(R, G, B, A);
RGB = float3(R, G, B);
RG = float2(R, G);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,81 @@
# Comparison Node
## Description
Compares the two input values **A** and **B** based on the condition selected on the dropdown. This is often used as an input to the [Branch Node](Branch-Node.md).
## Ports
| Name | Direction | Type | Binding | Description |
|:--- |:---|:---|:---|:---|
| A | Input | Float | None | First input value |
| B | Input | Float | None | Second input value |
| Out | Output | Boolean | None | Output value |
## Controls
| Control | Description |
|:---|:---|
| (Dropdown) | Select the condition for comparison between A and B. The options are:<ul><li>**Equal**</li><li>**NotEqual**</li><li>**Less**</li><li>**LessOrEqual**</li><li>**Greater**</li><li>**GreaterOrEqual**</li></ul> |
## Generated Code Example
The following example code represents one possible outcome of this node per comparison type.
**Equal**
```
void Unity_Comparison_Equal_float(float A, float B, out float Out)
{
Out = A == B ? 1 : 0;
}
```
**NotEqual**
```
void Unity_Comparison_NotEqual_float(float A, float B, out float Out)
{
Out = A != B ? 1 : 0;
}
```
**Less**
```
void Unity_Comparison_Less_float(float A, float B, out float Out)
{
Out = A < B ? 1 : 0;
}
```
**LessOrEqual**
```
void Unity_Comparison_LessOrEqual_float(float A, float B, out float Out)
{
Out = A <= B ? 1 : 0;
}
```
**Greater**
```
void Unity_Comparison_Greater_float(float A, float B, out float Out)
{
Out = A > B ? 1 : 0;
}
```
**GreaterOrEqual**
```
void Unity_Comparison_GreaterOrEqual_float(float A, float B, out float Out)
{
Out = A >= B ? 1 : 0;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,16 @@
# Compute Deformation Node
## Description
This node lets you pass compute deformed vertex data to a vertex shader, and only works with the [Entities Graphics package](https://docs.unity3d.com/Packages/com.unity.entities.graphics@latest/). You must provide `DeformedVertexData` in the `_DeformedMeshData` buffer. The node uses the `_ComputeMeshIndex` property to calculate where the `DeformedVertexData` associated with the current mesh are located in the `_DeformedMeshData` buffer. To output data, you must either install both the Entities Graphics package and DOTS Animation packages, or use a custom solution.
## Ports
| Name | Direction | Type | Stage | Description |
|:--------- |:-----------|:--------|:-------|:------------|
| Position | Output | Vector3 | Vertex | Outputs the deformed vertex position. |
| Normal | Output | Vector3 | Vertex | Outputs the deformed vertex normal. |
| Tangent | Output | Vector3 | Vertex | Outputs the deformed vertex tangent. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,55 @@
# Constant Node
## Description
Defines a **Float** of a mathematical constant value in the shader.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Out | Output | Float | None | Output value |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| Mode | Dropdown | PI, TAU, PHI, E, SQRT2 | Sets output constant value |
## Generated Code Example
The following example code represents one possible outcome of this node per constant type.
**PI**
```
float _Constant_PI = 3.1415926;
```
**TAU**
```
float _Constant_TAU = 6.28318530;
```
**PHI**
```
float _Constant_PHI = 1.618034;
```
**E**
```
float _Constant_E = 2.718282;
```
**SQRT2**
```
float _Constant_SQRT2 = 1.414214;
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,29 @@
# Contrast Node
## Description
Adjusts the contrast of input **In** by the amount of input **Contrast**. A **Contrast** value of 1 will return the input unaltered. A **Contrast** value of 0 will return the midpoint of the input.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| In | Input | Vector 3 | None | Input value |
| Contrast | Input | Float | None | Contrast value |
| Out | Output | Vector 3 | None | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Contrast_float(float3 In, float Contrast, out float3 Out)
{
float midpoint = pow(0.5, 2.2);
Out = (In - midpoint) * Contrast + midpoint;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,24 @@
# Cornea Refraction Node
This node performs the refraction of the view ray in object space and returns the object space position that results. This is used to simulate the refraction that can be seen when looking at an eye.
## Render pipeline compatibility
| **Node** | **Universal Render Pipeline (URP)** | **High Definition Render Pipeline (HDRP)** |
| -------------------------- | ----------------------------------- | ------------------------------------------ |
| **Cornea Refraction Node** | No | Yes |
## Ports
| name | **Direction** | type | description |
| ----------------------- | ------------- | ------- | ------------------------------------------------------------ |
| **Position OS** | Input | Vector3 | Position of the fragment to shade in object space. |
| **View Direction OS** | Input | Vector3 | Direction of the incident ray in object space. Either from the camera in rasterization or from the previous bounce in ray tracing. |
| **Cornea Normal OS** | Input | Vector3 | The normal of the eye surface in object space. |
| **Cornea IOR** | Input | float | The index of refraction of the eye (**1.333** by default). |
| **Iris Plane Offset** | Input | float | Distance between the end of the cornea and the iris plane. For the default model, this value should be **0.02** |
| **RefractedPositionOS** | Output | Vector3 | Position of the refracted point on the iris plane in object space. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Cosine Node
## Description
Returns the cosine of the value of input **In**.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value in radians |
| Out | Output | Dynamic Vector | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Cosine_float4(float4 In, out float4 Out)
{
Out = cos(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,69 @@
# Add and connect nodes in a shader graph
You can add and connect nodes in a shader graph in different ways depending on your current task.
> [!NOTE]
> To add and connect nodes in a shader graph, you need to [create a shader graph asset](create-shader-graph.md) first and open the asset in the [Shader Graph window](Shader-Graph-Window.md).
## Add a node
To add a [node](Node.md) to your shader graph, follow these steps:
1. Open the **Create Node** menu through either of the following:
* Select the [Shader Graph window](Shader-Graph-Window.md)'s workspace and press the **Spacebar**.
* Right-click in the Shader Graph Window's workspace and select **Create Node**.
1. In the **Create Node** menu, browse or search for the desired node.
The **Create Node** menu lists all nodes that are available in Shader Graph, categorized by their function. User-created [sub graphs](Sub-graph.md) are also available in the **Create Node** menu under **Sub Graph Assets**, or in a custom category that you define in the Sub Graph Asset.
1. Double-click on a node's name to add the corresponding node in the graph.
> [!NOTE]
> Use the **Create Node** menu search box to filter the listed nodes by name parts and synonyms based on industry terms. It provides autocomplete options and highlights matching text in yellow. You can press **Tab** to accept the predictive text.
## Connect node ports
To connect [ports](Port.md) between two existing [nodes](Node.md) or with the [master stack](Master-Stack.md), select and drag the desired port to the target.
The line resulting from that connection is called a [wire](Wire.md).
You can only connect an output port to an input port, or vice-versa, and you can't connect two ports of the same node together.
## Add and connect a node from an existing port
To connect a [port](Port.md) to a [node](Node.md) that doesn't exist yet and create that targeted node in the process, follow these steps:
1. Select and drag the desired port and release it in an empty area of the workspace.
1. In the **Create Node** menu, browse or search for the node you need to connect to the port you dragged out.
The **Create Node** menu displays every node port available according to the [data types](Data-Types.md) compatible with the port you dragged out.
1. Double-click on a node port's name to add the corresponding node in the graph, with the two expected ports already connected­.
## Add a block node in the Master Stack
To add a new [block node](Block-Node.md) to the [master stack](Master-Stack.md), follow these steps:
1. Open the **Create Node** menu for the Master Stack context through either of the following:
* Select the Master Stack's targeted context (**Vertex** or **Fragment**) and press the **Spacebar**.
* Right-click in the Master Stack's targeted context area and select **Create Node**.
1. In the **Create Node** menu, browse or search for the desired block node.
The **Create Node** menu displays all available blocks for the master stack based on the render pipelines in your project.
1. Double-click on a block node's name to add the corresponding block node in the Master Stack.
> [!NOTE]
> If the block that you add is not compatible with the current [graph settings](Graph-Settings-Tab.md), the block is deactivated until you configure the settings to support it.
## Additional resources
* [Nodes](Node.md)
* [Ports](Port.md)
* [Wires](Wire.md)
* [Master Stack](Master-Stack.md)
* [Block nodes](Block-Node.md)
@@ -0,0 +1,59 @@
# Create a shader graph asset
You can create a new shader graph asset in different ways according to your current workflow.
## Create a shader graph from a template
To create a new shader graph asset from a prebuilt shader graph template, follow these steps:
1. In the **Project** window, right-click and select **Create** > **Shader Graph** > **From Template**.
The [template browser](template-browser.md) lists all available templates according to your project's render pipeline.
1. Select the desired template and click **Create**.
Unity creates a new shader graph asset in your project.
1. Name the shader graph asset.
You can now open the asset and edit the graph in the [Shader Graph window](Shader-Graph-Window.md).
## Create a shader graph with a preset target
To start from a default configuration with a preset master stack according to a specific render pipeline and material type, follow these steps:
1. In the **Project** window, right-click and select **Create** > **Shader Graph**, and then the target render pipeline and the desired shader type.
The types of shader graphs available depend on the render pipelines present in your project (for example, **URP** > **Lit Shader Graph**). For a full list of provided options, refer to the [Universal Render Pipeline](https://docs.unity3d.com/Manual/urp/urp-introduction.html) and [High Definition Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest) documentation.
Unity creates a new shader graph asset in your project.
1. Name the shader graph asset.
You can now open the asset and edit the graph in the [Shader Graph window](Shader-Graph-Window.md).
## Create an empty shader graph
To create an empty shader graph asset and build your shader graph from scratch in the Shader Graph window:
1. In the **Project** window, right-click and select **Create** > **Shader Graph** > **Blank Shader Graph**.
Unity creates a new shader graph asset in your project.
1. Name the shader graph asset.
You can now open the asset and edit the graph in the [Shader Graph window](Shader-Graph-Window.md).
> [!NOTE]
> To make such a blank shader graph functional, you have to define a [Target](Graph-Target.md) in the [Graph settings tab](Graph-Settings-Tab.md) of the Graph Inspector.
## Additional resources
* [Shader Graph template browser](template-browser.md)
* [Create a custom shader graph template](template-browser.md#create-a-custom-shader-graph-template)
* [Shader Graph window](Shader-Graph-Window.md)
* [Shader Graph Asset reference](Shader-Graph-Asset.md)
@@ -0,0 +1,24 @@
# Create a Sub Graph
To perform the same operations multiple times within a single shader graph or across multiple shader graphs, create a [Sub Graph](Sub-graph.md).
## Create a Sub Graph from existing nodes
To create a [Sub Graph](Sub-graph.md) from an existing set of shader graph nodes, follow these steps:
1. In the Shader Graph window, select the nodes you want to include in the Sub Graph.
2. Right-click on one of the selected nodes to open the context menu.
3. Select **Convert To Sub-graph**.
Unity creates a Shader Graph asset in the Project window. To edit the Sub Graph, double-click the asset.
**Note:** If a node in a Sub Graph specifies a [shader stage](Shader-Stage.md), the Sub Graph can only include nodes that work with or specify the same shader stage.
## Create an empty Sub Graph
To create an empty Sub Graph, in the Project window, right-click and select **Create** > **Shader** > **Sub Graph**.
## Additional resources
- [Change the behavior of a Sub Graph with a dropdown](Change-Behaviour-Sub-Graph-Dropdown.md)
- [Custom Function Node](Custom-Function-Node.md)
@@ -0,0 +1,28 @@
# Cross Product Node
## Description
Returns the cross product of the values of the inputs **A** and **B**. The cross product of two vectors results in a third vector which is perpendicular to the two input vectors. The result's magnitude is equal to the magnitudes of the two inputs multiplied together and then multiplied by the sine of the angle between the inputs. You can determine the direction of the result vector using the "left hand rule".
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| A | Input | Vector 3 | First input value |
| B | Input | Vector 3 | Second input value |
| Out | Output | Vector 3 | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_CrossProduct_float(float3 A, float3 B, out float3 Out)
{
Out = cross(A, B);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,21 @@
# Cubemap Asset Node
## Description
Defines a constant **Cubemap Asset** for use in the shader. To sample the **Cubemap Asset** it should be used in conjunction with a [Sample Cubemap Node](Sample-Cubemap-Node.md). When using a separate **Cubemap Asset Node** you can sample a **Cubemap** twice, with different parameters, without defining the **Cubemap** itself twice.
## Ports
| Name | Direction | Type | Binding | Description |
|:--- |:---|:---|:---|:---|
| Out | Output | Cubemap | None | Output value |
## Controls
| Control | Description |
|:--- |:---|
| (Cubemap)| Defines the cubemap asset from the project. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,31 @@
# Custom Color Buffer Node (HDRP)
The Custom Color Node accesses the custom pass color buffer allocated by HDRP.
## Render pipeline compatibility
| **Node** | **Universal Render Pipeline (URP)** | **High Definition Render Pipeline (HDRP)** |
| -------------- | ----------------------------------- | ------------------------------------------ |
| Custom Color Node | No | Yes |
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| **UV** | Input | Vector 4 | Screen Position | Sets the normalized screen coordinates to sample. |
| **Output** | Output | Vector 4 | None | The value the custom pass color buffer contains at the sampled coordinates. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_CustomDepth_LinearEye_float(float4 UV, out float Out)
{
Out = SampleCustomColor(UV.xy);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,21 @@
# Custom Function Node
Use the Custom Function Node to inject your own custom HLSL code in Shader Graphs to do some fine-grained optimization, for example.
You can either write small functions directly into graphs by using the string mode, or reference external HLSL files. Use the [Custom Port Menu](Custom-Port-Menu.md) to define your own input and output ports on the node itself.
![The Custom Function node properties](images/Custom-Function-Node-File.png)
| Property | Description |
|:----------|:------------|
| **Inputs** | Define the node's input ports. The names you enter here define the names for the input values you use in the code. |
| **Outputs** | Define the node's output ports. The names you enter here define the names for the output values you use in the code. |
| **Type** | Select the way to reference the custom function in the node. The options are:<ul><li>**File**: Reference an external file that contains the functions.</li><li>**String**: Directly write functions in the node.</li></ul> |
| **Name** | The name of the custom function in the code, **without** the function precision suffix `_half ` or `_float `. |
| **Source** | When you set **Type** to **File**, the reference to the HLSL file that includes the custom functions. The file can be anywhere in your Unity project and must have the `.hlsl` extension. For more details, refer to [file content syntax](#file-content-syntax-details-and-examples). |
| **Body** | When you set **Type** to **String**, the HLSL code that defines the contents of the custom functions. Unity handles the arguments, braces, and indent scope automatically. |
## Additional resources
- [Create a Custom Function node](Custom-nodes-hlsl-create-custom-function-node.md)
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,19 @@
# Custom Interpolator block node reference
Pass per-vertex data from the vertex stage to the fragment stage through a [Custom Interpolator node](Custom-Interpolator-node-reference.md).
To complete the setup, you need to [add a Custom interpolator](Custom-Interpolators.md) that corresponds to the Custom Interpolator block node.
## Settings
| Property | Description |
|:------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Name** | Sets the unique name of the custom interpolator to identify and reference it in the graph. |
| **Type** | Sets the number of channels the Custom Interpolator exposes. The default value is **Vector 4**, which exposes x, y, z, and w channels. |
| **Interpolation** | Selects how Unity interpolates the value from vertex to fragment across the surface. The following options are available: <ul><li><b>Linear</b>: Applies the default linear interpolation, which preserves correct rates of change in screen space.</li><li><b>No Perspective</b>: Doesn't correct perspective, which can warp data, depending on the angle between the surface and the camera.</li><li><b>No Interpolation</b>: Doesn't interpolate the data, which creates hard edges between triangles.</li></ul> |
## Additional resources
* [Built-in blocks](Built-In-Blocks.md)
* [Add a custom interpolator](Custom-Interpolators.md)
* [Custom Interpolator node reference](Custom-Interpolator-node-reference.md)
@@ -0,0 +1,24 @@
# Custom Interpolator node reference
Read data from a [Custom Interpolator block node](Custom-Interpolator-block-node-reference.md) of the vertex stage to pass it to the fragment stage.
To be able to add a Custom Interpolator node, you first need to [add a Custom interpolator block node](Custom-Interpolators.md) to the vertex stage.
## Output port
| Name | Type | Description |
| :--- | :--- | :--- |
| Out | Depends on the **Type** selected in the [Node Settings](#settings) | The data read from the matching Custom interpolator block node from the vertex stage. |
## Settings
| Property | Description |
|:------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Name** | Sets the unique name of the custom interpolator to identify and reference it in the graph. |
| **Type** | Sets the number of channels the Custom Interpolator exposes. The default value is **Vector 4**, which exposes x, y, z, and w channels. |
| **Interpolation** | Selects how Unity interpolates the value from vertex to fragment across the surface. The following options are available: <ul><li><b>Linear</b>: Applies the default linear interpolation, which preserves correct rates of change in screen space.</li><li><b>No Perspective</b>: Doesn't correct perspective, which can warp data, depending on the angle between the surface and the camera.</li><li><b>No Interpolation</b>: Doesn't interpolate the data, which creates hard edges between triangles.</li></ul> |
## Additional resources
* [Add a custom interpolator](Custom-Interpolators.md)
* [Custom Interpolator block node reference](Custom-Interpolator-block-node-reference.md)
@@ -0,0 +1,9 @@
# Using Custom Interpolators
Use custom interpolators to pass custom data from the vertex shader to the fragment shader.
| **Page** | **Description** |
|--------------------------------------------------------------------|---------------------------------------------------------------------------------|
| [Custom Interpolators](Custom-Interpolators.md) | Learn how to use and manage custom interpolators according to your needs. |
| [Custom Interpolator block node reference](Custom-Interpolator-block-node-reference.md) | Pass per-vertex data from the vertex stage to the fragment stage through a Custom Interpolator node. |
| [Custom Interpolator node reference](Custom-Interpolator-node-reference.md) | Read data from a Custom Interpolator block node of the vertex stage to pass it to the fragment stage. |
@@ -0,0 +1,62 @@
# Add a custom interpolator
To pass custom data from the vertex shader to the fragment shader, add a custom interpolator to the vertex context of the Master Stack.
There are two target audiences for custom interpolators:
* Technical Directors and Lead Technical Artists setting up environments for their teams.
* Graphics programmers helping artists to optimize content performance.
**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.
[!include[birp-deprecation-message](snippets/birp-deprecation-message.md)]
## Supported data types
Custom interpolators support float, vector 2, vector 3, and vector 4 types.
## Channel limits
A custom interpolator supports a maximum of 32 channels. A channel is equivalent to four floats. Each float is an interpolator variable.
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).
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:
- **Warning Threshold** to tell users when they approach the channel limit. The range is 8 to 32 channels.
- **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**.
## Add a custom interpolator block to the Master Stack
1. Right-click in the **Vertex** context to create a block node.
1. Select **[Custom Interpolator](Custom-Interpolator-block-node-reference.md)**.
1. In the **Node Settings** tab of the **Graph Inspector** window, select a data type, for example **Vector 4**.
1. Select an interpolation method.
1. In the same tab, enter a name for the interpolator.
## Write data to the interpolator
1. Right-click in your graph to create a node.
2. Select the type, for example **Vertex ID**.
Custom interpolator blocks support many types of data, so you can connect the data from many other nodes including UV nodes and color nodes.
3. Connect the node to the custom interpolator block.
The graph now writes Vertex ID values into the custom interpolator.
## Read data from the interpolator
1. Right-click in your graph to create a node.
2. Select **[Custom Interpolator](Custom-Interpolator-node-reference.md)**.
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.
## Delete a custom interpolator
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.
## Additional resources
* [Built In Blocks](Built-In-Blocks.md)
* [Custom Interpolator block node reference](Custom-Interpolator-block-node-reference.md)
* [Custom Interpolator node reference](Custom-Interpolator-node-reference.md)
@@ -0,0 +1,31 @@
# Custom Port Menu
## Description
The Custom [Port](Port.md) Menu is displayed in the **Node Settings** tab of the [Graph Inspector](Internal-Inspector.md) by clicking on the [Custom Function Node](Custom-Function-Node.md) and [Sub Graph](Sub-graph.md) output node. This menu allows you to add, remove, rename, reorder, and define the types of your custom input and output ports.
## How to Use
Select the [Custom Function Node](Custom-Function-Node.md) or the [Sub Graph](Sub-graph.md) output node to view the Custom Port Menu in the Inspector. To close the menu, click anywhere in the graph or on another graph-element.
![01](images/Custom-Port-Menu-Empty.png)
### Adding and Removing Ports
To add ports, click the `+` icon at the bottom right corner of the port list.
![02](images/Custom-Port-Menu-Add.png)
To remove ports, select a port using the hamburger icon on the left, and click the `-` icon at the bottom right corner of the port list.
![03](images/Custom-Port-Menu-Remove.png)
### Renaming Ports
To rename a port, double-click its text field and enter the new name. Currently, only the following characters are valid for port names: A-Z, a-z, 0-9, _, ( ), and whitespace. If the name contains an invalid character, an error badge appears.
![04](images/Custom-Port-Menu-Rename.png)
### Reordering Ports
To reorder ports, click and hold the hamburger icon on the left, and drag the port to your desired place in the list.
### Changing Port Types
To change a port type, use the Type drop-down menu on the right. See the [Data Types](Data-Types.md) page for a list of currently valid port types.
![05](images/Custom-Port-Menu-Type.png)
@@ -0,0 +1,26 @@
# Access Custom Render Texture shader properties
If you want to create shaders, in Shader Graph, for use with Custom Render Textures, you need to understand how to access specific texture coordinates and other shader properties.
## Accessing the texture coordinates
Shader Graph provides access to local and global texture coordinates via the [UV Node](https://docs.unity3d.com/Packages/com.unity.shadergraph@latest?subfolder=/manual/UV-Node.html):
- Channel 0 (localTexcoord): Provides the local texture coordinates.
- Channel 1 (globalTexcoord): Provides the global texture coordinates.
To access these channels, add a UV node to your Shader Graph and select the appropriate channel.
## Access the cubemap view direction
For shaders that interact with Cubemaps, use the [View Direction](https://docs.unity3d.com/Packages/com.unity.shadergraph@latest?subfolder=/manual/View-Direction-Node.html) node to retrieve the direction for the Cubemap sampling . Make sure that the space is set to **World Space** to get the correct direction vector.
## Access the Update Zone Index
You can access the update zone index via the [UV Node](https://docs.unity3d.com/Packages/com.unity.shadergraph@latest?subfolder=/manual/UV-Node.html) as well.
- Channel 2 (PrimitiveID): Provides the Primitive ID. The primitive ID corresponds to the index of the update zone being rendered.
## Additional resources
- [Custom Render Textures](https://docs.unity3d.com/Manual/class-CustomRenderTexture.html)
- [Custom Render Texture Nodes](Custom-Render-Texture-Nodes.md)
- [UV node](https://docs.unity3d.com/Packages/com.unity.shadergraph@latest?subfolder=/manual/UV-Node.html)
- [View Direction node](https://docs.unity3d.com/Packages/com.unity.shadergraph@latest?subfolder=/manual/View-Direction-Node.html)
@@ -0,0 +1,76 @@
# Example Custom Render Texture with Shader Graph
This example demonstrates how to set up a Shader Graph for Custom Render Texture shaders to create a self-healing deformation effect that could be used for snow, sand, etc.
<video src="Images/CustomRenderTexture-Animation.mp4" title="A grid with various cells labeled with letter-number pairs (for example, A0, B1, G2, and so on), accompanied by arrows. Each cell is a different color. In the upper-left corner, there’s a black square with two red spots, one square and the other circular. The square remains stationary, while the circular spot traces a curve. In the upper-right corner, a black square contains the same glowing red spots, with the circular spot leaving a fading trail as it describes a curve. Above the grid, a cube corresponding to the square floats and leaves a hollow imprint behind, as if the grid were a mattress pressed by a heavy object. A red sphere traces the same curve as the circular spot, creating a furrow in the grid. The grid gradually recovers its original shape, and the furrow disappears." width="700" height="auto" autoplay="true" loop="true" controls></video>
For this effect, we need a Render Texture that contains the pixels we want to displace. This Render Texture is displayed at the top left corner of the preceding image. It was directly assigned to a camera that renders the objects in red above the UV plane.
1. Create a **Custom Render Texture** Shader Graph as follows:
- Right-click in the Project window.
- Select **Create** > **Shader Graph** > **Custom Render Texture** and name your shader.
2. Create a new **Custom Render Texture** as follows:
- Select **Create** > **Rendering** > **Custom Render Texture**.
- Configure the parameters to match the following settings:
- **Dimension**: 2D
- **Size**: 1024 x 1024
- **Anti-aliasing**: None
- **Enable Compatible Format**: selected
- **Color Format**: R32_SFLOAT
- **Depth Stencil Format**: None
- **Mipmap**: not selected
- **Dynamic Scaling**: not selected
- **Random Write**: not selected
- **Wrap Mode**: Clamp
- **Filter Mode**: Bilinear
- **Aniso Level**: 0
- **Material**: SnowHeightmapUpdate
**Note**: The material in the **Material** field was created.
- **Shader Pass**: <Unnamed Pass 0>
- **Initialization Mode**: OnDemand
- **Source**: Texture and Color
- **Color**: select a color
- **Texture**: None (Texture)
- **Update Mode**: Realtime
- **Period**: 0
- **Double Buffered**: selected
- **Wrap Update Zones**: not selected
- **Update Zone Space**: Normalized
- **Update Zones**: list empty
The following Shader Graph reads the output of the Camera Render Texture, as well as the Self texture, then adds them and lerps the result so that it tends towards 0 over time.
![The graph that is described in the preceding text.](images/CustomRenderTextureShaderGraph.png)
3. Finally you need to assign the **Custom Render Texture** to a material that can deform the geometry (tessellation or pixel displacement).
## New ShaderGraph Nodes for Custom Render Textures
Three new ShaderGraph nodes have been introduced to facilitate working with Custom Render Textures:
1. [Custom Render Texture Self](Custom-Render-Texture-Self-Node.md)
- Outputs the double-buffered texture from the previous update.
- It provides three outputs for different types of textures: 2D, 3D, and Cube textures.
2. [Custom Render Texture Size](Custom-Render-Texture-Size-Node.md)
- Outputs the width, height, and volume depth of the current Custom Render Texture.
- Use this node to determine the size of the texture being worked with.
3. [Custom Render Texture Slice](Slice-Index-Cubemap-Face-Node.md)
- Outputs the current slice for 2D Texture Arrays or the Cubemap face index being updated.
## Known Limitations
When working with Custom Render Texture shaders, be aware of the following limitations:
* Rendering Order
- The Custom Render Texture update loop runs before any rendering operations. This means:
- You cannot access any render pipeline-specific information in the shader, such as depth, normal, or scene color.
- Despite this, you can rely on the content of the Custom Render Texture being ready for use in the scene when the camera renders.
## Additional resources
- [Custom Render Textures](https://docs.unity3d.com/Manual/class-CustomRenderTexture.html)
- [Custom Render Texture Nodes](Custom-Render-Texture-Nodes.md)
@@ -0,0 +1,9 @@
# Custom Render Texture nodes
Access properties and data of custom render textures, including size, slice index, cubemap face, and previous update state.
| **Topic** | **Description** |
|--------------------------------------------------------|----------------------------------------------------------------|
| [Custom Render Texture Self](Custom-Render-Texture-Self-Node.md) | Access the custom render texture from the previous update. |
| [Custom Render Texture Size](Custom-Render-Texture-Size-Node.md) | Access the custom render texture size. |
| [Slice Index / Cubemap Face](Slice-Index-Cubemap-Face-Node.md) | Access the custom render texture slice index and cubemap face. |
@@ -0,0 +1,27 @@
# Custom Render Texture Self Node
## Description
Provides the texture that contains the result of the previous update of the **Custom Render Texture**. Use the output that corresponds to the type of **Custom Render Texture** used.
For more information on Custom Render Textures, refer to the [Unity Manual](https://docs.unity3d.com/Manual/class-CustomRenderTexture.html).
## Ports
| Name | Direction | Type | Binding | Description |
|:------------------|:-------------|:----------|:---|:-----------------------------------------------------------------------------------|
| Self Texture 2D | Output | Texture2D | None | 2D Texture object that contains the update result of the previous **Custom Render Texture**. |
| Self Texture Cube | Output | Cubemap | None | Cubemap object that contains the update result of the previous **Custom Render Texture**. |
| Self Texture 3D | Output | Texture3D | None | 3D Texture object that contains the update result of the previous **Custom Render Texture**. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
UnityBuildTexture2DStructNoScale(_SelfTexture2D)
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Custom Render Texture Size Node
## Description
Provides the size of the current **Custom Render Texture**.
For more information on Custom Render Textures, refer to the [Unity Manual](https://docs.unity3d.com/Manual/class-CustomRenderTexture.html).
## Ports
| Name | Direction | Type | Binding | Description |
|:---------------|:-------------|:----------|:---|:-------------------------------------------------------------------------------------------------------------|
| Texture Width | Output | Float | None | Width of the **Custom Render Texture**. |
| Texture Height | Output | Float | None | Height of the **Custom Render Texture**. |
| Texture Depth | Output | Float | None | Volume depth of the **Custom Render Texture**. This is valid only for 3D texture and 2D texture array types. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
_CustomRenderTextureWidth
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,11 @@
# Custom Render Textures
With Custom Render Textures, you can use Shader Graph to create shaders that are compatible with Custom Render Texture Update and Initialization materials. The following topics describe how to access the shader properties and set up a Shader Graph for Custom Render Texture shaders.
| **Topic** | **Description** |
| :------------------------------ | :------------------------------- |
| **[Access Custom Render Texture shader properties](Custom-Render-Texture-Accessing.md)** | Access specific texture coordinates and other shader properties. |
| **[Example Custom Render Texture with Shader Graph](Custom-Render-Texture-Example.md)** | Set up a Shader Graph for Custom Render Texture shaders to create a self-healing deformation effect that could be used for snow, sand, etc. |
## Additional resources
[Custom Render Textures](https://docs.unity3d.com/Manual/class-CustomRenderTexture.html).
@@ -0,0 +1,225 @@
# Create a Custom Function node
Create and set up a Custom Function node to execute an HLSL function specified as a string or as an HLSL include file.
To set up a Custom Function node:
1. [Create a new node](Create-Node-Menu.md) of **Custom Function** type (from the **Utility** category).
1. In the [Graph Inspector](Internal-Inspector.md), select **Node Settings**.
1. [Define custom **Inputs** and **Outputs**](Custom-Port-Menu.md) to set the node's ports and the corresponding variables to use in the custom function.
1. Define the custom function according to your needs, either with a [file](#define-the-custom-function-with-a-file) or a [string](#define-the-custom-function-with-a-string).
## Define the custom function with a string
In **String** mode, the graph generates the shader function.
To define the function with a string:
1. In the Graph Inspector, in the Node Settings, Set **Type** to **String**.
1. In the **Name** field, specify a name for the function.
1. In the **Body** field, write the contents of the function. Unity handles the arguments, braces, and indent scope automatically.
In **String** mode, you may use the token `$precision` instead of `half` or `float` in the **Body** field. Unity replaces this with the correct type when the node is processed, based on that node's precision.
![04](images/Custom-Function-Node-String-wFunction.png)
The example in the image above generates the following function:
```
void MyFunction_float(float3 A, float B, out float3 Out)
{
Out = A + B + 1/2;
}
```
## Define the custom function with a file
In **File** mode, the graph does not automatically generate the shader function. This mode injects an include reference in the final generated shader, and uses a function from within the referenced file.
To create an HLSL file to use from a Custom Function node:
1. Use your file system to create an empty text file with the `.hlsl` extension in any folder of your Unity project.
1. Write your custom function according to the [file content syntax](#file-content-syntax-details-and-examples).
To use a function from the HLSL file in the node:
1. In the Graph Inspector, in the Node Settings, set **Type** to **File**.
1. In the **Source** field, reference the HLSL file that contains the function.
1. In the **Name** field, specify the name of the function to call in the file, **without** the function precision suffix `_half ` or `_float `.
![06](images/Custom-Function-Node-File-wFunction.png)
### File content syntax, details, and examples
HLSL files you reference in Custom Function nodes can contain one or multiple functions. In all cases, you have to match the following expectations:
* The file should include a `#ifndef` condition along with a `#define` statement with an identifier to make sure Unity doesn't load the same functions twice, which would result in a compile error.
* You must use the same id string for the `#ifndef` condition and the `#define` statement.
* If you create multiple HLSL files for Custom Function nodes in the same project, you must use a different id string for each file.
* Each function name must have a precision suffix:
* Use `_float` to run the function in full precision mode.
* Use `_half` if you need to save resources, which might only apply to certain platforms.
* The function arguments must correspond to the Inputs you defined in the Node Settings.
For example:
```
//UNITY_SHADER_NO_UPGRADE
#ifndef MYHLSLINCLUDE_INCLUDED
#define MYHLSLINCLUDE_INCLUDED
void MyFunction_float(float3 A, float B, out float3 Out)
{
Out = A + B;
}
#endif //MYHLSLINCLUDE_INCLUDED
```
The **File** mode allows for more flexibility with custom functions in a graph.
### Multiple functions and multiple files
You can define multiple functions in the same file, and call them from your referenced function. Alternatively, you can reference the same file, but use different functions from different Custom Function nodes.
```
//UNITY_SHADER_NO_UPGRADE
#ifndef MYHLSLINCLUDE_INCLUDED
#define MYHLSLINCLUDE_INCLUDED
float3 MyOtherFunction_float(float3 In)
{
return In * In;
}
void MyFunction_float(float3 A, float B, out float3 Out)
{
A = MyOtherFunction_float(A);
Out = A + B;
}
#endif //MYHLSLINCLUDE_INCLUDED
```
You can even include other files that contain other functions.
```
//UNITY_SHADER_NO_UPGRADE
#ifndef MYHLSLINCLUDE_INCLUDED
#define MYHLSLINCLUDE_INCLUDED
#include "Assets/MyOtherInclude.hlsl"
void MyFunction_float(float3 A, float B, out float3 Out)
{
A = MyOtherFunction_float(A);
Out = A + B;
}
#endif //MYHLSLINCLUDE_INCLUDED
```
## Use shared data and existing Unity functions
Pass shared data into your custom function through uniform variables, and call functions from Unity's Render Pipeline shader libraries.
### Shared data and uniform variables
To supply shared data to your function without additional ports, use uniform variables defined outside the function scope.
```
//UNITY_SHADER_NO_UPGRADE
#ifndef MYHLSLINCLUDE_INCLUDED
#define MYHLSLINCLUDE_INCLUDED
float4x4 _MyMatrix;
void MyFunction_float(float3 A, float B, out float3 Out)
{
A = mul(float4(A, 0.0), _MyMatrix).rgb;
Out = A + B;
}
#endif //MYHLSLINCLUDE_INCLUDED
```
When you add a uniform variable in a Custom Function, like the `float4x4` matrix in the example above, you make this variable global. As a result:
- You can set this uniform globally only, using `Shader.SetGlobalMatrix()`.
- You don't have to add an input parameter to allow the shader to access them directly.
- You can't set it per material, because it's not declared in the `UnityPerMaterial` cbuffer and doesn't have a material property associated with it.
### Call Unity shader code functions
You can call from your custom function any shader code functions that are part of existing Unity's Render Pipeline libraries.
However, be aware of the following:
* Your project must include the library that contains the shader code functions you need to call. To prevent errors, you should always isolate the code with an `#if defined()` condition according to the library you're using, and define fallback values for the variables. The usual keywords that identify Unity shader code libraries are the following:
* For the [Built-In Render Pipeline (BiRP)](https://docs.unity3d.com/Manual/use-built-in-shader-methods-birp.html) library, use `#if defined(BUILTIN_PIPELINE_CORE_INCLUDED)`.
* For the [Universal Render Pipeline (URP)](https://docs.unity3d.com/Manual/urp/use-built-in-shader-methods.html) library, use `#if defined(UNIVERSAL_PIPELINE_CORE_INCLUDED)`.
* For the [High-Definition Render Pipeline (HDRP)](https://docs.unity3d.com/Manual/high-definition-render-pipeline.html) library, use `#if defined(UNITY_HEADER_HD_INCLUDED)`.
* The Shader Graph node and main previews can't access Unity's Render Pipeline libraries in the Editor. This generates compile errors in the Editor even though the shader works correctly in your project. To prevent this issue, you have to isolate the code with an `#ifdef SHADERGRAPH_PREVIEW` condition and also define default values for the variables in the Shader Graph preview context.
* The code in libraries might change over time from one Unity version to another. You need to make sure to regularly test and update your custom functions in your projects.
[!include[birp-deprecation-message](snippets/birp-deprecation-message.md)]
Here is an example with URP library function calls and the above-mentioned conditional protections set up:
```
#ifdef SHADERGRAPH_PREVIEW
half3 color = half3(0,0,0);
half atten = 1;
half3 dir = half3 (0.707, 0, 0.707);
#else
#if defined(UNIVERSAL_PIPELINE_CORE_INCLUDED)
half4 shadowCoord = TransformWorldToShadowCoord(WorldPosition);
Light mainLight = GetMainLight(shadowCoord);
half3 color = mainLight.color;
half atten = mainLight.shadowAttenuation;
half3 dir = mainLight.direction;
#else
half3 color = half3(0, 0, 0);
half atten = 1;
half3 dir = half3 (0.707, 0, 0.707);
#endif
#endif
```
## Reuse Custom Function Nodes
The Custom Function node, on its own, is a single node instance. If you wish to reuse the same custom function without re-creating the inputs, outputs, and function referencing, include the Custom Function node in a [Sub Graph](Sub-graph.md). Once created, the Sub Graph appears in the [Create Node Menu](Create-Node-Menu.md), along with the nodes.
![11](images/Custom-Function-Node-Subgraph.png)
You can create a Sub Graph and add a Custom Function node to it, or right-click an existing Custom Function node and select `Convert to Sub Graph`. To add the appropriate input and output ports, use the [Graph Inspector](Internal-Inspector.md) and [Custom Port Menu](Custom-Port-Menu.md).
## Work with texture wires
From version 10.3, Shader Graph has five new data structures to ensure that Custom Function nodes and Sub Graphs input and output data from texture wire in a consistent way. The new structures also make it possible for SamplerState to compile on [GLES2](https://en.wikipedia.org/wiki/OpenGL_ES#OpenGL_ES_2.0) platforms and access data associated with textures via `myInputTex.samplerstate` and `myInputTex.texelSize`.
Four structures are for the texture types, and one is for the sampler state:
* UnityTexture2D
* UnityTexture2DArray
* UnityTexture3D
* UnityTextureCube
* UnitySamplerState
Custom Function nodes you create with earlier versions of Shader Graph continue to work after this change. As part of the automatic update, Unity transitions them to the new **Bare** node type. This type replicates the old input and output behavior. All other types pass the new structs.
However, you should manually upgrade Custom Function nodes that produce texture or samplerstate types as output to ensure that they behave consistently—and to gain the benefits of the new design. Unity flags this type of outdated Custom Function Nodes with a warning when you open your Shader Graph in 10.3 or later.
### How to upgrade
1. Change all of the input and output types from **Bare** to **non-Bare**.<br/>
* **String** type: Ensure that your HLSL string already uses Unity's texture access macros (such as `SAMPLE_TEXTURE2D`).
* **File** type: Replace Bare types (such as Texture2D) with the new struct types (such as UnityTexture2D) in your function parameters.
2. If your HLSL code is using platform-specific or non-standard texture operations, you'll need to convert the way you access textures to take that structure into account. For example, `myInputTex.GetDimensions(...)` would become `myInputTex.tex.GetDimensions(...)`
From version 10.3, you can access data associated with textures via `myInputTex.samplerstate` and `myInputTex.texelSize`.
## Additional resources
- [Custom Function node reference](Custom-Function-Node.md)
@@ -0,0 +1,132 @@
# Create a custom node by reflection from HLSL
Create custom nodes by reflection from HLSL files and automatically make them available in the Shader Graph node library.
## Reflect an HLSL function into a Shader Graph node
Follow these steps:
1. Create an empty HLSL file anywhere in your Unity project: from the Editor's menu, select **Assets** > **Create** > **Shader** > **Empty HLSL**.
1. Write your HLSL function.
1. Add the following include at the top of the file: `#include "ShaderApiReflectionSupport.hlsl"`.
1. Precede the function declaration with `UNITY_EXPORT_REFLECTION`.
1. Save the HLSL file.
### Example
```
#include "ShaderApiReflectionSupport.hlsl"
UNITY_EXPORT_REFLECTION
float3 MyCustomFunction(
float3 param1,
float param2)
{
return param1 * param2;
}
```
## List the reflected node in Shader Graph's Create Node menu.
To make a reflected node available in Shader Graph's [**Create Node** menu](Create-Node-Menu.md), you minimally have to assign it a provider key.
To specify a provider key value, in the HLSL include file, precede the function with the following hint:
```
///<funchints>
/// <sg:ProviderKey>MyValue</sg:ProviderKey>
///</funchints>
```
By default, as soon as you specify a provider key, Unity places the reflected node in the **Reflected by Path** category and uses its corresponding function name to identify it. However, you can use [additional reflection hints](Custom-nodes-hlsl-reflection-hints-reference.md) to the HLSL include file to specify custom category and node display names, and more. For more details, refer to the next section.
## Further customize the reflected node
To further customize the behavior and appearance of the reflected function node and its parameters in Shader Graph, you have to precede the function with a list of [reflection hints](Custom-nodes-hlsl-reflection-hints-reference.md) in the HLSL include file.
There are two types of hints:
* Function hints for the function node as a whole.
* Parameter hints for the node parameters and ports.
### Add function hints
Add function hints (`funchints`) to further customize the node as a whole.
For example, to specify a provider key, a display name, and a **Create Node** menu search category for the node, use the following :
```
///<funchints>
/// <sg:ProviderKey>MyCustomUniqueID</sg:ProviderKey>
/// <sg:DisplayName>My Very Custom Function</sg:DisplayName>
/// <sg:SearchCategory>Custom/MyFunction</sg:SearchCategory>
///</funchints>
```
Make sure to meet the following criteria:
* Use a `<funchints></funchints>` xml tag pair to wrap the list.
* Start all lines with a triple-slash (`///`).
### Add parameter hints
Add parameter hints (`paramhints`) to further customize the node parameters and ports.
For example, to specify input port display names, types, and default values, use the following:
```
///<paramhints name = "param1">
/// <sg:DisplayName>Color</sg:DisplayName>
/// <sg:Color/>
/// <sg:Default>1,1,0</sg:Default>
///</paramhints>
///<paramhints name = "param2">
/// <sg:DisplayName>Range</sg:DisplayName>
/// <sg:Range>0, 1</sg:Range>
/// <sg:Default>0.25</sg:Default>
///</paramhints>
```
Make sure to meet the following criteria:
* Use a `<paramhints name = "paramname"></paramhints>` xml tag pair to wrap the list for each parameter.
* For `paramname`, use the name of the parameter as you specified it in the HLSL function.
* Start all lines with a triple-slash (`///`).
## Complete example
The following code snippet groups all the example cases provided in the previous sections. You can use it as is in your project to test the feature.
```
#include "ShaderApiReflectionSupport.hlsl"
///<funchints>
/// <sg:ProviderKey>MyCustomUniqueID</sg:ProviderKey>
/// <sg:DisplayName>My Very Custom Function</sg:DisplayName>
/// <sg:SearchCategory>Custom/MyFunction</sg:SearchCategory>
///</funchints>
///<paramhints name = "param1">
/// <sg:DisplayName>Color</sg:DisplayName>
/// <sg:Color/>
/// <sg:Default>1,1,0</sg:Default>
///</paramhints>
///<paramhints name = "param2">
/// <sg:DisplayName>Range</sg:DisplayName>
/// <sg:Range>0, 1</sg:Range>
/// <sg:Default>0.25</sg:Default>
///</paramhints>
UNITY_EXPORT_REFLECTION
float3 MyCustomFunction(
float3 param1,
float param2)
{
return param1 * param2;
}
```
## Additional resources
- [Introduction to HLSL in Shader Graph](Custom-nodes-hlsl-introduction.md)
- [Node Reference sample](Shader-Graph-Sample-Node-Reference.md): in the `Utility` folder, refer to the `ReflectedFunction` graph.
- [Reflected function hints reference](Custom-nodes-hlsl-reflection-hints-reference.md)
@@ -0,0 +1,32 @@
# Introduction to HLSL in Shader Graph
Create nodes based on your own custom HLSL functions to extend the Shader Graph functionality.
If you're familiar with [High Level Shader Language (HLSL)](https://docs.unity3d.com/Manual/shaders-reference.html), you can code your own custom shader functions to include them as nodes in your graphs.
There are two different methods to include your own HLSL code in a shader graph:
* Add a Custom Function node from the Shader Graph node library to make it execute HLSL code.
* Use reflection from an HLSL include file to automatically generate a custom node and make it available in the Shader Graph node library.
## Code execution through a Custom Function node
This method uses a [Custom Function node](Custom-Function-Node.md) from the Shader Graph node library as a starting point.
When you configure a Custom Function node, you can either write an HLSL function directly in the node settings or specify a path to a function you saved in an HLSL include file of your project.
In both cases, you have to manually add input and output ports to the node and make sure their names and types match the parameter names and types you use in the HLSL function.
For more details, refer to [Custom function node](Custom-Function-Node.md).
## Node creation by reflection from an HLSL include file
This method uses an HLSL include file of your project as a starting point.
When you prepare the HLSL include file, you have to add specific lines of code to make sure the HLSL function reflects as a node in the Shader Graph node library. Unity automatically creates input and output ports in the node by reflection from the parameters and return type specified in the HLSL function signature.
With this method, you can also further customize the behavior and appearance of the node and of its ports and parameters in Shader Graph. For example, you can set default values and force a parameter to be constant.
For more details, refer to [Create a custom node by reflection from HLSL](Custom-nodes-hlsl-create-node-by-reflection.md).
## Additional resources
- [Node Reference sample](Shader-Graph-Sample-Node-Reference.md): in the `Utility` folder, refer to the `CustomFunction` and `ReflectedFunction` graphs.
@@ -0,0 +1,10 @@
# Create custom nodes with HLSL
Use HLSL to extend the Shader Graph functionality with custom functions.
| Topic | Description |
| :--- | :--- |
| [Introduction to HLSL in Shader Graph](Custom-nodes-hlsl-introduction.md) | Learn how you can use HLSL code in a Shader Graph context. |
| [Create Custom Function node using HLSL](Custom-nodes-hlsl-create-custom-function-node.md) | Create a Custom Function node that executes an HLSL function specified as a string or as an HLSL include file. |
| [Create a custom node by reflection from HLSL](Custom-nodes-hlsl-create-node-by-reflection.md) | Write HLSL functions to use as custom nodes by reflection and automatically make them available in the Shader Graph node library. |
| [Reflected function hints reference](Custom-nodes-hlsl-reflection-hints-reference.md) | Learn about all the hints you can use to further customize the behavior and appearance of the reflected function node in Shader Graph. |
@@ -0,0 +1,44 @@
# Reflected function hints reference
Use hints to further customize the behavior and appearance, in Shader Graph, of a node generated by reflection from an HLSL function.
To know how to add the following hints to the HLSL function, refer to [Further customize the reflected node](Custom-nodes-hlsl-create-node-by-reflection.md#further-customize-the-reflected-node).
## Function hints
Use function hints (`funchints`) to customize the behavior and appearance of the Reflected Function node as a whole.
| Hint | Value / type | Description |
| :--- | :--- | :--- |
| `sg:DisplayName` | String | Specifies a custom display name for the node. If you don't use this hint, Unity uses a formatted version of the HLSL function name. |
| `sg:DynamicPrecision` | N/A | Enables the use of dynamic precision for all supported ports of the node. |
| `sg:ProviderKey` | String | Specifies a stable identifier for the reflected function. This hint is mandatory. It allows you to reference the function across any changes to the qualified signature. |
| `sg:ReturnDisplayName` | String | Specifies a custom display name for the node's output port. The default output port display name is **Out**. |
| `sg:SearchCategory` | Forward slash separated list of strings | Specifies a category path to use in the Create node menu. If you don't use this hint, Unity uses the namespace if present, otherwise the path to the source file. |
| `sg:SearchName` | String | Specifies a node name to use in the Create Node menu to differentiate between overloads that might have the same display name. |
| `sg:SearchTerms` | Comma-separated list of strings | Specifies synonyms for the node name to provide a wider range of matches when a user searches for the node in the Create Node menu. |
## Parameter hints
Use parameter hints (`paramhints`) to customize the behavior and appearance of any input port or parameter of the Reflected Function node.
| Hint | Value / type | Description |
| :--- | :--- | :--- |
| `sg:Color` | N/A | Renders the input as a color picker. |
| `sg:CustomBinding` | String | Specifies a custom UI binding label for the port. |
| `sg:Default` | String | Specifies a default value for the parameter. The string depends on the parameter type, commonly a list of comma-separated floats, referable default tokens such as `UV1`, or 0-based dropdown indices. |
| `sg:DisplayName` | String | Specifies a custom display name for the port. If you don't use this hint, Unity uses a formatted version of the HLSL parameter name. |
| `sg:Dropdown` | Comma separated list of strings | Manages the input as a dropdown with at least one option and specifies the option labels. The parameter type must be int, uint, float, or half. The dropdown value is the index of the entry in the list. |
| `sg:DynamicVector` | N/A | Enables the use of dynamic dimension (for example, scalar, vector2, vector3, vector4) for a scalar or vector parameter. |
| `sg:External` | String | Specifies a namespace prefix for unknown types. The result must be a valid HLSL formatted qualified namespace: `Namespace::TypeName`. |
| `sg:Linkage` | String | For a `bool` input only, links the UI state to another parameter on the same function. Specify the name of the other parameter to link to. If the other parameter's port is connected, this input state is true, otherwise false. Setting linkage forces the port to be treated as local internally. |
| `sg:Literal` | N/A | Marks the scalar port as a literal control (`float`/`half`/`int`/`uint` only). |
| `sg:Local` | N/A | Marks the parameter as local and hides it in the graph UI. Use this hint only if you need to have a local variable that is also Dynamic or has Precision. You should also preferably use it with `out` parameters to prevent unneeded initialization. |
| `sg:Range` | float, float | Renders the input as a slider and sets a range with minimum and maximum values. The range is not enforced in the shader code. You should expect to clamp the input. |
| `sg:Referable` | String | Binds the input to a built-in referable. Specify one of the following:<ul><li>`UV` (expects `float2` or `half2`).</li><li>`ScreenPosition` or `VertexColor` (expect `float4` or `half4`).</li><li>`Bitangent`, `Normal`, `Position`, `Tangent`, or `ViewDirection` (expect `float3` or `half3`).</li></ul>**Note**: All these values are also available as standalone hints that don't require any `sg:Referable` mention. For example, you can use `<UV />` instead of `<sg:Referable>UV</sg:Referable>`. |
| `sg:Static` | N/A | Forces the parameter to be static and hides the port in the graph UI. Valid on scalar `float`/`half`/`int`/`uint`/`bool`, or on `float3`/`float4`/`half3`/`half4` only if `sg:Color` is also present. |
## Additional resources
- [Introduction to HLSL in Shader Graph](Custom-nodes-hlsl-introduction.md)
- [Create a custom node by reflection from HLSL](Custom-nodes-hlsl-create-node-by-reflection.md)
@@ -0,0 +1,27 @@
# DDX Node
## Description
Returns the partial derivative of the input **In** with respect to the screen-space x-coordinate. This node can only be used in the pixel shader stage.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output partial derivative value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_DDX_float4(float4 In, out float4 Out)
{
Out = ddx(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# DDXY Node
## Description
Returns the sum of both partial derivatives of input **In**, with respect to the screen-space x-coordinate and screen-space y-coordinate respectively. This node can only be used in the pixel shader stage.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output partial derivative value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_DDXY_float4(float4 In, out float4 Out)
{
Out = ddxy(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# DDY Node
## Description
Returns the partial derivative of the input **In** with respect to the screen-space y-coordinate. This node can only be used in the pixel shader stage.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output partial derivative value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_DDY_float4(float4 In, out float4 Out)
{
Out = ddy(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,52 @@
# Data Types
## Description
There are a number of **Data Types** in [Shader Graph](index.md). Each **Port** on a [Node](Node.md) has an associated **Data Type** that defines what wires can be connected to it. The **Data Types** have colors for usability, these colors are applied to ports and wires of that **Data Type**.
Some **Data Types** have associated [Property Types](Property-Types.md) for exposing these values to the [Inspector](https://docs.unity3d.com/Manual/UsingTheInspector.html) for [Materials](https://docs.unity3d.com/Manual/class-Material.html) that use the shader.
## Data Types
| Name | Color | Description |
|:------------|:----------------|:------------|
| Float | Light Blue | A **Float** or scalar value |
| Vector 2 | Green | A **Vector 2** value |
| Vector 3 | Yellow | A **Vector 3** value |
| Vector 4 | Pink | A **Vector 4** value |
| Dynamic Vector | Light Blue | See **Dynamic Data Types** below |
| Matrix 2 | Blue | A **Matrix 2x2** value |
| Matrix 3 | Blue | A **Matrix 3x3** value |
| Matrix 4 | Blue | A **Matrix 4x4** value |
| Dynamic Matrix | Blue | See **Dynamic Data Types** below |
| Dynamic | Blue | See **Dynamic Data Types** below |
| Boolean | Purple | A **Boolean** value. Defined as a float in the generated shader |
| Texture 2D | Red | A [Texture 2D](https://docs.unity3d.com/Manual/class-TextureImporter.html) asset |
| Texture 2D Array | Red | A [Texture 2D Array](https://docs.unity3d.com/Manual/class-TextureImporter.html) asset |
| Texture 3D | Red | A [Texture 3D](https://docs.unity3d.com/Manual/class-TextureImporter.html) asset |
| Cubemap | Red | A [Cubemap](https://docs.unity3d.com/Manual/class-Cubemap.html) asset |
| Virtual Texture | Gray | A [Texture Stack](https://docs.unity3d.com/2020.1/Documentation/Manual/svt-use-in-shader-graph.html) |
| Gradient | Gray | A **Gradient** value. Defined as a struct in the generated shader |
| SamplerState | Gray | A state used for sampling a texture |
## Promoting/Truncating
All **Vector** types can be promoted or truncated to match any **Vector** type [Port](Port.md). This behaviour occurs only when the [Port](Port.md) in question is not of type **Dynamic Vector**. When truncating, excess channels are simply removed. When promoting, the extra required channels are filled by default values. These values are (0, 0, 0, 1).
## Dynamic Data Types
Some **Data Types** are dynamic. This means a port using these **Data Types** can change their underlying **Concrete Data Type** based on what **Data Type** is connected to it. By default, [Nodes](Node.md) using dynamic **Data Types** can only have one **Concrete Data Type**, meaning that once a connected wire has applied its **Data Type** to that port, all other **Dynamic Data Type** slots of that [Node](Node.md) will apply the same **Data Type**.
One notable exception to this is the [Multiply Node](Multiply-Node.md) which allows both **Dynamic** **Matrix** and **Vector** types.
### Dynamic Vector
The **Dynamic Vector** type allows connected wires of any **Vector** type. All connected wires are automatically truncated to the type with the lowest dimension, unless the lowest dimension is 1, in which case the **Float** is promoted.
### Dynamic Matrix
The **Dynamic Matrix** type allows connected wires of any **Matrix** type. All connected wires are automatically truncated to the type with the lowest dimension.
### Dynamic
The **Dynamic** type is a special case. [Nodes](Node.md) that support it must define how it is validated. In the case of the [Multiply Node](Multiply-Node.md), it allows connections of any **Vector** or **Matrix** type, ensuring the correct multiplication is applied depending on the mix of **Data Types**.
@@ -0,0 +1,29 @@
# Degrees To Radians Node
## Description
Returns the value of input **In** converted from degrees to radians.
One degree is equivalent to approximately 0.0174533 radians and a full rotation of 360 degrees is equal to 2 Pi radians.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value in degrees |
| Out | Output | Dynamic Vector | Output value in radians |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_DegreesToRadians_float4(float4 In, out float4 Out)
{
Out = radians(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,63 @@
# Dielectric Specular Node
## Description
Returns a **Dielectric Specular** F0 value for a physically based material. The material to use can be selected with the **Material** dropdown parameter on the [Node](Node.md).
A **Common** **Material** type defines a range between 0.034 and 0.048 sRGB values. The value between this range can be selected with the **Range** parameter. This **Material** type should be used for various materials such as plastics and fabrics.
You can use **Custom** material type to define your own physically based material value. The output value in this case is defined by its index of refraction. This can be set by the parameter **IOR**.
## Ports
| Name | Direction | Type | Binding | Description |
|:--- |:---|:---|:---|:---|
| Out | Output | Float | None | Output value |
## Controls
| Control | Description |
|:---|:---|
| **Material** | Selects the material value to output. The options are:<ul><li>**Common**</li><li>**RustedMetal**</li><li>**Water**</li><li>**Ice**</li><li>**Glass**</li><li>**Custom**</li></ul> |
| **Range** | Controls the output value for a **Common** material type. |
| **IOR** | Controls the index of refraction for a **Custom** material type. |
## Generated Code Example
The following example code represents one possible outcome of this node per **Material** mode.
**Common**
```
float _DielectricSpecular_Range = 0.5;
float _DielectricSpecular_Out = lerp(0.034, 0.048, _DielectricSpecular_Range);
```
**RustedMetal**
```
float _DielectricSpecular_Out = 0.030;
```
**Water**
```
float _DielectricSpecular_Out = 0.020;
```
**Ice**
```
float _DielectricSpecular_Out = 0.018;
```
**Glass**
```
float _DielectricSpecular_Out = 0.040;
```
**Custom**
```
float _DielectricSpecular_IOR = 1;
float _DielectricSpecular_Out = pow(_Node_IOR - 1, 2) / pow(_DielectricSpecular_IOR + 1, 2);
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,25 @@
# Diffusion Profile Node
The Diffusion Profile Node allows you to sample a [Diffusion Profile](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/diffusion-profile-reference.html) Asset in your Shader Graph. For information on what a Diffusion Profile is and the properties that it contains, see the [Diffusion Profile documentation](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/diffusion-profile-reference.html).
## Render pipeline compatibility
| **Node** | **Universal Render Pipeline (URP)** | **High Definition Render Pipeline (HDRP)** |
| ---------------------- | ----------------------------------- | ------------------------------------------ |
| Diffusion Profile Node | No | Yes |
## Ports
| name | **Direction** | type | description |
|--- | --- | --- | --- |
| **Out** | Output | float | Outputs a unique float that the Shader uses to identify the Diffusion Profile. |
## Notes
The output of this Node is a float value that represents a Diffusion Profile. The Shader can use this value to find settings for the Diffusion Profile Asset that this value represents.
If you modify the output value, the Shader can no longer use it to find the settings for the Diffusion Profile Asset. You can use this behavior to enable and disable Diffusion Profiles in your Shader Graph. To disable a Diffusion Profile, multiply the output by **0**. To enable a Diffusion Profile, multiply the output by **1**. This allows you to use multiple Diffusion Profiles in different parts of your Shader Graph. Be aware that the High Definition Render Pipeline (HDRP) does not support blending between Diffusion Profiles. This is because HDRP can only evaluate a single Diffusion Profile per pixel.
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,28 @@
# Distance Node
## Description
Returns the euclidean distance between the values of the inputs **A** and **B**. This is useful for, among other things, calculating the distance between two points in space and is commonly used in calculating a [Signed Distance Function](https://en.wikipedia.org/wiki/Signed_distance_function).
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| A | Input | Dynamic Vector | First input value |
| B | Input | Dynamic Vector | Second input value |
| Out | Output | Float | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Distance_float4(float4 A, float4 B, out float Out)
{
Out = distance(A, B);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,39 @@
# Dither node
The Dither node adds a structured form of noise to the input. Use the Dither node to reduce the color bands that might appear if you move from a high number of colors to a low number (quantizing), or to simulate transparency by adding random alpha pixels to an opaque object.
The Dither node applies dithering in screen space to ensure a uniform distribution of the pattern. To change the space the node uses, connect another node to the **Screen Position** input, such as a [UV node](UV-Nodes.md).
To use a dither pattern for transparency, connect the Dither node to the **Alpha Clip Threshold** input in the [Master Stack](Master-Stack.md). As a result, when you adjust the overall alpha value of the material, some pixels are discarded because the alpha value is lower than their alpha clip threshold. This technique is useful for creating geometry that appears to be transparent but has the advantages of rendering as opaque, such as writing to the depth buffer or rendering using a deferred [rendering path](https://docs.unity3d.com/Manual/built-in-rendering-paths.html).
## Ports
| **Name** | **Direction** | **Type** | **Binding** | **Description** |
|:------------ |:-------------|:-----|:---|:---|
| **In** | Input | Dynamic vector | None | The input to dither. The noise stays within the overall minimum and maximum range of the input values. |
| **Screen Position** | Input | Vector 4 | Screen Position | The coordinates Unity uses to calculate the dither pattern. For more information about the options, refer to the [Screen Position node](Screen-Position-Node.md). |
| **Out** | Output | Dynamic vector | None | The dithered output. |
## Generated code example
The following example code represents one possible outcome of this node.
```
void Unity_Dither_float4(float4 In, float4 ScreenPosition, out float4 Out)
{
float2 uv = ScreenPosition.xy * _ScreenParams.xy;
float DITHER_THRESHOLDS[16] =
{
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
};
uint index = (uint(uv.x) % 4) * 4 + uint(uv.y) % 4;
Out = In - DITHER_THRESHOLDS[index];
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,28 @@
# Divide Node
## Description
Returns the result of input **A** (dividend) divided by input **B** (divisor).
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| A | Input | Dynamic Vector | First input value |
| B | Input | Dynamic Vector | Second input value |
| Out | Output | Dynamic Vector | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Divide_float4(float4 A, float4 B, out float4 Out)
{
Out = A / B;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,32 @@
# Dot Product Node
## Description
Returns the dot product, or scalar product, of the two input vectors **A** and **B**.
The dot product is a value equal to the magnitudes of the two vectors multiplied together and then multiplied by the cosine of the angle between them.
For normalized input vectors, the **Dot Product** node returns 1 if they point in exactly the same direction, -1 if they point in completely opposite directions and 0 if the vectors are perpendicular.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| A | Input | Dynamic Vector | First input value |
| B | Input | Dynamic Vector | Second input value |
| Out | Output | Float | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_DotProduct_float4(float4 A, float4 B, out float Out)
{
Out = dot(A, B);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,60 @@
# Dropdown node
The Dropdown node is a node representation of a Dropdown property. It allows you to create a custom dropdown menu on a Subgraph node in its parent Shader Graph. You can specify the number of options that appear in the dropdown menu, and their names.
After you create a Dropdown property and add a Dropdown node to a Subgraph, the Subgraph node in any parent Shader Graph displays with a dropdown control.
## Create Node menu category
The Subgraph Dropdown node isn't accessible from the Create Node menu.
To add a Subgraph Dropdown node to a Subgraph:
1. In the Shader Graph window, open a Subgraph.
2. In the Blackboard, select **Add** (+) and select **Dropdown**.
3. Enter a name for your new Dropdown property, and press Enter.
4. Select your Dropdown property and drag it onto your graph to create a new Subgraph Dropdown node.
5. Select your new Dropdown node in your graph or the Dropdown property in the Blackboard and open the Graph Inspector.
6. Select the **Node Settings** tab.
7. In the **Entries** table, select **Add to the list** (+) to add a new option to your dropdown. Each Entry adds a corresponding input port to your node.
To remove an Entry, select its handle in the list and select **Remove selection from the list** (-).
8. (Optional) In the **Default** list, select the default Entry that you want Shader Graph to select on your property.
## Ports
> [!NOTE]
> The Subgraph Dropdown node's number of input ports and their names directly correspond to the settings you specify in the Graph Inspector's **Node Settings** tab. The node always has one output port.
A Subgraph Dropdown node's input ports always have the **DynamicVector** type. This means that you can make a connection to an input port from any node that outputs a float, Vector 2, Vector 3, Vector 4, or Boolean value. For more information, see [Dynamic Data Types](Data-Types.md#dynamic-data-types).
It has one output port:
| **Name** | **Type** | **Description** |
| :--- | :----------- | :---------- |
| Out | DynamicVector | The selected option from the dropdown menu on the parent Shader Graph's Subgraph node. This value can also be the specified **Default** for the property in the Graph Inspector's **Node Settings** tab. |
## Example graph usage
In the following example, a Subgraph Dropdown node changes the UV channel it sends to the Subgraph's Output node. The selection on the Subgraph node in the parent graph changes whether the Subgraph outputs **UV1** or **UV0**. If the Subgraph is used in multiple Shader Graphs, the Subgraph Dropdown node can change the UV channel output without changing the Subgraph:
![An image of the Graph window. The first input port on a Subgraph Dropdown node connects to a UV node and receives UV0. The second input port connects to a UV node and receives UV1. The Subgraph Dropdown node sends its output to the Subgraph's Output node.](images/sg-subgraph-dropdown-node-example-2.png)
## Related nodes
<!-- OPTIONAL. Any nodes that may be related to this node in some way that's worth mentioning -->
[!include[nodes-related](./snippets/nodes-related.md)] Subgraph Dropdown node:
- [Subgraph node](Sub-graph-Node.md)
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,32 @@
# Ellipse Node
## Description
Generates an ellipse shape based on input **UV** at the size specified by inputs **Width** and **Height**. The generated shape can be offset or tiled by connecting a [Tiling And Offset Node](Tiling-And-Offset-Node.md). Note that in order to preserve the ability to offset the shape within the UV space the shape will not automatically repeat if tiled. To achieve a repeating dot effect first connect your input through a [Fraction Node](Fraction-Node.md).
NOTE: This [Node](Node.md) can only be used in the **Fragment** [Shader Stage](Shader-Stage.md).
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| UV | Input | Vector 2 | UV | Input UV value |
| Width | Input | Float | None | Ellipse width |
| Height | Input | Float | None | Ellipse height |
| Out | Output | Float | None | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Ellipse_float(float2 UV, float Width, float Height, out float4 Out)
{
float d = length((UV * 2 - 1) / float2(Width, Height));
Out = saturate((1 - d) / fwidth(d));
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,43 @@
# Emission node
The Emission node outputs a color that makes a material appear as a visible source of light.
## Render pipeline compatibility
The Emission node is compatible only with the High Definition Render Pipeline (HDRP).
## Ports
| **Name** | **Direction** | **Type** | **Description** |
|-|-|-|-|
| **Color** | Input | Low dynamic range (LDR) RGB color | Sets the low dynamic range (LDR) color to make emissive. |
| **Intensity** | Input | Float | Sets the intensity of the emission of the output color. |
| **Exposure Weight** | Input | Float | Sets how much the [exposure](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/Override-Exposure.html) of the scene affects emission. The range is between 0 and 1. A value of 0 means that exposure does not affect this part of the emission. A value of 1 means that exposure fully affects this part of the emission. |
| **Output** | Output | High dynamic range (HDR) RGB color | The emissive color. |
## Properties
| **Name** | **Description** |
|-|-|
| **Intensity Unit** | Sets the unit of the **Intensity** property. For more information, refer to [Understand physical light units](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/Physical-Light-Units.html). The options are: <ul><li>**Nits**: Sets the units as nits, which is a measure of luminance, the surface power of a light source.</li><li>**EV100**: Sets the units as EV<sub>100</sub>, which is a measure of exposure value.</li></ul> |
| **Normalize Color** | Adjusts the intensity of the input color so the red, green, and blue values look similar. As a result, colors are more balanced in the **Output**. |
## Generated code example
```hlsl
float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight)
{
// Convert the LDR color. This line is generated only if Normalize Color is enabled.
ldrColor = ldrColor * rcp(max(Luminance(ldrColor), 1e-6));
float3 hdrColor = ldrColor * luminanceIntensity;
float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier();
hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight);
return hdrColor;
}
```
## Additional resources
- [Add light emission to a material](https://docs.unity3d.com/Manual/StandardShaderMaterialParameterEmission.html)
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,47 @@
# Exponential Node
## Description
Returns the exponential value of input **In**. The exponential base can be switched between base-e and base 2 from the **Base** dropdown on the node.
* **Base E** : Returns e to the power of input **In**
* **Base 2** : Returns 2 to the power of input **In**
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output value |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| Base | Dropdown | BaseE, Base2 | Selects the exponential base |
## Generated Code Example
The following example code represents one possible outcome of this node per **Base** mode.
**Base E**
```
void Unity_Exponential_float4(float4 In, out float4 Out)
{
Out = exp(In);
}
```
**Base 2**
```
void Unity_Exponential2_float4(float4 In, out float4 Out)
{
Out = exp2(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,28 @@
# Exposure node
The Exposure node outputs the exposure value of the current camera. You can output the value from the current frame or the previous frame.
## Render pipeline compatibility
The Exposure node is compatible only with the High Definition Render Pipeline (HDRP).
For more information about exposure, refer to [Control exposure](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/Override-Exposure.html) in the HDRP manual.
## Ports
| **Name** | **Direction** | **Type** | **Description** |
|--- | --- | --- | --- |
| **Output** | Output | Float | The exposure value of the camera. |
## Type
Use the **Type** property to select which exposure value to get. The options are:
- **Current Multiplier**: Gets the camera's exposure value from the current frame.
- **Inverse Current Multiplier**: Gets the inverse of the camera's exposure value from the current frame.
- **Previous Multiplier**: Gets the camera's exposure value from the previous frame.
- **Inverse Previous Multiplier**: Gets the inverse of the camera's exposure value from the previous frame.
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,38 @@
# Expression node
Use the Expression node to specify a complex mathematical expression as a string instead of using multiple [Math nodes](Math-Nodes.md).
> [!NOTE]
> Unity injects the provided expression into the shader code as HLSL and validates it through preview shader compilation. Ensure that the provided expression conforms to HLSL syntax.
## Input ports
The number and type of input ports automatically adjust to the values of the [node controls](#controls). Unity adds an input port for each variable in the expression in the text field.
## Output port
| **Name** | **Type** | **Description** |
| :--- | :--- | :--- |
| **Out** | Depends on the selected **Type** in the [node controls](#controls). | The value resulting from the expression specified in the text field. |
## Controls
| **Name** | **Description** |
| :--- | :--- |
| **Type** | Specifies the data type to use for all input and output ports of the node. The options are:<ul><li>**Vector 1**</li><li>**Vector 2**</li><li>**Vector 3**</li><li>**Vector 4**</li></ul> |
| (Text field) | Use this field to specify the mathematical expression. The field supports the following:<ul><li>Math operators: `+`, `-`, `*`, `/`, and parentheses.</li><li>HLSL intrinsic functions: for example, `frac` and `saturate`.</li><li>Vector swizzling: for example, `a.xw`.</li><li>Vector construction: `float2(x, y)`.</li></ul> |
## Example
If you specify the expression:
`a + b * c / 2`
* Unity adds three input ports to the node: **A**, **B**, and **C**.
* If you input 1, 2, and 10, the node calculates `1 + 2 * 10 / 2` and outputs the result to the **Out** port.
**Note**: If you use Shader Graph math nodes instead, the example requires three separate nodes: [Divide](Divide-Node.md), [Multiply](Multiply-Node.md), and [Add](Add-Node.md).
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,16 @@
# Eye Index Node
## Description
Provides access to the **Eye Index** when stereo rendering is enabled. The **Eye Index** node outputs a value of `0` for the left eye and `1` for the right eye.
## Ports
| Name | Direction | Type | Binding | Description |
|:-------|:-----------|:------|:--------|:------------|
| Out | Output | Float | None | **Eye Index** for the camera of a stereo draw. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,24 @@
# Eye Surface Type Debug Node
Debug node that allows you to visually validate the current pupil radius.
## Render pipeline compatibility
| **Node** | **Universal Render Pipeline (URP)** | **High Definition Render Pipeline (HDRP)** |
| ------------------------------- | ----------------------------------- | ------------------------------------------ |
| **Eye Surface Type Debug Node** | No | Yes |
## Ports
| name | **Direction** | type | description |
| ---------------- | ------------- | ------- | ------------------------------------------------------------ |
| **PositionOS** | Input | Vector3 | Position in object space of the current fragment to shade. |
| **EyeColor** | Input | Color | Final Diffuse color of the Eye. |
| **IrisRadius** | Input | float | The radius of the Iris in the used model. For the default model, this value should be **0.225**. |
| **Pupil Radius** | Input | float | Radius of the pupil in the iris texture as a percentage. |
| **IsActive** | Input | bool | Flag that defines if the node should be active. |
| **SurfaceColor** | Output | Color | Final Diffuse color of the Eye. |
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,38 @@
# Fade Transition Node
## Description
Fade Transition is a method of adding noise to add variation while a function transitions from on to off. This node takes in a fade value and remaps it using the noise value (usually from a texture). When FadeValue is 0, the output is always 0, and when FadeValue is 1, the output is always exactly 1. In between 0 and 1 the transition will follow the pattern in the noise.
This [Node](Node.md) is commonly used as an input to the **Alpha** block in the [Master Stack](Master-Stack.md) to provide an LOD transition.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Texture | Input | Texture 2D | None | Input value |
| Noise | Input | Float | None | The noise variation to apply to the fade function |
| FadeValue | Input | Float | None | The amount of transition to apply |
| FadeContrast | Input | Float | None | The contrast at which a single pixel goes from fully transparent to fully opaque. Higher values cause sharper edges in the transition |
| Fade | Output | Float | None | The resulting fade value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
float Unity_FadeTransitionNode_ApplyFade_float(float noise, float fadeValue, float fadeContrast)
{
float ret = saturate(fadeValue*(fadeContrast+1)+(noise-1)*fadeContrast);
return ret;
}
float Result = Unity_FadeTransitionNode_ApplyFade_float(
_NoiseValue,
_FadeValue,
_FadeContrast);
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,62 @@
# Fetch Scene Depth node
The Fetch Scene Depth node reads the depth buffer that a previous render pass wrote to on-chip memory, using it as an input attachment ([framebuffer fetch](https://docs.unity3d.com/Manual/urp/render-graph-framebuffer-fetch.html)). Unlike the [Scene Depth](Scene-Depth-Node.md) node, it doesn't sample the camera depth texture, so it avoids a round trip to video memory, especially on mobile devices that use tile-based deferred rendering, such as most mobile and XR devices.
The node reads depth only at the current pixel position. It has no UV input, so you can't sample depth at any screen coordinate. For texture-based depth sampling at any coordinate, use the [Scene Depth](Scene-Depth-Node.md) node instead.
> [!NOTE]
> This node works only in the fragment shader stage.
> [!NOTE]
> Depth input attachments are supported only in URP, and only on DirectX 12 and Vulkan. To check support at runtime, use `SystemInfo.supportsDepthAttachmentAsInputAttachment`.
This node returns a value of 0 (black) if depth input attachments aren't enabled or supported on the target platform. There's no automatic fallback to sampling the depth texture.
To make the Fetch Scene Depth node return a valid depth value, you must render the material in a pass that reads the depth buffer as an input attachment. For example, use a [Render Objects Renderer Feature](https://docs.unity3d.com/Manual/urp/renderer-features/renderer-feature-render-objects.html) with **Set As Input Attachment** enabled.
For more information, refer to [Get the current depth buffer from GPU memory in URP](https://docs.unity3d.com/Manual/urp/read-depth-input-attachment.html).
## Render pipeline support
This node supports the following render pipelines:
- Universal Render Pipeline (URP)
## Ports
| **Name** | **Direction** | **Type** | **Binding** | **Description** |
|:------------ |:-------------|:-----|:---|:---|
| **Out** | Output | Float | None | The depth value at the current pixel position. |
## Sampling modes
| **Name** | **Description** |
|----------|------------------------------------|
| **Linear 01** | Returns the linear depth value. The range is from 0 to 1. 0 is the near clipping plane of the camera, and 1 is the far clipping plane of the camera. |
| **Raw** | Returns the non-linear depth value. The range is from 0 to 1. 0 is the near clipping plane of the camera, and 1 is the far clipping plane of the camera. |
| **Eye** | Returns the depth value as the distance from the camera in meters. |
For more information about clipping planes, refer to [Introduction to the camera view](https://docs.unity3d.com/Manual/UnderstandingFrustum.html).
## Generated code example
The following example code represents one possible outcome of this node.
```
void Unity_FetchSceneDepth_Raw_float(float4 clipPos, out float Out)
{
#if defined(_DEPTH_AS_INPUT_ATTACHMENT) || defined(_DEPTH_AS_INPUT_ATTACHMENT_MSAA)
// Fetches raw depth from on-chip memory using an input attachment.
Out = shadergraph_LWFetchSceneDepth(clipPos.xy);
#else
// There is explicitly no fallback here.
Out = 0;
#endif
}
```
## Additional resources
- [Scene Depth](Scene-Depth-Node.md)
- [Get the current depth buffer from GPU memory in URP](https://docs.unity3d.com/Manual/urp/read-depth-input-attachment.html)
- [Render Objects Renderer Feature reference](https://docs.unity3d.com/Manual/urp/renderer-features/renderer-feature-render-objects.html)
@@ -0,0 +1,121 @@
# Create a shader graph and use it with a material
This example shows you how to do the following:
* Create a simple Lit shader graph with the Universal Render Pipeline (URP).
* Create and manage a material that uses this shader graph in a scene.
For more options to get started with Shader Graph, refer to:
* [Create a shader graph asset](create-shader-graph.md)
* [Add and connect nodes in a shader graph](Create-Node-Menu.md)
## Create a new shader graph
Before you can build a new shader graph, you have to create a shader graph asset to contain it. Follow these steps:
1. In the **Project** window, right-click and select **Create** > **Shader Graph** > **URP** > **Lit**.
1. Name the created shader graph asset and press Enter.
The [Shader Graph window](Shader-Graph-Window.md) opens, which allows you to edit the shader graph in the created asset. If the window doesn't open, double-click on the created asset.
## Create a new node
For this example, you need to create a Color node. Follow these steps:
1. Select the Shader Graph window's workspace and press the **Spacebar**.
The **Create Node** menu opens, with the list of all available nodes.
1. In the **Create Node** menu's search bar, type `color`.
1. In the **Input** > **Basic** category, double-click on **Color**.
A new **Color** node appears in the workspace.
## Connect the node to the master stack
To use the Color node property as an input for the shader, you need to connect the node to the master stack. Follow these steps:
1. Select the **Out(4)** port of the **Color** node.
1. Drag it to the **Base Color** block port of the **Fragment** section of the [master stack](Master-Stack.md).
This connection updates the appearance of the 3D object in the **Main Preview**, which is now black, according to the Color node's default value.
## Change the shader color
You can change the output color of the Color node to view how it affects the final shader. Follow these steps:
1. In the **Color** node, click on the color bar.
1. Use the color picker to change the color.
The color of the 3D object in the **Main Preview** changes to the selected color in real time.
## Save your shader graph
You need to save your shader graph to use it with a material. To save your shader graph, do one of the following:
* Click the **Save Asset** button in the top left corner of the window.
* Close the graph. If Unity detects any unsaved changes, a dialog appears, and asks if you want to save those changes.
## Create a material from your shader graph
After you've saved your shader graph, you can use it to create a new material.
The process of [creating a new Material](https://docs.unity3d.com/Manual/Materials.html) and assigning it a Shader Graph shader is the same as that for regular shaders.
To create a new material from your shader graph, follow these steps:
1. In the Project window, right-click the shader graph asset you created.
1. Select **Create > Material**.
Unity automatically assigns the shader graph asset to the newly created material. You can view the shader graph name selected in the material's Inspector in the **Shader** property.
## Use the material in the scene
Now that you have assigned your shader to a material, you can apply this material to GameObjects in the scene through one of the following:
* Drag the material onto a GameObject in the scene.
* In the GameObject's Inspector, go to **Mesh Renderer > Materials**, and set the **Element** property to your material.
## Control the color from the material's Inspector
You can use a property in the shader graph to alter your shader's appearance directly from the material's Inspector, without the need to edit the shader graph.
To use a Color property instead of a Color node in your shader graph, follow these steps:
1. Open the shader graph you created earlier in the [Shader Graph window](Shader-Graph-Window.md).
1. In the [Blackboard](Blackboard.md), select **Add (+)**, and then select **Color**.
The Blackboard now displays a [property of Color type](Property-Types.md#color).
1. Select the property.
1. In the [Graph Inspector](Internal-Inspector.md), in the **Node Settings** tab:
* Change the **Name** according to the name you want to identify the property within the material's Inspector.
* Make sure to activate the **Show In Inspector** option.
1. Drag the property from the Blackboard onto the Shader Graph window's workspace.
1. Connect the property's node to the **Base Color** block port of the **Fragment** section of the [master stack](Master-Stack.md), instead of the Color node you were using previously.
This connection updates the appearance of the 3D object in the **Main Preview**, which is now black, according to the property's default value.
1. Save your graph, and return to the material's Inspector.
The property you added to the graph now appears in the material's Inspector. Any changes you make to the property from the Inspector affect all objects that use this material.
## Additional resources
* [Art That Moves: Creating Animated Materials with Shader Graph](https://unity.com/blog/engine-platform/creating-animated-materials-with-shader-graph)
* [Custom Lighting in Shader Graph: Expanding Your Graphs in 2019](https://unity.com/blog/engine-platform/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019)
* [Shader Graph video tutorials](https://www.youtube.com/user/Unity3D/search?query=shader+graph) (on Unity YouTube Channel)
* [Shader Graph forum](https://discussions.unity.com/tags/c/unity-engine/52/shader-graph)
> [!NOTE]
> Older tutorials use a former version of Shader Graph with master nodes. To know the differences between the former master node and the [Master Stack](Master-Stack.md), refer to the [Upgrade Guide](Upgrade-Guide-10-0-x.md).
@@ -0,0 +1,38 @@
# Flip Node
## Description
Flips the individual channels of input **In** selected by the [Node](Node.md)'s parameters. Positive values become negative values and vice versa.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| In | Input | Dynamic Vector | None | Input value |
| Out | Output | Dynamic Vector | None | Output value |
## Controls
| Name | Type | Options | Description |
|:------------ |:-------------|:-----|:---|
| Red | Toggle | True, False | If true red channel will be flipped. |
| Green | Toggle | True, False | If true green channel will be flipped. Disabled if **In** is Float. |
| Blue | Toggle | True, False | If true blue channel will be flipped. Disabled if **In** is Vector 2 or smaller. |
| Alpha | Toggle | True, False | If true alpha channel will be flipped. Disabled if **In** is Vector 3 or smaller. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
float2 _Flip_Flip = float4(Red, Green, Blue, Alpha);
void Unity_Flip_float4(float4 In, float4 Flip, out float4 Out)
{
Out = (Flip * -2 + 1) * In;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,48 @@
# Flipbook Node
## Description
Creates a flipbook, or texture sheet animation, of the UVs supplied to input **UV**. The amount of tiles on the sheet are defined by the values of the inputs **Width** and **Height**. The index of the current tile is defined by the value of the input **Tile**.
This node can be used to create a texture animation functionality, commonly used for particle effects and sprites, by supplying [Time](Time-Node.md) to the input **Tile** and outputting to the UV input slot of a [Texture Sampler](Sample-Texture-2D-Node.md).
UV data is typically in the range of 0 to 1 starting from the bottom left of UV space. This can be seen by the black value at the bottom left corner of a UV preview. As flipbooks typically start from top left the parameter **Invert Y** is enabled by default, however you can change the direction of the Flipbook by switching the **Invert X** and **Invert Y** parameters.
## Ports
| Name | Direction | Type | Binding | Description |
|:-------|:----------|:---------|:--------|:------------|
| UV | Input | Vector 2 | UV | Input UV value |
| Width | Input | Float | None | Amount of horizontal tiles |
| Height | Input | Float | None | Amount of vertical tiles |
| Tile | Input | Float | None | Current tile index |
| Out | Output | Vector 2 | None | Output UV value |
## Controls
| Name | Type | Options | Description |
|:---------|:-------|:------------|:------------|
| Invert X | Toggle | True, False | If enabled tiles are iterated from right to left |
| Invert Y | Toggle | True, False | If enabled tiles are iterated from top to bottom |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
float2 _Flipbook_Invert = float2(FlipX, FlipY);
void Unity_Flipbook_float(float2 UV, float Width, float Height, float Tile, float2 Invert, out float2 Out)
{
Tile = floor(fmod(Tile + float(0.00001), Width*Height));
float2 tileCount = float2(1.0, 1.0) / float2(Width, Height);
float base = floor((Tile + float(0.5)) * tileCount.x);
float tileX = (Tile - Width * base);
float tileY = (Invert.y * Height - (base + Invert.y * 1));
Out = (UV + float2(tileX, tileY)) * tileCount;
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,24 @@
# Float Node
## Description
Defines a **Float** value in the shader. If [Port](Port.md) **X** is not connected with a [Wire](Wire.md) this [Node](Node.md) defines a constant **Float**.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| X | Input | Float | None | Input x component value |
| Out | Output | Float | None | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
float _Vector1_Out = X;
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,27 @@
# Floor Node
## Description
Returns the largest integer value, or whole number, that is less than or equal to the value of input **In**.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Floor_float4(float4 In, out float4 Out)
{
Out = floor(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,37 @@
# Fog Node
## Description
Provides access to the Scene's **Fog** parameters.
Note: The behavior of this [Node](Node.md) is undefined globally. Shader Graph does not define the function of the node. Instead, each Render Pipeline defines what HLSL code to execute for this [Node](Node.md).
Different Render Pipelines may produce different results. If you're building a shader in one Render Pipeline that you want to use in both, try checking it in both pipelines before production. A [Node](Node.md) might be defined in one Render Pipeline and undefined in the other. If this [Node](Node.md) is undefined, it returns 0 (black).
#### Unity Render Pipelines Support
- Universal Render Pipeline
The High Definition Render Pipeline does **not** support this Node.
## Ports
| Name | Direction | Type | Binding | Description |
|:------------ |:-------------|:-----|:---|:---|
| Position | Input | Vector 3 | Position (object space) | Mesh vertex/fragment's position |
| Color | Output | Vector 4 | None | Fog color |
| Density | Output | Float | None | Fog density based on depth. Returns a value between 0 and 1, where 0 is no fog and 1 is full fog. |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Fog_float(float3 Position, out float4 Color, out float Density)
{
SHADERGRAPH_FOG(Position, Color, Density);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,33 @@
# Fraction node
The Fraction node returns the fractional part of an input, also known as the decimal part. The range is 0 to 1. For example, the fractional part of 3.75 is 0.75.
The Fraction node calculates the result using the following formula:
```
fractional_part = input - floor(input)
```
As a result, the node returns a positive value if you input a negative number. For example, the fractional part of -3.75 is 0.25.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In | Input | Dynamic Vector | Input value |
| Out | Output | Dynamic Vector | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_Fraction_float4(float4 In, out float4 Out)
{
Out = frac(In);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]
@@ -0,0 +1,36 @@
# Fresnel Effect Node
## Description
**Fresnel Effect** is the effect of differing reflectance on a surface depending on viewing angle, where as you approach the grazing angle more light is reflected. This effect is often used to achieve rim lighting, common in many art styles.
The **Fresnel Effect** node approximates this by calculating the angle between the surface normal and the view direction. The output value is a floating-point number between `0` and `1`. This value represents the viewing angle relative to the surface and the Fresnel effect that is being calculated:
**0**: The viewing angle is 0&deg; from the surface normal, as if you are looking straight at the object.
**1**: The viewing angle is 90&deg; from the surface normal, as if you are looking along the surface or edge of the object.
A low Fresnel value (output value of `0`) means the surface appears as if viewed from the front, with minimal rim highlighting. A high Fresnel value(`1`) means the surface appears as if viewed from the side, with a strong rim highlight.
## Ports
| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| Normal | Input | Vector 3 | Normal direction. By default bound to World Space Normal |
| View Dir | Input | Vector 3 | View direction. By default bound to World Space View Direction |
| Power | Input | Float | Exponent of the power calculation |
| Out | Output | Float | Output value |
## Generated Code Example
The following example code represents one possible outcome of this node.
```
void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out)
{
Out = pow((1.0 - saturate(dot(normalize(Normal), ViewDir))), Power);
}
```
## Additional resources
[!include[nodes-example-samples](./snippets/nodes-example-samples.md)]

Some files were not shown because too many files have changed in this diff Show More