Shaders · Chapter 9 of 11

Shaders: Materials in Depth

Written for version 2.7.0

Take a graph from a flat square to a lit surface: every input of the PBR node, textures, the world and the camera, transparency, and Graph Inputs.

The last chapter set a graph moving with the clock. So far almost every result has been a flat square that shows exactly the colour the graph makes. This chapter wraps that result round a model and lets the app light it, then goes through everything a material's graph can use: every input of the PBR node, textures, the material's own panel, the camera and the world, and transparency.

It builds on the Materials chapter of the Rig Editor path, which shows where materials live and how to give one to a model. If the Materials list and the material's panel are new to you, read that first.

From a square to a surface

A material is a graph that is worn by a model. The model's surface is cut into pixels on your screen, and the graph runs once for each of them, exactly as it did for the square. Two things are new. The pattern is now stretched over a shape, using the model's UVs. And the app can light the result, if you ask it to.

You ask with one node: PBR, the only node in the Shading folder. PBR stands for physically based rendering, a way of describing a surface by what it is made of. Without it, the colour that reaches Surface Output is the colour on screen, the same in any light. That is called unlit. With it, the colour is only one fact about the surface, and the app works out the bright side, the dark side and the highlight.

The same graph on a flat square and on a ball. Wired straight into Surface Output the ball is a flat disc. Through PBR the pattern becomes the surface's Base Color and the app lights it. Lower Roughness tightens the highlight.
  • Every material is a graph. A PBR material and an Unlit material are ready-made graphs, and New Graph Material starts you with three nodes: Color into PBR into Surface Output.
  • PBR does not make a colour for you to carry on working with. It hands the app a description: this colour, this rough, this metallic. The lighting happens after the graph has finished.
  • The result pictures on this page are lit by a simple stand-in: one light and a soft sky. The app's own lighting is richer, so use them to compare one setting with another, not as a preview of your scene.
PBR goes last

A surface is lit only when PBR's Color is wired straight into Surface Output's Color. Put any node in between, even a Multiply, and the app no longer sees a PBR node at the end. The surface turns unlit and shows only the Base Color. Do your colour work before PBR, never after it.

The Lighting menu

The material's panel has a Lighting menu with PBR and Unlit. On a ready-made material it swaps one ready-made graph for the other, and Unlit hides the rows that only a lit surface uses. On a graph you have built yourself, what decides is the graph: a PBR node wired into Color is lit, anything else is unlit.

The PBR node, input by input

PBR has fourteen inputs. Four of them do most of the work, and you can leave the rest alone until you need them. Each has a value of its own when nothing is wired in, shown in the inspector when you tap the node.

Base Color

The colour of the surface itself, before any light: the paint, the plastic, the metal. A new PBR node holds a light grey. Everything from the Colour, Patterns and Noise chapters can be wired in here. Keep it honest: shadows and highlights are the lighting's job, so a Base Color with shading painted into it looks wrong as soon as the light moves.

Metalness and Roughness

Metalness says whether the surface is a metal. At 0 it is not: light scatters inside it and comes back out in the Base Color, with a small colourless reflection on top. At 1 it is bare metal: there is no scattered colour at all, and the Base Color tints the reflections instead. Values in between are for the edge where one meets the other, such as paint wearing off steel.

Roughness says how smooth the surface is. At 0 it is a mirror, with a small sharp highlight. At 1 it is chalk, with the highlight spread so wide it almost vanishes. A new PBR node starts at 0.5.

Ten balls with one Base Color. Along each row Roughness climbs from 0 to 1 and the highlight spreads and fades. The top row is Metalness 0, the bottom row Metalness 1: bare metal, where the colour lives in the reflections.
Metal is 0 or 1

Real surfaces are almost always fully metal or not metal at all. Use 0 and 1 for whole surfaces, and the values in between only where a mask blends from one material to another.

Emissive and Emissive Strength

Emissive is light the surface gives off by itself, like a screen, a lamp or hot metal. It is a colour, and it is added on top of the lighting, so it shows on the dark side of a model too. Emissive Strength multiplies it. At 0 the glow is off, at 1 the surface gives off the colour as it is, and above 1 it is brighter still.

A dark ball with an orange Color wired into Emissive: the glow is added to the lighting, so the shaded side shows it too. Emissive Strength multiplies it, from barely there to brighter than the colour itself.

Black gives off nothing, so a pattern wired into Emissive glows only where it is bright. That is how glowing lines, lit windows and lava cracks are made. In the regular viewport a glowing surface is bright but does not light the things around it.

The other inputs

The remaining inputs are described here in words. The pictures on this page come from a simple lighting stand-in that does not work them out, and a drawn guess would not be honest. In the app, all of them are live.

InputWhat it is forWith nothing wired
NormalThe direction the surface faces at each point. Wire a Normal Map or Bump node in to fake small dents and grooves without changing the meshThe mesh's own direction
OcclusionDarkens the soft light in creases, where less light reaches. 1 is no darkening, 0 is full1
SpecularHow strongly a surface that is not a metal reflects. Rarely needs changing. Lower it for dry, dusty things0.5
SheenA soft glow at the edges of the shape, as on velvet and cloth. 0 is off0
Sheen TintThe colour of that glowWhite
Sheen RoughnessHow wide the glow spreads0.3
SubsurfaceLight that soaks into the surface and comes out nearby, as in skin, wax, milk and leaves. 0 is off0
Subsurface ColorThe colour the soaked light takes onA warm red
Subsurface RadiusHow far the light travels inside, set separately for red, green and blueRed further than green and blue

Patterns into the inputs

Every input of PBR takes a wire, not only Base Color. This is where the earlier chapters pay off: a pattern does not have to be a colour. It can be how rough the surface is.

Bare metal with a single Roughness looks factory new. Noise, squeezed into a sensible range by Scale And Offset and wired into Roughness, leaves some patches polished and others dull, like metal that has been handled.
  • Roughness and Metalness want a single number from 0 to 1. Noise, Voronoi Noise, Wave and anything shaped with Smoothstep fit directly.
  • Scale And Offset is the quickest way to fit a pattern into a narrower range, such as 0.1 to 0.8, so no part of the surface becomes a perfect mirror or pure chalk.
  • A grey output can go into a colour input, but a colour cannot go into a single number. To drive Roughness from a colour, put Luminance, from the Color folder, in between.

One mask, two whole surfaces

A real object is often two materials: paint and the metal under it, rust and steel, moss and stone. Build each one as a set of values, then let a mask choose between them with Mix (Lerp). You need one Mix for each input that differs.

A Checker is the mask. Three Mix (Lerp) nodes read it as T: one for colour, one for Metalness, one for Roughness. Each wire adds part of the difference, until polished gold sits beside dull red rubber.
  • The mask goes into T on every Mix. A is the look where the mask is 0 and B the look where it is 1.
  • For the colour Mix, wire a Color node into A and another into B. For Metalness and Roughness, type the two numbers into A and B.
  • Swap the Checker for a Noise through Smoothstep and the hard squares become worn patches. The Recipes chapter builds that.
Typing a number into a Math node

A number typed into A or B of a Math node sets only its first lane. For one number that is all there is. When the node is working on a colour, a typed 0.5 changes only the red. To scale a whole colour, wire a Float node in: a Float wire fills every lane.

Textures

A texture is a picture the model carries. In a graph it takes two nodes. Texture Object, in the Parameters folder, holds the picture: tap it and choose one of the model's textures from its Texture menu. Sample Texture, in the Texture Processing folder, reads that picture at a place and gives the Color and Opacity it finds there.

Texture Object holds a picture and has a pink Texture output. Sample Texture reads it at its UV: with no wire, the model's own UVs. A Coordinates node wired into UV tiles, slides or turns the picture. No picture is drawn here.
  • One Texture Object can feed several Sample Texture nodes, each reading it at a different place or scale.
  • A Sample Texture with nothing wired into Texture gives plain white.
  • Soft Sample Texture is the same node with a Radius: it reads a small blurred patch around the place. Radius is in the units of the UV square, so 0.01 is a hundredth of the picture.
  • Past the edges of the picture, Sample Texture and Soft Sample Texture follow the texture's own Wrap X and Wrap Y, and they read it with its Filter. All three are on the texture's panel in the Rig Editor. A new texture starts on Repeat, so a scaled UV tiles it. On Clamp to Edge the edge pixels stretch outwards instead.
  • A graph can hold up to 8 Texture Object nodes. One more and the graph fails to compile, and the inspector says so.
  • A Texture Object is listed under Graph Inputs, so the picture can be swapped from the material's panel.

The Material folder

The standard material panel has a Base Color, a Roughness, a Metalness, an Emissive colour, and five texture slots. The nodes in the Material folder give those to the graph. Material Base Color is whatever the panel's Base Color is now. Material Base Color Map is whatever picture sits in the Base Color slot.

This is why a ready-made PBR material is still a graph: its graph is these nodes, multiplied together in pairs and wired into PBR. It is also why they are worth using in your own graphs. A graph built on them keeps answering to the panel, so you, or anyone you hand the model to, can recolour it without opening the graph.

Material Base Color and Material Roughness read the material's own panel. Here the panel colour is multiplied by stripes made in the graph. Change the colour or the Roughness in the panel and the ball follows, though the graph was not touched.
NodeGives
Material Base ColorThe panel's Base Color, as RGB and Alpha
Material Base Color MapThe picture in the Base Color slot, as RGB and Alpha. White when the slot is empty
Material Roughness, Material MetalnessThe panel's two numbers
Material MR MapRoughness and Metalness read from the Metallic Roughness slot
Material Emissive, Material Emissive MapThe panel's Emissive colour, and the picture in the Emissive slot
Material Normal MapThe Normal slot, already turned into a direction for PBR's Normal
Material Normal ScaleThe panel's Normal Scale number
Material OcclusionThe Occlusion slot, weighted by the panel's Occlusion number

Surface detail: Normal Map and Bump

PBR's Normal input changes which way the surface seems to face, point by point, so light catches dents and ridges that are not in the mesh. Two nodes in the Input folder make a value for it.

  • Normal Map takes the colour of a normal map picture, usually from a Sample Texture, and a Strength, and gives a Normal. A normal map is a picture, mostly pale blue, in which the colour is a direction.
  • Bump takes a height: a picture wired into Height Tex, or any pattern from the graph wired into Height. Bright is high, dark is low. Strength and Distance set how deep the detail looks.
  • Wire the Normal output of either into Normal on PBR. Bump has a Normal input of its own, so a Normal Map can be wired into it to stack two layers of detail.
They change the light, not the shape

Normal Map and Bump only change how the surface is lit. The outline of the model stays smooth, and from a low angle the trick shows. For detail you can see on the outline, the mesh itself has to change.

The world and the camera

UV Coord tells a graph where a point is on the model's unwrapped surface. The Input folder has other answers to the question of where, and they do not depend on UVs at all.

World Position and World Normal

World Position is the place of the point in the scene, as three numbers: X across, Y up, Z toward you. World Normal is the direction the surface faces there, also as three numbers. Split Vector, from the Channels folder, takes one of the three out.

Split Vector takes the Y, the up and down part. From World Position, everything above a height turns white, whatever the UVs. From World Normal, only what faces up turns white: on the box, just the top face. Snow, dust and moss work like this.
  • A pattern driven by World Position stays put in the scene. Move the model and it slides through the pattern, like walking through a beam of light.
  • The Procedural nodes take a pair of numbers for UV, and World Position has three. Put Swizzle 2, from Channels, in between to pick two of them, such as X and Y.
  • Because it ignores UVs, a World Position pattern has no seams and works on a mesh that has never been unwrapped.

Edge glow: Rim / Fresnel and Camera Facing Ratio

Some effects depend on where you are looking from. Rim / Fresnel is 0 where the surface faces the camera and rises to 1 where it turns away, at the outline of the shape. Its Power input tightens it. Camera Facing Ratio is the plain version the other way up: 1 facing the camera, 0 at the outline.

Rim / Fresnel times a colour, wired into Emissive, rings the ball with light. A high Power gives a thin line at the very edge. A low Power spreads the glow across the surface.
  • Rim into Emissive is a glow. Rim into the T of a Mix changes the colour at the edges, for velvet, soap bubbles and force fields.
  • Rim into Opacity makes a shape that is solid at its outline and clear in the middle. The Recipes chapter uses it for a hologram.
  • View Vector is the raw direction from the point to the camera, and Reflection Vector the direction a mirror there would show. Camera Position and Camera Axes give the camera itself.

Screen UV

Screen UV is the place of the pixel on the screen, 0 to 1 across and down, whatever the model is doing. A pattern driven by it looks printed on the glass: the model moves and the pattern stays still behind its outline. Its second output, Size, is the size of the picture in pixels.

Transparency

Surface Output has a second input, Opacity: how solid each point is, from 0, not there, to 1, solid. Wiring something into it is only half the job. The material's panel has an Alpha menu that decides what Opacity means, and it starts on Opaque, which ignores it.

Noise is wired into Opacity. With Alpha on Opaque nothing changes. Mask cuts away every point whose Opacity is below Cutoff, with a hard edge. Blend fades the surface by its Opacity instead.
AlphaWhat Opacity doesUse it for
OpaqueNothing. The surface is solidAlmost everything
MaskCuts the surface away where Opacity is below Cutoff. The rest is fully solidLeaves, fences, torn cloth, dissolves
BlendFades the surface: 0.5 is half see-throughGlass, smoke, ghosts, holograms
  • Cutoff appears in the panel when Alpha is Mask. It starts at 0.5 and runs from 0 to 1.
  • Double Sided, just above Alpha in the panel, draws the back of every face as well as the front. Turn it on for anything cut open, or you will see straight through the far side.
  • Is Front Facing, in the Input folder, is 1 on the front of a face and 0 on the back. With Double Sided on, it lets the inside have its own colour.
  • Mask keeps solid surfaces sorting correctly behind and in front of each other. Blend can show surfaces in the wrong order where see-through things overlap. Prefer Mask when a hard edge will do.

Discard

Discard, in the Utility folder, throws a pixel away from inside the graph. It has a Value, which passes straight through to its Out, and a Condition. Where Condition is above 0.5 the pixel is not drawn at all, whatever Alpha is set to. Put it on the way to Surface Output's Color, or before PBR's Base Color, and feed Condition from a Step or a node in the Logic folder.

Cutting that works in both engines

Discard only works in the Physically Based engine. The Ray Traced engine ignores it. Opacity with Alpha set to Mask cuts in both, so use that unless you have a reason not to.

Graph Inputs: a material you can adjust

A finished graph is a machine with its decisions buried inside it. Graph Inputs brings the decisions you choose back to the surface. Every Float, Color, Bool and Texture Object node in the graph is listed at the foot of the material's panel, named by the Label you type in the node's inspector.

A Color labelled Paint, a Float labelled Roughness, a Float labelled Glow and its colour appear under Graph Inputs. The number and the colour are changed right there in the panel, with the graph left alone.
  • Decide what should be adjustable, and make each of those a Float, Color or Bool node with a clear Label. Leave everything else typed into the nodes.
  • The rows follow the nodes on the canvas from top to bottom, so arrange the nodes in the order you want the rows.
  • A Bool is a switch: 0 or 1. Wire it into the Condition of a Conditional node, in the Logic folder, to choose between two values.
  • A Graph Input can also be driven from outside the graph: a Value Driver constraint can target one, so something else in the rig moves it.

How the two engines treat a graph

The Rig Editor has two engines, Physically Based and Ray Traced. Both use the same graph, and the app prepares it once for each. Nearly everything behaves the same. These are the differences.

NodeIn the Ray Traced engine
Delta TimeAlways 0. Elapsed Time works as usual
DDX, DDY, FWidthGive 0
DiscardPasses its Value through and cuts nothing
Is Front FacingAlways 1
Faceted NormalUses the true direction of each triangle
Material OcclusionGives 1. Ray tracing works out that shading for itself
BumpWorks from a picture in Height Tex. A pattern wired into Height is ignored and the surface stays smooth
Sample TextureReads the picture at full sharpness at any distance
  • Screen UV is worked out so that a ray traced render lines up with the regular viewport.
  • A graph that is unlit stays unlit when ray traced: it shows its colour and takes no light.
  • If a graph fails to compile, the model shows plain PBR until it is fixed, and the inspector says what went wrong.

When it does not look right

What you seeWhat to check
Flat colour, no shadingPBR's Color must go straight into Surface Output's Color, with nothing in between
Opacity does nothingThe material's Alpha is Opaque. Set it to Mask or Blend
You can see through the far sideTurn on Double Sided
Only the red changesA number typed into a Math node sets one lane. Wire a Float in
A wire will not landA colour cannot go into a single number. Use Luminance or Split Vector first
The panel's colour does nothingThe graph does not read it. Use Material Base Color, or change the Color node under Graph Inputs
Black where a glow should beEmissive Strength is 0, or the Emissive colour is black there

Now you try

  1. Brushed steel. Start a graph material. Type a pale grey into PBR's Base Color and set Metalness to 1. Add a Wave, from Procedural, set its Scale to 40, follow it with Scale And Offset at Scale 0.3 and Offset 0.3, and wire that into Roughness.
  2. Snow on top. Wire World Normal into Split Vector, its Y into a Color Ramp, and the ramp into Base Color. Give the ramp a rock colour at 0.3 and white at 0.5.
  3. A cut-out pattern. Wire a Checker into Surface Output's Opacity, set Alpha to Mask in the panel, and turn on Double Sided.
  4. Make it adjustable. In any of the three, replace one typed number with a Float node, give it a Label, and change it from Graph Inputs.
Something unclear?

Tell us which input or picture confused you, what you wired, and what the model showed instead of what you expected.

Send Feedback