# Shader Graphs

Shader graphs can be used to define the material of particles more precisely allowing you to fine-tune colors and even make materials react dynamically to particle properties like velocity and force influence. Such a shader graph consists of nodes that work together to define the final pixel color and opacity. Each nodes implements a specific function that computes an output value from its input values, which are supplied by other nodes. Some nodes also have additional parameters that influence their function.

One example is the *Blend* node, which mixes two colors together: The two colors are connected to the input pins of the blend node while the output pin, carrying the resulting color, is connected to other nodes in the graph. The parameter *Mode* determines how the colors are blended together.

Eventually, all nodes run together into the *Output* node, which sets the final color of each pixel. Color values are stored in *RGBA (Red, Green, Blue, Alpha)* format, where each channel contains a number in the range *[0, 1]* defining the color intensity for that channel. The alpha component defines the opacity.

## Creating Shader Graphs

The shader graph of a particle type can be modified in the shader graph window. To open this window, click **Shader Graph...** in the *Material* property of the particle type.

### New Shader Graphs

Each particle type already has a default shader graph, which applies a texture and combines it with the color set in the particle properties. To assign a completely new shader graph to the object click **New** or select a preset from the drop-down menu.

### Adding Nodes

New nodes can be added by right-clicking an empty space and selecting a node type, by dragging out an attribute pin and dropping it on an empty space or by clicking **Add** in the toolbar. The list of available nodes can be filtered by typing in the search box at the top.

While right-clicking or dragging out a node pin, there are several keyboard shortcuts for creating common node types directly.

Shortcut | Node |
---|---|

1 | Number |

2 | Vector 2 |

3 | Vector 3 |

4 | Vector 4 |

B | Boolean |

C | Color |

### Modifying Nodes

After adding a new node, connect its input and output pins to the rest of the graph by dragging out links from each pin. The pin color and shape denote the data type that is expected for the attribute. For example, the red color denotes a *4-component vector*, which is used for color values. Most of the time, different data types can be converted into one another.

To remove a node, click **Remove** in the context menu of the node or select the node(s) and press **Remove** in the tool bar.

### Applying Changes

In order to apply your changes to the particle type, click **Apply** in the toolbar. Otherwise, they are discarded when you close the window.

## List of Available Nodes

### Nodes: Constants

Node | Inputs | Description |
---|---|---|

Boolean | Boolean constant, which can be true or false. | |

Integer | Integer constant, which can be any positive or negative integer. | |

Number | Number constant, which can be any rational number. | |

Vector 2 | Vector constant with two components. | |

Vector 3 | Vector constant with three components. | |

Vector 4 | Vector constant with four components. | |

Color | Color constant with four components (RGBA). |

### Nodes: Inputs

Node | Inputs | Description |
---|---|---|

Input: Texture Coordinate | Per-vertex texture coordinate for the current drawable. Used to sample textures. | |

Input: Color | Color of the particle. This input can be set with the Color attribute in the Visuals tab. | |

Input: Velocity | Velocity vector of the particle. | |

Input: Force | Force vector of the particle. | |

Input: Life | Life left for the particle, from 1.0 (particle has just spawned) to 0.0 (particle is about to disappear). | |

Input: Object ID | ID of the current drawable, which can be used to differentiate individual particles, for example. | |

Effect Time | Time passed since the effect has started. | |

Object Time | Time passed since the particle emitter was instantiated. |

### Nodes: Colors

Node | Inputs | Description |
---|---|---|

Blend | A, B | Blends colors A and B together using the specified blending mode. |

Color Ramp | Value | Picks a color from the specified gradient using Value as an index between 0.0 and 1.0. |

Adjust Brightness | Color, Brightness | Increases the brightness of Color for Brightness > 0 and decreases it for Brightness < 0. |

Adjust Exposure | Color, Exposure | Increases the exposure of Color for Exposure > 0 and decreases it for Exposure < 0. |

Adjust Contrast | Color, Contrast | Increases the contrast of Color for Contrast > 0 and decreases it for Contrast < 0. |

Adjust Saturation | Color, Saturation | Increases the saturation of Color for Saturation > 0 and decreases it for Saturation < 0. |

Posterize | Color, Number | Reduces the number of available colors per channel to Number. |

### Nodes: Textures

Node | Inputs | Description |
---|---|---|

Texture: Image | UV | Samples the given image at texture coordinate UV. |

Texture: Sprite Sheet | UV, Frame | Samples the sprite at index Frame in the given sprite sheet at texture coordinate UV. |

Tiling and Offset | UV, Tiling, Offset | Transforms texture coordinate UV by tiling it Tiling times and applying Offset. |

Twirl | UV, Amount | Transforms texture coordinate UV by twirling it with strength Amount. |

### Nodes: Procedural

Node | Inputs | Description |
---|---|---|

Circle Mask | UV, Radius, Smoothness | Generates a circular mask, where (0.5, 0.5) is the circle's center, Radius is its radius and Smoothness dictates how slowly the value falls off outside the radius. The circle is then sampled at coordinate UV. |

Noise (2D) | UV, Amplitude, Frequency, Persistence, Lacunarity | Generates 2D Simplex noise with the given parameters. This noise is sampled at coordinate UV. |

### Nodes: Math

Node | Inputs | Description |
---|---|---|

Add | A, B | Adds A and B (A + B). |

Subtract | A, B | Subtracts B from A (A - B). |

Multiply | A, B | Multiplies A with B (A * B). |

Divide | A, B | Divides A by B (A / B). |

Modulo | A, B | Computes the modulus of A and B (A mod B). |

Power | A, B | Raises A to the power of B (A).^{B} |

Natural Exponentiation | Value | Computes the natural exponentiation of Value (exp(Value)). |

Natural Logarithm | Value | Computes the natural logarithm of Value (ln(Value)). |

Sign | Value | Returns the sign of Value, i.e. +1 if Value is positive, -1 if Value is negative and 0 if Value is 0. |

Absolute Value | Value | Returns the absolute value of Value (|Value|). |

Min | A, B | Returns the minimum of A and B (min(A, B)). |

Max | A, B | Returns the maximum of A and B (max(A, B)). |

Clamp | Value, Min, Max | Limits Value to the range [Min, Max]. |

Linear Interpolation | A, B, Factor | Interpolations linearly between A and B using Factor (in the range [0, 1]). |

Floor | Value | Rounds Value down to the next integer. |

Ceil | Value | Rounds Value up to the next integer. |

Round | Value | Rounds Value to the nearest integer. |

Square Root | Value | Computes the square root of Value. |

Sin | Value | Computes the sine of Value. |

Cos | Value | Computes the cosine of Value. |

Arcsin | Value | Computes the arcus sine of Value. |

Arccos | Value | Computes the arcus cosine of Value. |

Dot Product | A, B | Computes the dot product of vectors A and B. |

Cross Product | A, B | Computes the cross product of vectors A and B. |

Normalize | Vector | Normalizes Vector to a vector of length 1. |

Vector Length | Vector | Returns the length or magnitude of Vector. |

Step | Value, Edge | Generates a step function by comparing Value to Edge. If Value < Edge, the output is 0 and otherwise 1. |

Smooth Step | Value, Edge 1, Edge 2 | Performs a smooth interpolation between 0 and 1 when Edge 1 < Value < Edge 2. |

Threshold | Value | Returns parameter Output if Value is smaller than parameter Threshold. |

### Nodes: Logic

Node | Inputs | Description |
---|---|---|

Negation (NOT) | Value | Negates the boolean Value. |

Conjunction (AND) | A, B | Outputs true if and only if both A and B are true. |

Disjunction (OR) | A, B | Outputs true if and only if A or B is true. |

Exclusive Disjunction (XOR) | A, B | Outputs true if and only if either A or B is true. |

Branch | Predicate, True, False | Outputs the value for True if Predicate evaluates to true and the value for False otherwise. |

### Nodes: Comparison

Node | Inputs | Description |
---|---|---|

Equal | A, B | Outputs true if A = B and false otherwise. |

Not Equal | A, B | Outputs true if A ≠ B and false otherwise. |

Approximately Equal | A, B | Outputs true if A ≈ B (depending on given Epsilon) and false otherwise. |

Less | A, B | Outputs true if A < B and false otherwise. |

Less or Equal | A, B | Outputs true if A ≤ B and false otherwise. |

Greater | A, B | Outputs true if A > B and false otherwise. |

Greater or Equal | A, B | Outputs true if A ≥ B and false otherwise. |

### Nodes: Utility

Node | Inputs | Description |
---|---|---|

Frame Animation | Time | Computes the frame (in a sprite sheet, for example) that has been reached after time Time. The animation is characterized by the given parameters. |

Value Curve | Value | Defines a graph using keyframes and samples this graph at position Value. |

Split Vector (2) | Vector | Splits the two-dimensional vector Vector into its components. |

Split Vector (3) | Vector | Splits the three-dimensional vector Vector into its components. |

Split Vector (4) | Vector | Splits the four-dimensional vector Vector into its components. |

Merge Vector (2) | X, Y | Combines X, Y into a two-dimensional vector. |

Merge Vector (3) | X, Y, Z | Combines X, Y, Z into a three-dimensional vector. |

Merge Vector (4) | X, Y, Z, W | Combines X, Y, Z, W into a four-dimensional vector. |