Opening the Shader Graph editor
Create a Shader Graph asset
Open the Asset Browser, right-click, and select Create > Shader Graph. Give the asset a name and save it.
Editor layout
The editor is divided into four panels:| Panel | Purpose |
|---|---|
| Preview | Shows a real-time preview of your shader output. Change the preview model and lighting to suit your shader. |
| Properties | Inspect and edit properties of the shader or any selected node. |
| Graph | The node canvas. All graphs end with a Material node where your output values connect. |
| Output | Displays errors and warnings. Also contains tabs for the Console, Undo History, and Node Palette. |
Creating nodes
Right-click anywhere in the Graph canvas to open the node creation menu, or drag nodes from the Palette tab in the Output panel directly onto the canvas.Input and output types
Each node pin is colour-coded by type:| Colour | Type | Example uses |
|---|---|---|
| Green | Float | A single floating-point value |
| Purple | Float2 | UV coordinates, screen position |
| Blue | Float3 | Positions, normals, RGB colour |
| Yellow | Float4 / Color | RGBA, positions with W component |
Float when given two Float inputs, but returns a Float4 when a Color is connected.
Turning a Shader Graph into a material
When you save your Shader Graph, s&box compiles it and places a.shader file alongside it. You can use that shader file when creating a Material in the Asset Browser.
To create a material directly from the graph, right-click the compiled shader asset and select Create Material.
Custom nodes
You have two ways to extend the node library with your own reusable nodes.Subgraphs
Package a group of existing nodes into a single reusable node. Good for encapsulating logic you repeat across shaders.
C# Shader Nodes
Write a
ShaderNode subclass in C# to define fully custom inputs, outputs, and generated HLSL.Creating a subgraph
A Subgraph (Shader Graph Function) is a collection of nodes saved as a standalone asset that other graphs can use as a single node.Create the asset
In the Asset Browser, right-click and select Create > Shader > Shader Graph Function.
true to force the caller to connect a node rather than use the default value.
Creating a C# shader node
Custom nodes inherit fromShaderNode and support [Title], [Description], [Category], and [Icon] attributes.
NodeInput properties with the [Input] attribute. Use [InputDefault] to expose a default value in the Properties panel.
NodeResult.Func properties with the [Output] attribute. Use the GraphCompiler to resolve connected inputs and emit HLSL.
Inputs and Outputs to return lists you build at runtime, for example when the number of pins depends on a property the user configures.
IErroringNode to return a list of error strings that prevent the graph from compiling until the user fixes them.
OnPaint to draw custom visuals on the node face, similar to built-in Binary and Texture nodes.