Shaders · Chapter 2 of 11
Shaders: The Shader Graph
Written for version 2.7.0
Find the shader graph in the Rig Editor and learn to work in it: make a graph material, add nodes, wire ports, set values and read the output.
The last chapter explained what a shader is: a recipe that every pixel runs to find its own colour. This chapter shows where that recipe lives in Kilona and how to work on it. The recipe is called a shader graph, and you edit it in the Rig Editor on iPad.
A recipe run for every pixel at once: flat colour, place and time.
Make a graph material
In the Rig Editor a material decides how a surface looks, and every material is a shader graph. The two ready-made kinds, PBR and Unlit, are graphs that have already been wired for you. A graph material is one you wire yourself.
- Open a rig. In the Selection Panel, scroll the Model group down to Materials.
- Tap + beside Materials and choose New Graph Material.
- The new material is called Graph Material and is already selected. Its panel on the right says Type: Graph, and its graph appears in a pane under the viewport.
- Give the material to a node so you can see it: select the node, find Material in its panel and choose Graph Material. The materials chapter of the Rig Editor path shows this step by step.
A new graph material begins as Color into PBR into Surface Output, but the three nodes are placed so close that they overlap. Drag each one sideways by its title before you start. The pane is also narrow while both side panels are open, so hide the Selection Panel with its button in the top bar when you work on a graph.
Materials and how to assign them to a model.
Open the graph
- The pane shows the graph of whichever material is selected. Select a PBR or Unlit material and you see its ready-made graph.
- The bar along the top of the pane carries the material's name, a + that adds a node, and two arrows that open the graph full screen.
- Full screen gives the graph the whole iPad, with the inspector down the right side. Back, at the top left, returns to the rig.
- Drag the bar between the viewport and the pane to make the pane taller or shorter.
Move around the canvas
- The dotted area is the canvas. It is far larger than the pane, and you slide and zoom it to reach your nodes.
- Two fingers always work: drag with two fingers to slide the canvas, and pinch to zoom.
- One finger on empty canvas does what the rail on the left says. Pan, the top button, slides the canvas. Select, the dashed square, drags a box round several nodes. Zoom, the magnifier, zooms as you drag.
- Drag a node by its body to move it, whichever tool is lit. With several nodes selected, dragging one moves them all.
- The canvas remembers where you left it for each material.
Add a node
A node is one step of the recipe. It takes values in on its left side, does one job, and hands the result out on its right side.
- Tap an empty part of the canvas. The Add Node card opens where you tapped.
- Open a folder, or type in the search field at the top.
- Tap a node. It lands where your first tap was and is selected.
- The + in the pane's bar opens the same card and puts the new node in the middle of the view.
| Folder | What its nodes are for |
|---|---|
| Shading | PBR, the node that turns colours and numbers into a lit surface |
| Input | Facts each pixel is given: its UV, its position, which way the surface faces, where the camera is, the clock |
| Parameters | Values you choose: Float (a number), Color, Bool (on or off) and Texture Object (a picture) |
| Material | The material's own settings and texture slots from its panel, as nodes. The ready-made PBR and Unlit graphs are built from these |
| Math | Arithmetic and shaping, in five subfolders: Common, Trigonometry, Exponential, Geometric and Derivatives |
| Logic | Questions with a yes or no answer, such as Is Greater, and Conditional, which picks one of two values |
| Blend & Compositing | Blend, which lays one colour over another with a blend mode |
| Color | Changing colour: Hue/Saturation/Value, Color Ramp, Float Curve, Invert Color and others |
| Channels | Taking a group of numbers apart and putting one together: Split Vector, Construct Vector, Swizzle |
| Coordinates | Moving, scaling, turning and bending the UV before a pattern uses it |
| Procedural | Patterns made by maths alone: Gradient, Checker, Wave and several kinds of noise |
| Texture Processing | Sample Texture and Soft Sample Texture, which read a picture at a UV |
| Halftone | Print style screens of dots and lines |
| Utility | Subgraph, Sticky Note and Discard |
At the top level the search field looks through every node. Inside a folder it only looks through that folder, and its placeholder says so. If a node does not turn up, tap All in the trail under the search field and search again.
Ports and types
The dots on the sides of a node are ports. Ports on the left are inputs, where values arrive. Ports on the right are outputs, where the result leaves. The colour of a dot tells you what kind of value passes through it.
| Type | Dot | What it carries |
|---|---|---|
| Float | Grey | One number, such as a brightness or a size |
| Vector 2 | Green | Two numbers together, most often a UV |
| Vector 3 | Yellow | Three numbers together: a colour as red, green and blue, or a direction, or a position |
| Vector 4 | Blue | Four numbers together: a colour with its opacity |
| Texture | Pink | A whole picture. It only joins another pink dot |
- A filled dot has a wire on it. A hollow input has none and uses its own value.
- Many Math nodes, such as Add and Multiply, take whatever you give them: wire in a Float and they work on one number, wire in a colour and they work on all three at once. Their dots are drawn grey whatever is passing through.
Wire and unwire
- A wire always starts at an output, on the right of a node, and ends at an input, on the left of another.
- An output can feed as many inputs as you like. An input holds one wire, and dropping a second on it replaces the first.
- To remove a wire, drag it off its input and let go over empty canvas. To move it, drag it off and drop it on another input.
- A wire takes the colour of the output it comes from.
An input accepts its own type or a Float. A Float fits anywhere, because the one number is copied into every slot: wire a Float into a colour input and you get a grey. A group of numbers will not go into an input of a different size, so a UV, which is two numbers, cannot go straight into a colour input, which wants three. The wire simply falls away when you let go.
| To get | From | Use |
|---|---|---|
| One number | A group of numbers | Split Vector, which gives X, Y, Z and W each as a Float |
| A colour | Up to three numbers | Construct Vector3, with a Float into each of X, Y and Z |
| A UV | Two numbers | Construct Vector2 |
| The same numbers in another order | A group of numbers | Swizzle 2, Swizzle 3 or Swizzle 4 |
The inspector: values and wires
- Tap a node to select it. A blue outline appears round it and the inspector, on the right of the pane, shows what can be set on it.
- Every input can get its value in one of two ways: from a wire, or from a number you set in the inspector. The inspector only lists inputs that have no wire.
- To change a number, drag up or down on it. Tap it instead to open the number editor and type.
- Some nodes also have menus in the inspector, such as Type on Gradient or Mode on Blend.
- With nothing selected, the inspector counts the nodes and connections in the graph.
If a value you set earlier has vanished from the inspector, that input now has a wire on it. Drag the wire off and the row comes back with the number it had before.
The output node
Every material graph has exactly one Surface Output. It is the end of the recipe: whatever reaches it is what you see. It has no outputs, it cannot be deleted, and it is not in the Add Node card because there is always one already.
| Input | What it means |
|---|---|
| Color | The colour of this pixel. Wire a PBR node in for a surface that reacts to light, or any other colour for a flat, unlit one |
| Opacity | How solid this pixel is, from 0, see through, to 1, solid. It only shows when the material's Alpha is set to Blend or Mask in its panel |
The PBR node is what makes a surface look real. You give it a Base Color and, if you like, Metalness, Roughness, a Normal, an Emissive glow and more, and the renderer lights the result. It must be wired straight into Surface Output's Color to do its work. The Materials chapter of this path goes through its inputs one by one.
If a graph cannot be built, for example because a Math node has been given a UV on one input and a colour on another, the inspector says so in red when no node is selected, and the model shows plain PBR until the wiring is fixed. Undo takes you back to the last graph that worked.
Graph Inputs
- You will often want to change a colour or a number later without opening the graph. Every Float, Color, Bool and Texture Object node in a graph is also listed in the material's panel, under Graph Inputs.
- Select the Float, Color, Bool or Texture Object node and type a Label in the inspector. The row in the panel takes that name. Without a Label the row is simply called Float or Color.
- The rows are listed in the order the nodes sit on the canvas, top to bottom.
- Changing a row in the panel changes the node's value in the graph. They are the same value.
Delete, duplicate and undo
- With a node selected, Duplicate and the trash appear in the pane's bar and at the foot of the tool rail.
- Deleting a node removes its wires too.
- A duplicate lands just below and to the right of the original, with the same wires coming into it.
- Undo and Redo are the two arrows in the Rig Editor's top bar. Adding a node, wiring, deleting, and one whole drag of a number each count as one step.
Subgraphs and notes
When a graph grows crowded, select a group of nodes and tap the grouping button at the foot of the tool rail: they fold into one Subgraph node, which you can name and open again with Enter Subgraph in its inspector. A subgraph has at most eight inputs and four outputs, and you can also add an empty one from the Utility folder. Sticky Note, also in Utility, is a yellow note for writing yourself a reminder on the canvas. It does nothing to the picture.
Bend a value from 0 to 1 into edges, bands, curves, waves and repeats.
Tell us which step you were on, what you tapped or dragged, and what the graph or the model did instead of what you expected.