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 consits 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.
An example of a node 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.
Interaction
The shader graph of an object can be modified in the shader graph window. To open this window, click Shader Graph... from the Material property of an object.
Creating Shader Graphs
Each emitter and sprite already has a default shader graph, which applies a texture and combines it with the color set from the particle or sprite properties. To assign a completely new shader graph to the object click New or select a preset with
Preset....
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 Constant |
2 | Float2 Constant |
3 | Float3 Constant |
4 | Float4 Constant |
B | Boolean Constant |
C | Color Constant |
Removing Nodes
To remove a node, click Remove in the context menu (right mouse button) or select the node(s) and press
Remove in the tool bar.
Applying Changes
Changes to the graph are not actually applied to the object until you click Apply in the toolbar. Otherwise, they are not saved when you close the window.
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 | The per-vertex texture coordinate for the current drawable. Used to sample textures. | |
Input: Color | The per-vertex color of the current drawable. This input can be set with Color attribute in the Visuals tab. | |
Input: Velocity | The velocity vector of the current drawable (only available for particles). | |
Input: Force | The force vector of the current drawable (only available for particles). | |
Input: Life | The percentage of life left for the current drawable from 1.0 (drawable has spawned) to 0.0 (drawable is about to disappear). | |
Input: Object ID | The 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 object (emitter or sprite) 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 | Reduce 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 image 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 (AB). |
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. |
Negate | Value | Negates the boolean Value. |
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: Utililty
Node | Inputs | Description |
---|---|---|
Branch | Predicate, True, False | Outputs the value for True if Predicate evaluates to true and the value for False otherwise. |
Frame Animation | Time | Computes the frame (for example of a sprite sheet) that has been reached after time Time. The animation is characterized by the given parameters. |
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. |