16. Perlin & Simplex Noise

Controlled randomness — the foundation of procedural textures, terrain, and organic motion

Pure randomness looks terrible. If you assign each pixel a random brightness, you get TV static — no structure, no flow, nothing that looks natural. What you need is smooth randomness: values that vary continuously so nearby points are similar, but that still shift unpredictably over distance. That's exactly what noise functions provide.

Ken Perlin invented his noise function in 1983 while working on the original Tron. It won an Academy Award for Technical Achievement. Nearly every procedural texture, terrain heightmap, cloud layer, and animated wobble in games and film traces back to this idea.

The Core Idea

A noise function maps coordinates to a smooth, pseudorandom value:

noise(x,y)→[−1,1]\text{noise}(x, y) \rightarrow [-1, 1]

The key properties:

  1. Continuous — nearby inputs produce nearby outputs (no sudden jumps)
  2. Pseudorandom — no visible patterns or repetition
  3. Repeatable — the same input always returns the same output
  4. Bounded — output stays in a known range

White noise has property 3 but fails properties 1 and 2 at the perceptual level. A sine wave has property 1 but is obviously patterned. Noise functions sit in the sweet spot.

The difference is immediately visible. White noise (left) has no spatial structure — every pixel is independent. A single octave of smooth noise (right) varies continuously, creating organic-looking blobs:

White noise

Smooth noise (1 octave)

Value Noise: The Simplest Approach

The easiest way to build smooth noise:

  1. Create a grid of random values (one per integer coordinate)
  2. For any point between grid nodes, interpolate the surrounding values

The left canvas below shows the grid — each dot's brightness represents a random value at that integer coordinate. The right canvas shows the result after bilinear interpolation fills in every pixel between the grid points:

Random grid values

Interpolated result

For 2D, each point (x, y) sits inside a unit square defined by four grid corners. You interpolate in two steps:

// Grid corner values
v00 = random at (floor(x),     floor(y))
v10 = random at (floor(x) + 1, floor(y))
v01 = random at (floor(x),     floor(y) + 1)
v11 = random at (floor(x) + 1, floor(y) + 1)

// Fractional position within the cell
fx = x - floor(x)
fy = y - floor(y)

// Smooth the fractional values (fade function)
u = fade(fx)
v = fade(fy)

// Bilinear interpolation
result = lerp(lerp(v00, v10, u), lerp(v01, v11, u), v)

The fade function is critical. Linear interpolation produces visible grid artifacts. Perlin's original fade curve:

fade(t)=3t2−2t3\text{fade}(t) = 3t^2 - 2t^3

His improved version (2002) uses a quintic that has zero first and second derivatives at 0 and 1:

fade(t)=6t5−15t4+10t3\text{fade}(t) = 6t^5 - 15t^4 + 10t^3

This eliminates subtle discontinuities in the gradient of the noise.

Perlin Noise: Gradient-Based

Value noise interpolates random values. Perlin noise interpolates random gradients — and this produces more natural-looking results with fewer directional artifacts.

The algorithm:

  1. At each integer grid point, assign a random gradient vector (a unit vector pointing in a random direction)
  2. For a point inside a grid cell, compute the dot product of each corner's gradient with the vector from that corner to the point
  3. Interpolate the four dot products using the fade function

The left canvas shows gradient arrows at each grid point. The right canvas shows the resulting noise — notice how it's smoother and more natural than value noise, with no blocky grid artifacts:

Gradient vectors at grid points

Perlin noise result

for each corner (cx, cy) of the cell containing (x, y):
    gradient = random unit vector at (cx, cy)
    offset  = (x - cx, y - cy)
    dot[cx][cy] = gradient · offset

result = interpolate the four dot products using fade(fx), fade(fy)

Why gradients instead of values?

Random values at grid points can create blocky artifacts because all four corners might have similar values, producing flat regions aligned to the grid. Gradients force the noise to vary across each cell — the dot product changes sign as you cross the grid point, creating natural-looking hills and valleys.

The permutation table

Perlin noise doesn't store gradient vectors in a 2D array. Instead, it uses a permutation table — a shuffled array of 0-255 — to hash grid coordinates into gradient indices. This makes the noise function stateless and memory-efficient:

// Classic permutation table approach
perm = [151, 160, 137, 91, ...]   // 256 shuffled values, repeated

function hash(ix, iy):
    return perm[perm[ix & 255] + (iy & 255)]

The hash output selects one of a small set of gradient vectors (typically the 8 or 12 vectors pointing toward edges of a cube in higher dimensions).

Simplex Noise: Perlin's Successor

In 2001, Perlin introduced simplex noise to fix two problems with his original algorithm:

  1. Computational cost scales badly — classic Perlin noise in n dimensions needs 2n corners per cell (4 in 2D, 8 in 3D, 16 in 4D). Simplex noise uses n + 1 corners (3 in 2D, 4 in 3D).
  2. Directional artifacts — the square grid creates subtle axis-aligned patterns. Simplex noise uses a simplex grid (triangles in 2D, tetrahedra in 3D) that has no preferred directions.

The simplex grid

A simplex is the simplest shape that fills n-dimensional space:

Dimensions Simplex Corners
1D Line segment 2
2D Triangle 3
3D Tetrahedron 4

To tile 2D space with equilateral triangles, simplex noise skews the coordinate system:

  1. Skew the input point from square space into simplex (triangular) space to find which triangle it falls in
  2. Determine which three corners surround the point
  3. For each corner, compute a radial falloff — a kernel that smoothly drops to zero at a fixed radius — multiplied by the dot product of the corner's gradient and the offset vector
  4. Sum the three contributions

The skew factor for 2D is:

F=3−12≈0.366F = \frac{\sqrt{3} - 1}{2} \approx 0.366

G=3−36≈0.211G = \frac{3 - \sqrt{3}}{6} \approx 0.211

The key advantage: instead of interpolating between 4 corners with a fade function, simplex noise sums 3 independent kernel contributions. Each kernel is:

(max⁡(0, 0.5−d2))4⋅(gradient⋅offset)\left(\max(0,\ 0.5 - d^2)\right)^4 \cdot (\text{gradient} \cdot \text{offset})

where d is the distance from the corner. The max(0, ...) means distant corners contribute nothing — a natural, smooth cutoff with no interpolation artifacts.

Fractal Brownian Motion (fBm)

A single octave of noise is smooth and blobby. Natural textures have detail at every scale — large rolling hills and tiny bumps. Fractal Brownian Motion layers multiple octaves of noise at different frequencies and amplitudes:

fBm(p)=∑i=0n−1amplitudei×noise(frequencyi×p)\text{fBm}(p) = \sum_{i=0}^{n-1} \text{amplitude}_i \times \text{noise}(\text{frequency}_i \times p)

Each octave doubles the frequency and halves the amplitude:

Octave Frequency Amplitude
0 1 1.0
1 2 0.5
2 4 0.25
3 8 0.125

The ratio between successive frequencies is called lacunarity (typically 2.0). The ratio between successive amplitudes is called persistence or gain (typically 0.5).

Here's what each octave looks like individually, and how they combine. Each row doubles the frequency and halves the amplitude — the sum produces rich, multi-scale detail:

function fbm(x, y, octaves, lacunarity, persistence):
    value = 0
    amplitude = 1
    frequency = 1
    maxAmplitude = 0

    for i in 0..octaves:
        value += amplitude * noise(x * frequency, y * frequency)
        maxAmplitude += amplitude
        amplitude *= persistence
        frequency *= lacunarity

    return value / maxAmplitude   // normalize to [-1, 1]

Why "fractal"?

The term comes from the self-similar structure: each octave adds detail at a smaller scale, just as a fractal coastline has bays within bays within bays. The persistence value controls the fractal dimension — how rough or smooth the result looks. Low persistence (0.25) gives gentle rolling hills; high persistence (0.75) gives craggy, rough terrain.

Domain Warping

One of the most powerful techniques built on noise is domain warping — using one noise function to distort the input coordinates of another:

function warpedNoise(x, y):
    offsetX = fbm(x, y)
    offsetY = fbm(x + 5.2, y + 1.3)
    return fbm(x + offsetX * warpStrength, y + offsetY * warpStrength)

This produces swirling, organic patterns reminiscent of marble, wood grain, or atmospheric turbulence. Stacking multiple warping passes creates increasingly complex fluid-like forms.

Try It: Noise Explorer

Experiment with noise type, octaves, lacunarity, persistence, and domain warping. The canvas renders in real time as you adjust parameters.

Noise Explorer

Adjust parameters to explore noise patterns

Applications

Noise functions are the workhorse of procedural generation:

  • Terrain heightmaps — fBm noise mapped to elevation, with octaves controlling detail from mountain ranges down to individual rocks
  • Cloud and smoke — 3D noise animated over time, with density thresholds for volume rendering
  • Water and caustics — animated noise displacing surface normals or UV coordinates
  • Textures — marble (noise as a phase offset for sine), wood (noise in polar coordinates), stone (high-octave fBm with harsh contrast)
  • Vegetation placement — noise thresholds determining where trees, grass, and flowers spawn
  • Animation — noise-driven camera shake, character idle motion, flickering lights

The key insight across all of these: noise gives you spatial coherence that pure randomness cannot. Nearby points get similar values, creating the smooth variation that the eye reads as "natural."

What's Next

Noise gives us smooth, organic randomness. Next we'll explore L-systems — deterministic string-rewriting rules that grow fractal trees, branching plants, and organic structures through simple recursive grammars.