Module 05

Noise & randomness

A hash is not a texture lookup

There's no random number generator on the GPU in the way you're used to — no seed, no state, no "next value." Instead, a hash function turns a coordinate into a pseudo-random number deterministically: the same input always produces the same output, every frame, on every pixel. The classic one-liner is fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123) — it looks arbitrary, and mostly is, but it works because sin() oscillates fast for large inputs and fract() throws away everything except the noisy decimal part. Change the input by a tiny amount and the output jumps unpredictably. That's all "random" means here.

Value noise vs. Perlin/simplex vs. Worley — the actual family tree

Teal dots: the hashed random value at each grid corner. Gold curve: what smoothstep-blending between them actually looks like — smooth, not the jagged straight-line interpolation you might expect.

Value noise hashes the four corners of a grid cell and smoothly interpolates between them — simple, but you can sometimes see the underlying grid if you look closely. Perlin noise (and its faster, cleaner successor, simplex noise) hashes random gradients at each corner instead of random values, which removes almost all of that grid-aligned look. Worley noise (also called cellular noise) is a different animal entirely — it scatters random points and colors each pixel by its distance to the nearest one, which is where that distinctive cracked, cell-like pattern comes from. Four names, three genuinely different ideas — not one blurry "noise" bucket.

fbm: stacking noise on itself

Fractal Brownian motion sounds academic; it's just "add several layers of noise together, each one at double the frequency and half the strength of the last." One octave of value noise looks like lava-lamp blobs. Four or five octaves layered on top of each other start looking like real clouds, marble, or fire — because that's roughly how those natural patterns actually build up, detail on top of detail on top of detail.

Predict the output

Which of these is built from distance-to-nearest-random-point, rather than interpolating values across a grid?