Shaders · Chapter 7 of 11
Shaders: Random, Noise and Cells
Written for version 2.7.0
Why perfect maths looks artificial, and how controlled randomness fixes it: static, smooth noise, layers of detail, cells, and noise used as colour, mask and wobble.
The last chapter repeated and tiled shapes into patterns, and every one of them came out perfect: each tile a copy of the one beside it. This chapter is about breaking that perfection on purpose. You will meet the four nodes that make randomness, learn the dials that control it, and use it to make clouds, stone, islands, cells and cracks.
Repeat, tile and turn a shape into a pattern.
Why perfect looks fake
Nothing in the real world is perfectly even. A painted wall has patches, a brick is not quite the colour of the next brick, and a cloud has no straight edge anywhere. Maths has no such flaws. A gradient is exactly smooth and a stripe is exactly straight, and the eye spots that at once and reads it as artificial. The cure is noise: numbers that look like chance but are fully under your control. You decide how big the lumps are, how rough they are and where they sit. Mix a little noise into a colour, an edge or a position, and the picture starts to look as if it was made by weather and wear, not by a ruler.
Random Noise: every cell for itself
Start with the rawest kind. Random Noise, in the Procedural folder, cuts the square into a grid of cells and gives each cell one value between 0 and 1. The values have nothing to do with each other: a cell that is nearly white can sit beside one that is nearly black.
- Scale is the number of cells across the square, and the same number up. A small Scale gives big blocks. A large Scale gives fine grain.
- Seed changes which value each cell gets. Use it when you like the grain but not the particular pattern, or when two Random Noise nodes must not match.
- The plot shows why this kind of noise looks harsh: the line jumps from one flat step to the next, with nothing in between.
A shader cannot roll dice. Random Noise works its value out from the cell's position and the Seed, so the same cell with the same Seed gives the same value every time. That is what you want: the pattern holds still and does not flicker. It changes only when you change Scale, Seed or the coordinates going in.
Noise: neighbours agree
Static is rarely what a surface needs. The Noise node, also in Procedural, makes randomness with manners. It still places random values on a grid, but it blends smoothly from each one to the next, so every spot ends up close to the spots around it.
- Read Scale as zoom. It is roughly how many lumps fit across the square.
- Compare the two plots. Random Noise is a staircase. Noise is hills. That smoothness is the whole difference, and it is why Noise can pass for cloud, stain or stone.
- This picture has Detail (Octaves) set to 1, so you see one plain layer. The next section turns it up.
Noise gives values between 0 and 1, but it seldom gets close to either end. Most of the square sits between about 0.3 and 0.7, which is why raw noise looks like grey fog. To get real darks and lights, stretch it: send it through Smoothstep with Edge 0 at 0.3 and Edge 1 at 0.7, or through a Color Ramp whose stops sit in that middle stretch.
Layers of detail
One layer of noise is too soft to be a cloud. Real things are lumpy at every size at once: a mountain has ridges, the ridges have rocks, the rocks have grit. Noise copies that by stacking layers. The first layer is the big lumps. Then comes the same noise again, smaller and fainter, added on top. Then again, smaller and fainter still. Each of these layers is called an octave, and the whole stack has a name you will meet elsewhere: fractal noise, or fBm.
Detail (Octaves) counts whole layers, from 1 up to 8. A setting of 2.7 gives two layers, not two and a bit. A new Noise node starts at 2.
| Input | What it does | A new node starts at |
|---|---|---|
| Scale | Zoom. How many of the biggest lumps fit across the square | 5 |
| Detail (Octaves) | How many layers are stacked, 1 to 8 | 2 |
| Roughness | How strong each layer is next to the one before. At 0.5 each is half as strong. Higher is grittier, lower is smoother | 0.5 |
| Lacunarity | How much finer each layer is than the one before. At 2 each has lumps half the size | 2 |
| Distortion | Pushes the whole pattern sideways by a noise of its own before the layers are added. 0 leaves it alone | 0 |
Every layer is the noise worked out again for every pixel. Past 4 or 5 layers the extra ones are too fine to see at most sizes, so they cost time and show nothing. Raise Detail until the look stops changing, then stop.
Using noise: colour
Grey fog is raw material. The quickest way to turn it into something is the Color Ramp from the colour chapter: wire Noise's Out into Fac and choose stops. Because noise sits in the middle of its range, keep the stops in the middle too, and move them closer together for harder edges.
| Look | Stops, from low to high |
|---|---|
| Clouds | Sky blue at 0.42, white at 0.6 |
| Marble | Pale stone at 0.44, near black at 0.5, pale stone again at 0.56. The thin dark stop is the vein |
| Rust | Steel grey at 0.4, orange brown at 0.5, dark brown at 0.62 |
| Lava | Black at 0.38, deep red at 0.48, orange at 0.56, pale yellow at 0.64 |
Using noise: edges and masks
Chapter 3 cut a gradient in two with Step and Smoothstep. Cut noise the same way and the cut is no longer a straight line. It is a coastline. Everything above the level is 1, everything below is 0, and the shape between them is as ragged as the noise. A picture made only of 0 and 1 is called a mask. A mask says where, and Mix (Lerp) does the rest: wire the mask into T, and you get A where the mask is 0 and B where it is 1.
- Use Step for a hard cut: type the level into A and wire the noise into B. Use Smoothstep, as here, when the edge will be seen. The noise goes into Value.
- The level decides how much of the square is covered. Near 0.5 it is about half and half. Lower it for more of B, raise it for more of A.
- A and B can be anything, not only colours: two patterns, a rough number and a smooth one, a glow and no glow. A noise mask is how one material gets patches of another, such as rust on paint or moss on stone.
- For splotches with holes in them, add a second Noise at a different Scale and multiply the two masks together.
Bending other things with noise
So far noise has been the picture. It can also disturb a picture you already have. Every Procedural node reads coordinates through its UV input, and normally those run straight across the square. Add a little noise to the coordinates before they go in, and each spot reads the pattern from somewhere slightly off. Straight lines turn wobbly. The name for this is domain warping, which only means bending the space a pattern is drawn in.
- UV Coord's UV0 is a Vector 2 and Noise's Out is a Float. Add accepts both, and the Float fills both lanes, so the same push is added to U and to V.
- Multiply sets the strength. With B at 0 nothing moves. Around 0.1 gives a gentle wobble. Past 0.4 the pattern tears into swirls.
- The same wiring bends anything with a UV input: Checker, Gradient, Voronoi Noise, even another Noise.
- Wave and Noise each have a Distortion input of their own that does a similar job in one number. Build it by hand when you want to choose the noise that does the bending.
Coordinates run from 0 to 1 across the whole square, so a push of 1 throws a spot clear across it. Useful strengths are small numbers, often below 0.2. If the pattern turns to mush, the Multiply is too high.
Voronoi Noise: cells
Voronoi Noise makes a different kind of randomness. It scatters points across the square, one to each cell of a grid, and for every pixel it measures how far away the points are. The result is a field of cells, like scales, pebbles or dried mud. Its Feature setting, in the inspector, chooses which distance you get.
| Feature | What the value is | Looks like |
|---|---|---|
| F1 | The distance to the nearest point | A dark dot at every point, brightening to a sharp crease where two cells meet |
| Smooth F1 | The same, with the creases melted. Smoothness sets how much | Soft dark blobs that run into each other |
| F2 | The distance to the second nearest point | Broader, more angular cells, bright almost everywhere |
- Scale is how many cells fit across the square.
- Randomness is how far each point may stray from the middle of its grid cell. At 1 the cells are irregular. At 0 every point sits dead centre and the cells become a perfect grid of squares.
- Smoothness only matters when Feature is Smooth F1.
Cell borders
The node has one output, so to draw the lines between cells you use two of them. On the border between two cells, the nearest point and the second nearest point are exactly as far away as each other. So F2 minus F1 is 0 on every border and grows as you move into a cell.
- Both Voronoi Noise nodes must have the same Scale and Randomness, or the two sets of cells will not line up.
- Cracked earth: this graph as it is, through a Color Ramp from dark brown to dry tan.
- Scales and pebbles: F1 through One Minus, so each cell is bright in the middle and dark at its rim.
- Bubbles and pores: Smooth F1 with Smoothness around 0.3, cut with Smoothstep.
Simplex Noise 3D: noise with depth
Every noise so far reads a flat position, a U and a V. Simplex Noise 3D reads a position with three numbers. Think of it as a solid block of noise, like a block of marble, where the other nodes are a printed sheet. Whatever shape you cut from the block, the pattern runs straight through it.
- Wire World Position, from the Input folder, into Position. Each point of the model then reads the noise at the place where it sits in the scene.
- No seams. A flat noise is wrapped round a model like a paper label, and it shows a join wherever the edges of the UV layout meet. The block has no edges to join.
- With nothing wired into Position, the node reads the UV with a third number of 0, so it works as a flat noise too.
- Its dials are the ones you know: Scale, Detail (Octaves), Lacunarity and Roughness. A new node starts with Detail at 4. Its output is called Fac.
- A third number is a spare direction to travel in. Feed the clock into it and the pattern changes shape without sliding anywhere. That is the next chapter.
World Position is where a point is in the scene, not where it is on the model. Move or turn the model and it passes through the block of noise, so the pattern appears to swim across it. That is fine for a model that stays put.
Which one do I reach for?
| You want | Reach for |
|---|---|
| Grain, static, glitter, or one value for each tile of a pattern | Random Noise |
| Clouds, smoke, stains, stone, wear: anything soft and organic | Noise, with Detail at 3 or more |
| Scales, pebbles, bubbles, cracks: anything made of cells | Voronoi Noise |
| A pattern on a 3D model with no seams, or one that changes shape over time | Simplex Noise 3D |
| A regular pattern made a little irregular | Any noise, multiplied small and added to the coordinates |
Now you try
- Wood grain. Start with Wave, set Type to Rings and Scale to 8. Add UV Coord, Noise, Multiply and Add, and wire them as in the wobbling bands picture, with Multiply's B at 0.1. Finish with a Color Ramp from dark brown to light brown.
- Camouflage. Send Noise, with Scale 4 and Detail 3, into B of a Step whose A is 0.5. Wire Step's Out into T of Mix (Lerp), and two Color nodes into A and B. For a third colour, repeat with a second Noise at Scale 7 and a second Mix (Lerp) that takes the first Mix (Lerp) as its A.
- Pebbles. Set Voronoi Noise to Smooth F1 with Smoothness 0.2, follow it with One Minus, then with a Color Ramp from dark grey to pale grey. Change Randomness to see the pebbles line up.
Make a shader move, pulse and scroll.
Tell us which node or picture lost you, what you built, and what the square showed instead of what you expected.