skip to content

For a terrain heightmap, how do value, Perlin and Simplex noise differ, and what do fBm octaves add on top?

level: middleimportance: should knowfreq 40%

answer

  1. random values versus random slopes
  2. zero at every lattice point
  3. fewer corners on a triangle grid
  4. double the frequency, halve the amplitude
  5. stop when detail is below a sample

basics

~20 s

Value noise blends random heights stored at grid points and looks blocky; Perlin noise blends random gradients for smoother, less grid-bound hills; Simplex noise uses a triangle grid with fewer corners and artifacts. fBm sums octaves of rising frequency and falling amplitude.

solid answer

~50 s

All three are **lattice noise**: smooth, repeatable functions built from pseudo-random data hashed from integer grid coordinates. **Value noise** stores a random height per grid point and interpolates, so hills and pits sit on grid points and the grid shows. **Perlin noise** stores a random gradient per corner, dots it with the offset from that corner to the sample point and blends the results with a fade curve such as `6t^5 - 15t^4 + 10t^3`; it is exactly zero at every lattice point, so sampling at integer coordinates gives a flat map. **Simplex noise** uses a skewed triangle grid (tetrahedra in 3D), sums `n + 1` corner contributions instead of blending `2^n`, and has fewer axis-aligned artifacts. **fBm** adds octaves: each one multiplies frequency by the lacunarity (often 2) and amplitude by the gain (often 0.5), and the sum is normalised by the total amplitude.

code

pseudocode · 16 lines
pseudocode
function fbm(x, y, octaves, lacunarity, gain):
    sum = 0
    amplitude = 1
    frequency = 1
    norm = 0
    for k from 0 to octaves - 1:
        ox = 17.3 * k                     // per-octave offset so octaves do not align at the origin
        oy = 41.9 * k
        sum = sum + amplitude * noise(x * frequency + ox, y * frequency + oy)
        norm = norm + amplitude
        frequency = frequency * lacunarity
        amplitude = amplitude * gain
    return sum / norm

// heightmap pixel (px, py): sample at scaled, non-integer coordinates
height = fbm(px * 0.005, py * 0.005, 6, 2.0, 0.5)

go deeper

for a junior

Recall the difference in one line each: value noise blends random heights, Perlin blends random gradients, Simplex uses a triangle grid, and fBm stacks octaves.

for a middle

Explain the Perlin evaluation (corner gradients, dot products, fade curve), why it is zero on lattice points, and what lacunarity and gain do in an fBm loop.

for a senior

Diagnose terrain from symptoms: flat maps from integer sampling, grid streaks, creases from the fade curve, aligned octaves, and blockiness far from the origin.

for a principal

Own the terrain pipeline's noise contract: deterministic seeding, fixed parameters versioned with the world format, and tests that regenerate known chunks bit for bit.

## Why noise instead of a random number per pixel A **terrain heightmap** is a grid of heights. Filling it with independent random numbers gives static: neighbouring samples are unrelated, so there are no hills. **Coherent noise** is a function `noise(x, y)` that is pseudo-random at large scales but smooth at small ones: nearby inputs give nearby outputs. It is also **deterministic**: the same coordinates and the same seed always give the same height, so a world can be regenerated chunk by chunk instead of stored. The three classic kinds are all **lattice noise**. Space is cut into cells by an integer grid; each grid point gets pseudo-random data by **hashing** its integer coordinates, usually through a shuffled permutation table of 256 entries; the value at any point is built from the cell's corners. ## Value noise **Value noise** stores a random **height** at each grid point and interpolates between corners with a smooth curve. It is cheap and easy to explain, but its extremes sit on the grid points, so ridges and valleys line up with the axes and the grid is visible, especially in a single octave. ## Perlin gradient noise **Perlin noise** stores a random **gradient** (a direction) at each grid point instead of a height. For a sample point: 1. Find the cell containing the point and the point's fractional offset inside it. 2. For each of the cell's `2^n` corners (4 in 2D, 8 in 3D), take the dot product of the corner's gradient with the vector from that corner to the point. 3. Blend the corner results with a **fade curve** applied to each fractional coordinate. The original curve was `3t^2 - 2t^3`; the improved version uses `6t^5 - 15t^4 + 10t^3`, whose second derivative is also zero at the cell edges, removing creases visible in lighting computed from the terrain's slope. Two consequences matter in practice: - At any **integer lattice point** the offset to its own corner is zero and the fade weights of the other corners are zero, so **Perlin noise is exactly 0 there**. A heightmap that samples `noise(x, y)` at integer pixel coordinates is perfectly flat. Scale the coordinates first, for example `noise(x * 0.01, y * 0.01)`. - The output is roughly centred on zero, and its exact range depends on the dimension and the gradient set, so real code rescales it rather than assuming exactly `[-1, 1]`. ## Simplex noise **Simplex noise**, also by Ken Perlin, replaces the square or cubic grid with a grid of **simplices**: triangles in 2D, tetrahedra in 3D. A sample touches only `n + 1` corners instead of `2^n`, and each corner contributes a gradient dot product times a kernel that falls off with distance, so contributions are **summed** rather than interpolated. This makes it cheaper in higher dimensions and removes most of the axis-aligned look. | Kind | Stored per grid point | Corners per 3D sample | Look | |---|---|---|---| | Value noise | random height | 8 | blocky, grid-aligned extremes | | Perlin noise | random gradient | 8 | smoother, some axis-aligned artifacts | | Simplex noise | random gradient | 4 | smooth, close to direction-free | ## fBm octaves: lacunarity and gain One layer of noise gives rolling hills of one size. Real terrain has mountains, hills, rocks and pebbles at once. **Fractional Brownian motion (fBm)** sums several layers, called **octaves**: - Each octave samples the noise at a higher **frequency**, multiplied each time by the **lacunarity**, commonly about 2. - Each octave contributes a smaller **amplitude**, multiplied each time by the **gain** (also called persistence), commonly about 0.5. - With lacunarity 2 and gain 0.5, the third octave has 4 times the frequency and a quarter of the amplitude of the first. - The sum is divided by the total of the amplitudes (for gain 0.5 and `k` octaves, `2 * (1 - 0.5^k)`) to keep the range stable. - Stop adding octaves when an octave's features shrink below about two heightmap samples; finer octaves cannot be represented and only add aliasing. - Variations reshape each octave: **ridged** noise uses `1 - abs(noise)` for sharp crests, and **domain warping** feeds noise into the coordinates of more noise for eroded-looking shapes. ## Seeding and the classic bugs - **Seeding**: shuffle the permutation table with Fisher-Yates from the world seed, or mix the seed into the hash. - **Correlated octaves**: every octave of Perlin noise is zero at the origin, so the octaves line up there. Offset or rotate each octave's coordinates. - **Grid streaks**: value noise with few octaves shows the axes; switch to gradient or simplex noise. - **Float precision far from the origin**: large world coordinates lose fractional bits and the noise turns blocky; that is a floating-point precision problem, handled by rebasing coordinates.

  • Why did the improved Perlin noise change the fade curve?
    The original `3t^2 - 2t^3` has a continuous first derivative but a jumping second derivative at cell edges. Terrain lighting depends on slope, and bump effects on its derivative, so the jump shows up as faint grid creases. `6t^5 - 15t^4 + 10t^3` has zero first and second derivatives at `t = 0` and `t = 1`, so the seams disappear.
  • How do you make the terrain repeat seamlessly across a tile?
    Make the lattice wrap: hash grid coordinates modulo the tile's period in cells, so the corners on the right edge reuse the gradients of the left edge. With fBm, choose a lacunarity and base period so every octave's period divides the tile size, for example lacunarity 2 with a power-of-two tile.

fBm is like describing a coastline: first the shape of the continent, then its bays, then the coves inside each bay, then rocks along each cove. Each layer is finer and smaller in height than the one before, and stopping early just gives a smoother coast.

  • Perlin noise is just smoothed random values stored at grid points.
  • Sampling Perlin noise at integer pixel coordinates gives a detailed heightmap.
  • More fBm octaves always add useful detail to a heightmap.
  • Simplex noise is Perlin noise with a different fade curve.
  • Noise output always lies exactly in the range from -1 to 1.