Midpoint displacement: roughness from one random number
The simplest fractal terrain algorithm, midpoint displacement, starts with just the four corners of a square set to some elevation and repeatedly bisects: find the midpoint of each edge, average the two endpoints, then add a random offset. Do this recursively and a jagged, self-similar profile emerges from almost nothing — the same idea used to generate fractal coastlines and mountain skylines in one dimension before it was extended to a full 2D heightmap.
The diamond-square algorithm
Diamond-square, developed in the 1980s as a fix for directional artifacts in naive 2D midpoint displacement, alternates two steps on a grid whose size is 2ⁿ+1 on each side. The diamond step takes each square of four corners and sets its centre to the average of those four corners plus a random offset; the square step takes each diamond of four already-set points and sets its centre (the midpoint of a grid edge) to their average plus a random offset, wrapping or clamping at the grid boundary. Repeating diamond-then-square at half the step size each pass fills in progressively finer detail:
diamond step: center = avg(4 corners of a square) + random(±r) square step: center = avg(4 corners of a diamond) + random(±r) after each pass: step size /= 2, r *= 2^(-H)
The Hurst exponent: turning noise into believable terrain
The single parameter that decides whether the output looks like gentle hills or jagged mountains is the Hurst exponent H, which sets how quickly the random offset shrinks as the grid refines: multiplying the offset range by 2⁻ᴴ at every halving of the step size. Low H (near 0) keeps the random offsets large even at fine scales, producing rough, jagged, high-frequency terrain; high H (near 1) shrinks fine-scale randomness quickly, producing smooth, rolling terrain dominated by the large-scale structure set in the first few passes. H is directly related to the terrain's fractal dimension, D = 3 − H for a 2D surface, which is the formal justification for calling the result a fractal landscape at all — it has a well-defined, non-integer dimension, and the statistical roughness looks similar whether you zoom into a mountain range or a single hillside.
Why real terrain actually looks fractal
This isn't just a convenient computer-graphics coincidence — real terrain genuinely exhibits self-affine scaling over a wide range of scales, a property first quantified by Benoit Mandelbrot's studies of coastlines and mountain ranges in the 1970s. Erosion, deposition and tectonic uplift all act across many spatial scales simultaneously with roughly self-similar statistics, so a power-law elevation spectrum with Hurst exponents typically between 0.4 and 0.9 for real landscapes turns out to be a genuinely decent statistical model, not merely a visually plausible cheat.
The classic seam artifact, and why it happens
A naive implementation processes each square independently, which means a shared edge midpoint gets computed and randomly offset twice — once by each of the two squares that share it — producing two different values for what should be one shared height and a visible discontinuity (a seam) running along grid lines that align with the original power-of-two subdivisions. The fix is to process every square step for the whole grid at a given scale, then every diamond step for the whole grid at that scale, always sharing already-computed edge values rather than recomputing them per-square; keeping the diamond and square passes properly synchronized across the entire grid is precisely what separates diamond-square from the older, seam-prone 2D midpoint-displacement scheme it replaced.
Beyond diamond-square: noise-based alternatives
Diamond-square is fast and simple but its randomness is tied to the recursive grid structure, which can leave subtle grid-aligned artifacts even when implemented correctly. Modern terrain generators more often layer several octaves of Perlin or simplex noise at increasing frequency and decreasing amplitude — conceptually the same idea of summing detail at multiple scales weighted by a roughness parameter, but built from a smooth, grid-decoupled noise function instead of recursive point averaging. Both approaches are, at heart, ways of approximating the same target: a power-law spectrum of elevation variation across scales, which is what a fractal landscape actually is mathematically.
Frequently asked questions
Why does diamond-square need a grid size of 2^n + 1?
Because the algorithm repeatedly halves the step size, and each halving needs to land exactly on a grid point for the diamond and square steps to align cleanly. A size of 2^n + 1 (like 129, 257, 513) guarantees every halving produces a whole number of cells with no remainder, right down to the single-cell level.
What does the Hurst exponent actually control?
It sets how fast the random offset shrinks as the terrain is refined to finer detail. A low Hurst exponent keeps randomness large at fine scales, producing jagged, mountainous terrain; a high Hurst exponent shrinks fine detail quickly, producing smooth, rolling hills dominated by the broad shape set early in the algorithm.
Why do naive implementations produce visible seams?
A shared grid point between two neighbouring squares gets computed and randomly offset independently by each square if the passes aren't properly synchronized, producing two different heights for what should be one shared point. Correct diamond-square processes every point of a given pass together across the whole grid before moving to the next, finer pass, avoiding the duplicate offset.
Try it live
Everything above runs in your browser — open Fractal Landscape and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Fractal Landscape simulation