TerraFractal, part 1: a planet you can zoom into

TerraFractal is a planet generator. The goal is a whole world you can fly over from orbit and then walk across, where every hill, valley and stream is there because of something larger: the plates, the climate, the rock, the rivers that drain it.

Most terrain in games and films starts with noise: random bumps at many sizes, stacked on top of each other until they look like ground. It looks good from a distance. It falls apart when you look for the things a geologist would look for. Rivers that run uphill. Valleys that end in a pit. Mountains that sit in the middle of a plain for no reason. Rock that is the same everywhere.

I wanted the opposite: a chain of causes from the planet down to the pebble.

A mountain block in the current build, from about 6 km up, with snow on the higher range behind
A mountain block in the current build, from about 6 km up, with snow on the higher range behind.
The whole planet from orbit
The whole planet from orbit. The clouds are read from the simulated climate: storm tracks, a cyclone, clear deserts.

The plan in one sentence

Simulate the planet coarsely through its history, then refine it, level by level, where someone is looking.

The simulation runs plate tectonics, crust thickness and age, erosion, sea level, ocean currents and climate across hundreds of millions of years, on a mesh with points about 55 to 110 km apart. That is enough to know where the mountains, basins, rifts, coasts and rain are. It is nowhere near enough to know what a valley looks like.

Everything finer is added by the refinement. The surface is split into tiles. Each tile can split into smaller tiles, and each smaller tile adds detail at its own scale, inheriting what its parent knew. From orbit you see the largest tiles; as you descend, smaller ones load in.

Why “fractal”

Real landscapes look similar across many scales. A gully on a hillside looks like a valley on a mountain range. The usual way to imitate that is to add the same kind of bump at many sizes, each about half the size and half the height of the last. Each size is called an octave, after music. The sum is a fractal: rough at every scale you look at.

Octaves
Octaves: the same kind of bump at smaller and smaller sizes, added together.

That trick is cheap and looks natural, which is why everyone uses it. The trouble is that the octaves know nothing about each other or about water. Most of this series is about that trouble.

What I care about

  • Causes, not decoration. A feature should come from something the simulation knows: uplift, rock hardness, rainfall, age. Fold belts where the crust was squeezed, rift lakes where it was pulled apart, smooth old ranges and jagged young ones.
  • Water that works. Every drop of rain should have a way to the sea or to a lake that evaporates. Rivers fall all the way. Lakes have one level and one outlet.
  • No seams. The world is the same no matter which part you load first, and neighbouring tiles agree exactly along their edges.
  • Same seed, same world. Every random choice comes from the planet’s seed, so a place is always the same place.
  • Spend effort where you’re looking. No pre-computing the whole planet at walking detail.
The same area from 60 km up
The same area from 60 km up. Blue: rivers handed down from the largest scale. Tan: streams the smaller tiles added to them.

What this series covers

I’ve changed approach several times. Not because the code was wrong, but because the way I’d framed the problem was. Each time, the failure taught me something about how terrain has to be built if it’s going to drain. The posts that follow are:

  1. This one: the goals.
  2. Simulating the planet, and where resolution actually matters.
  3. Why noise doesn’t drain.
  4. Constraints, and learning that the grid is only the output.
  5. Co-refinement, and why negotiation never finishes.
  6. Function first: hexagon tiles that only listen to their parents.
  7. Making rivers agree with the ground.
  8. Landforms as geology: rifts, fold belts, cuestas, volcanoes.
  9. Climate and clouds.
  10. Building a forest from the leaf up.

The first seven are about the ground and the water on it. The last three are about what sits on top: the landforms, the weather and the plants.