Documentation

Unity Spark

Open Unity Spark

Unity Spark

Create a Shader Graph material

Create a shader graph, add and connect nodes, add properties, apply the graph, and use it in a material in the Unity Spark Shader Graph window.
Read time 3 minutesLast updated 3 hours ago

Create a shader graph when a material with a ready-made shader can't create the effect you want. For how shader graphs become materials, refer to Create a custom shader with a shader graph.
To have the AI assistant create the graph for you, describe the effect you want in the Chat window, for example,
Give the shield a pulsing glow.

Create a shader graph

To create a shader graph, do one of the following:
  • In the Project window, select Create (+) > Shader Graph.
  • In the Shader Graph window, enter a name in New graph name, and select Create.
A new graph is an Unlit graph. To change it to a lit surface, set Kind to Lit in the side panel.

Open an existing shader graph

To open a shader graph, do one of the following:
  • Double-click the shader graph in the Project window.
  • Select Open graph… in the Shader Graph window.

Add and connect nodes

To add and connect nodes:
  1. Right-click the canvas, or press Space, to open the node search.
  2. Enter part of a node's name, then select the node or press Enter.
  3. To connect two nodes, drag from an output port of one node to an input port of another. A port is a connection point on a node. The wire carries the first node's result into the second node.
  4. Connect your result to the inputs of the Master node, which sets the final appearance of the surface. For example, connect to
    baseColor
    for the surface color, or to
    alpha
    for how transparent it is.
Node names and Master node inputs use their internal names, such as
sampleTexture2D
or
baseColor
. To remove a wire, select the connected input port.

Remove a node

To remove a node:
  1. On the canvas, select the node.
  2. On your keyboard, press the Delete or Backspace key.
You can't remove the Master node.

Add properties

Properties let each material that uses the graph set its own values, such as a color or a speed.
To add a property:
  1. In the Properties section of the side panel, select a property type, such as Float or Color. For a description of each type, refer to Property types.
  2. Optional: Enter a name.
  3. Select Add property (+) or press Enter.
Float, Vector, Color, and Texture 2D properties appear as fields on the materials that use the graph.

Apply the graph

Select Apply to save the graph and turn it into a shader that the graphics card can run. Apply is unavailable while the graph has errors. Errors mark the nodes that caused them, and the line under the toolbar shows the first error.
Every material that already uses the graph updates when you apply it.

Use the graph in a material

To draw an object with the graph:
  1. Create a material, or select an editable one. Refer to Create and apply materials.
  2. In the Inspector window, set Shader to your graph.
  3. Set the values of the graph's properties.
  4. Assign the material to the object.
Only Lit and Unlit graphs appear in the Shader list.

Write custom code

To add your own code to a graph:
  1. Add a customFunction node.
  2. Double-click the node.
  3. In the panel that opens under the canvas, write one function in WebGPU Shading Language (WGSL).
For more information, refer to Custom Function panel.

Recover from a rejected shader

A graph can apply without errors, but the graphics card in your computer might still refuse to run the shader. The toolbar then displays Rejected by the GPU, and objects that use the shader don't draw.
If the graphics card rejects the shader, do one of the following:
  • Select Retry to build the shader again.
  • Select Turn off to stop the shader until you retry or reload.
To fix the shader:
  1. Change the graph.
  2. Apply the graph again.

Additional resources