Creative Coding

Getting Started With Unity Shader Graph: Writing Shaders by Connecting Nodes

Shader Graph trades HLSL syntax for a visual node network — here's how its data flow actually works, and when you still need to drop into custom code.

Writing a shader by hand means learning HLSL syntax, a compilation pipeline, and usually a fair amount of trial and error before anything renders. Unity’s Shader Graph replaces most of that with a visual node network — you wire together operations instead of writing them line by line, and see a live preview update as you go. It’s not a toy version of real shader authoring; it compiles down to the same HLSL a hand-written shader would produce, which means the node graph is a genuine substitute for code in most cases, not a simplified stand-in for it.

The two pieces: nodes and the master stack

A Shader Graph asset is built around a master stack — a set of output blocks (Base Color, Normal, Emission, and so on for a Lit graph; simpler outputs for Unlit) that the rest of the graph feeds into. Everything upstream of the master stack is a web of nodes: math operations, texture samples, UV manipulations, time-based animation, each with typed input and output ports. Connect a Sample Texture 2D node’s RGBA output into the Base Color input, and you’ve already got a working (if boring) shader.

Data types flow through connections, and that’s the whole logic

The core thing to internalize: a connection between two node ports isn’t just a wire, it’s a typed value flowing from one computation into the next. A Vector2 output won’t plug directly into a Vector3 input without an adapter node, and Shader Graph will tell you so rather than silently guessing. Once that clicks, reading someone else’s graph — or debugging your own — becomes a matter of tracing value types backward from the master stack to the inputs, the same mental model as reading dataflow in any node-based tool (TouchDesigner, Houdini’s VEX wrangles, or Blender’s shader nodes work the same way).

Sub-graphs: your own reusable nodes

Once a cluster of nodes solves a specific problem — a dissolve effect, a parallax UV offset, a custom fresnel calculation — you can collapse it into a Sub Graph, which then shows up as a single reusable node with its own named inputs and outputs. This is the node-graph equivalent of extracting a function: it keeps a complex graph legible, and it’s the difference between a shader graph that stays maintainable past a few dozen nodes and one that becomes an unreadable wall of wires.

When you still need actual code

Shader Graph covers the large majority of real-time shader work, but it isn’t a complete replacement for hand-written HLSL. The escape hatch is the Custom Function node, which lets you drop in a block of HLSL (inline or from a separate .hlsl file) and wire its inputs and outputs back into the graph like any other node. Reach for it for genuinely custom lighting models that Unity’s built-in Lit/Unlit targets don’t expose, compute-heavy per-pixel logic that’s painful to express as a chain of generic math nodes, or anything that needs direct access to render pipeline data the visual nodes don’t surface. Knowing when to drop into a Custom Function node — rather than fighting the visual graph into an unreadable mess trying to avoid it — is itself a skill worth developing early.