๐จ Lesson 8.3: Intro to Shader Graph
You've been using shaders someone else wrote (the URP Lit shader). Now you'll build your own โ visually, by wiring boxes together instead of writing HLSL. Shader Graph is Unity's node editor for shaders, and once you can read its Master Stack and connect a few nodes, a huge chunk of "how did they make that effect?" stops being a mystery.
๐ฏ Learning Objectives
By the end of this lesson, you will be able to:
- Confirm Shader Graph is installed and create a URP Lit Shader Graph asset
- Read the graph's anatomy: the Master Stack (Vertex / Fragment), nodes, and edges
- Declare reusable inputs on the Blackboard and expose them to the material Inspector
- Wire a Color property โ Base Color as your first working graph
- Build a simple Time + UV driven effect (a scrolling texture) to see animation in a shader
- Assign the graph to a material and preview it live
Estimated Time: 45 minutes ยท Prerequisite: Lesson 8.1 (the URP Lit shader & what a shader does)
In This Lesson
Enabling Shader Graph
If your project was created from the URP (Universal 3D) template, the Shader Graph package is already installed โ it's a dependency of URP. To confirm, open Window โธ Package Manager, switch the dropdown to Packages: In Project, and look for Shader Graph. If it's missing, select Unity Registry and install it there.
Shader Graph produces shaders that are render-pipeline specific. In this course we always target URP, so every graph you make uses a URP target. (A graph authored for URP won't work under the Built-in pipeline, and vice versa.)
โ ๏ธ Shader Graph needs a Scriptable Render Pipeline
Shader Graph only works with URP or HDRP โ not the legacy Built-in Render Pipeline. Since you set up URP back in the Fundamentals course, you're ready. If a graph renders magenta, the graph's Active Target doesn't match your project's pipeline.
Creating a Shader Graph
Right-click in the Project window and choose Create โธ Shader Graph โธ URP โธ Lit Shader Graph (or Unlit for effects that shouldn't receive scene lighting). Name it something like SG_MyFirst. Two flavours:
- Lit โ receives scene lighting and shadows, like the standard Lit shader. Use for surfaces (walls, characters, water).
- Unlit โ ignores lighting; the colour you output is exactly what's drawn. Use for UI effects, holograms, glowing energy, and many stylized effects.
Double-click the asset to open the Shader Graph editor โ a dark canvas that fills the window. Let's learn to read it before we build.
๐ Definition
Shader Graph: a visual, node-based editor that generates shader code for you. Each node is an operation (add, multiply, sample a texture, read time); you connect their outputs to inputs, ending at the Master Stack, which is the shader's final output.
Anatomy of the Editor
Here is the Shader Graph editor rebuilt faithfully โ the exact graph we'll build in this lesson: a Color property feeding Base Color, and a scrolling texture (Time + UV โ Tiling And Offset โ Sample Texture 2D) feeding both Base Color and Emission.
๐ก Read a graph like a river. Data flows left to right, always ending at the Master Stack. Any node not connected (directly or through a chain) to the stack does nothing to the final shader. When a graph confuses you, start at Base Color and trace the wires backward.
Your First Graph: Color โ Base Color
The simplest useful graph is one node's worth of work: output a solid colour. Here's the whole thing:
- Open your
SG_MyFirstLit graph. - Right-click the canvas โธ Create Node, search Color, and add a Color node. Click its swatch and pick a colour.
- Drag from the Color node's output port to the Base Color input on the Fragment block of the Master Stack.
- Click Save Asset (top-left).
That's a complete, valid shader. Assign it to a material and the material is that colour, lit by your scene. Trivial โ but it proves the core loop: a node's output connected to the Master Stack becomes the shader's result.
Conceptually, the data path of the full lesson graph looks like this:
Figure 2: The same graph as a flow โ properties and nodes converging on the Master Stack's Base Color and Emission.
The Blackboard & Properties
Hard-coding a colour inside the graph is fine for one object. But you usually want the colour adjustable per material, in the Inspector, without reopening the graph. That's what the Blackboard is for.
Click + on the Blackboard and add a Color property; rename it BaseTint. Now:
- Drag it onto the canvas to get a property node you can wire up (the pink-capped boxes in Figure 1).
- Because it's a property (not a constant), it shows up as an editable field on every material that uses this graph.
Common property types: Color, Float (a slider or number), Vector2/3/4, Texture2D, and Boolean. In Figure 1 the Blackboard holds BaseTint (Color), MainTex (Texture2D), and ScrollSpeed (Vector2) โ everything the material's user can tweak.
๐ Definition
Property (exposed): a named input declared on the Blackboard that becomes a field in the material Inspector. It lets one shader graph power many materials, each with different colours, textures, and numbers โ exactly like the Base Map and Smoothness fields on the built-in Lit shader.
โ Pro Tip
Give properties a clear Reference name (in the Graph Inspector, e.g. _BaseTint). That reference is how you'd set the value from C# with material.SetColor("_BaseTint", Color.red) โ which is exactly how the next lesson animates a dissolve.
A Time + UV Effect
Static colour is boring. The magic of shaders is that they can move without any C#. Two nodes unlock that:
- Time โ outputs the seconds elapsed, ever-increasing. Feed it into anything and that thing animates.
- UV โ outputs each pixel's texture coordinates (0โ1 across the surface). It's how a shader knows where on the surface it is.
To scroll a texture, you offset its UVs over time:
- Add a Time node and a ScrollSpeed Vector2 property; Multiply them so the offset grows each second.
- Add a UV node and a Tiling And Offset node. Feed UV into its UV input and the TimeรSpeed result into its Offset input.
- Feed Tiling And Offset's output into the UV input of a Sample Texture 2D node (with
MainTexin its Texture slot). - Wire the sampled colour into Base Color (multiplied by
BaseTint) and also into Emission for a glow.
Save, and the texture on your material now scrolls โ an animated shader, and you never touched a script. This exact pattern (UV + time) powers scrolling force-fields, flowing lava, waterfalls, and conveyor belts.
โ ๏ธ Nothing moves in the Scene view
The Time node advances in Play mode and in the graph's live preview, but the Scene view may look frozen when not playing. Press Play (or watch the small preview on the Sample node) to see the animation. Also make sure your texture's Wrap Mode is Repeat, or scrolling will smear the edge pixel.
Assigning to a Material
A Shader Graph asset is a shader, not a material โ you still need a material to use it. Two ways:
- Right-click the graph asset โธ Create โธ Material โ makes a material already pointing at this shader.
- Or create a material normally, then in its Inspector set Shader โธ Shader Graphs โธ SG_MyFirst.
Now the material's Inspector shows BaseTint, MainTex, and ScrollSpeed โ the very properties you put on the Blackboard. Drop a texture into MainTex, pick a tint, and drag ScrollSpeed. Assign the material to any renderer and your custom shader is live in the scene.
๐ก One graph, many looks: because the tweakable bits are properties, you can make a dozen materials from this single graph โ a slow blue force-field, a fast red one, a scrolling green toxic sludge โ without editing the graph again.
Hands-on Challenge
๐๏ธ Exercise 1: A tintable, scrolling material
Objective: reproduce the graph in Figure 1 end to end.
- Create a URP โธ Lit Shader Graph named
SG_Scroll. - Add Blackboard properties:
BaseTint(Color),MainTex(Texture2D),ScrollSpeed(Vector2). - Wire Time ร ScrollSpeed into the Offset of a Tiling And Offset node fed by a UV node.
- Sample
MainTexwith that scrolled UV; multiply the result byBaseTint; connect to Base Color. - Also connect the sampled colour to Emission. Save, make a material, drop in a repeating texture, and press Play.
๐ก Hint: the texture doesn't scroll
Confirm the Time output goes through the Multiply into the Offset input (not Tiling), the texture's Wrap Mode is Repeat, and you're in Play mode (or watching the node preview). If it scrolls impossibly fast, lower ScrollSpeed to something like (0.1, 0).
โ Success check
Two materials made from the one graph look different (different tint + speed), and the texture visibly scrolls across the surface in Play mode with a faint glow from the Emission wire.
๐๏ธ Exercise 2: Prove it's a real property
Give BaseTint a Reference name of _BaseTint. Write a one-line test script that calls GetComponent<Renderer>().material.SetColor("_BaseTint", Color.cyan) in Start(), and confirm the object turns cyan at runtime. This is the bridge from Shader Graph to C# you'll lean on in Lesson 8.4.
๐ฏ Quick Quiz
Question 1: Where does every Shader Graph's data flow ultimately end?
Question 2: You want a colour that's editable per-material in the Inspector, not baked into the graph. What do you use?
Question 3: Which pair of nodes is the classic recipe for making a texture scroll over time?
Summary
๐ Key Takeaways
- Shader Graph ships with URP; create graphs via Create โธ Shader Graph โธ URP โธ Lit/Unlit.
- Data flows left to right through nodes and always ends at the Master Stack (Vertex + Fragment).
- The Fragment context's Base Color, Emission, Metallic, Smoothness, and Alpha are the outputs you'll wire most.
- The Blackboard holds properties that appear in the material Inspector โ one graph, many materials.
- Time + UV let a shader animate (e.g. a scrolling texture) with no C# at all.
- A graph is a shader; make a material from it to actually use it in the scene.
๐ What's Next?
You can now read a graph, expose properties, and animate with Time. In Lesson 8.4: Building a Dissolve Shader you'll put it all together into a real effect โ noise + a threshold that clips pixels away, plus a glowing edge โ and drive it from a script so an object disintegrates on cue.
๐จ You can build a shader now
Nodes in, wires across, Master Stack out. Every jaw-dropping effect you'll ever see is that same river of data โ just with more interesting nodes in the middle.