Procedural Thermal and Hydraulic Terrain Erosion
Procedural terrain generation in modern video games often relies on physical erosion simulations to transform raw, synthetic noise into believable landscapes. By modeling thermal weathering and hydraulic water carving on two-dimensional heightmaps, developers can replicate millions of years of geological time in a matter of seconds. This article explains how these two fundamental erosion processes operate, how they are mathematically represented on height fields, and how developers optimize them using compute hardware to simulate deep-time terrain deformation.
Heightmaps as the Foundation
A heightmap is a two-dimensional grid where each cell \((x, y)\) stores a scalar value representing elevation (\(z\)). Because heightmaps are essentially single-channel images, they are memory-efficient and straightforward to modify. However, basic noise generators, such as Perlin or Simplex noise, produce isotropic, uniform shapes that lack the directed drainage networks and sediment dynamics seen in nature. To achieve realism, developers apply cellular and agent-based erosion algorithms directly to this grid.
Simulating Thermal Erosion
Thermal erosion, or material slumping, represents the breakdown of rock faces caused by freeze-thaw cycles, thermal expansion, and gravity. In nature, loose material rests at a characteristic maximum slope known as the angle of repose. When a slope exceeds this angle, material slides downward to form talus deposits or scree slopes.
Developers simulate this process using a cellular automaton approach:
- Slope Evaluation: For each cell in the heightmap, the algorithm measures the height difference (\(\Delta h\)) relative to its orthogonal and diagonal neighbors.
- Threshold Comparison: The local slope is compared against a defined talus angle threshold (\(T\)). If \(\Delta h > T\), the slope is unstable.
- Material Redistribution: A volume of material proportional to the excess slope is subtracted from the higher cell and added to the lower neighbor: \[\Delta z = c \cdot (\Delta h - T)\] where \(c\) is a transfer rate constant.
- Iteration: This operation runs across the entire grid for multiple iterations until the terrain stabilizes.
The result is the natural softening of sharp cliffs and the accumulation of debris fans at the bases of steep inclines.
Simulating Hydraulic Erosion
Hydraulic erosion models the interaction of rainfall, surface runoff, and sediment transport. It is responsible for carving riverbeds, branching valleys, and alluvial plains. Developers generally use one of two models: Eulerian (grid-based) or Lagrangian (particle-based).
The Particle-Based (Lagrangian) Approach
The particle-based droplet model is the most widely adopted method in game development due to its simplicity, localized memory access, and high visual fidelity.
- Precipitation: A virtual water droplet is initialized at a random coordinate \((x, y)\) on the map with properties including position, velocity, water volume, and sediment load.
- Direction and Movement: The droplet determines the local surface normal (gradient) via bilinear interpolation of surrounding height values. Gravity accelerates the droplet down the steepest gradient.
- Sediment Capacity Calculation: The droplet's carrying capacity (\(C\)) is calculated dynamically based on its speed, water volume, and the current slope: \[C = k \cdot \text{slope} \cdot \text{velocity}\] where \(k\) is a capacity constant.
- Erosion and Deposition:
- Erosion: If the droplet carries less sediment than \(C\), it dissolves a portion of the terrain height beneath it, adding the material to its sediment load.
- Deposition: If the droplet moves to a flatter area and its capacity falls below its current sediment load, it deposits the excess sediment back onto the heightmap, filling depressions.
- Evaporation: A fraction of the droplet's water evaporates each step. As water decreases, capacity drops, forcing further deposition.
- Termination: The droplet is terminated when its water volume hits zero, it drops below a minimum speed, or it leaves the boundaries of the map.
The Grid-Based (Eulerian) Approach
Grid-based models simulate fluid flow across the entire map simultaneously using shallow water equations. Each cell tracks terrain height, water height, sediment concentration, and velocity vectors. Water flows between adjacent cells based on hydrostatic pressure differences, picking up and dropping sediment according to flow velocity. While computationally heavier, this method captures complex interactions like pooling, dynamic lakes, and broad river flows more accurately than discrete particles.
Simulating Geological Time
True geological erosion occurs over millions of years. Games bridge this gap using time-compression techniques:
- Massive Iteration: Instead of simulating microscopic increments of sediment movement, developers simulate millions of droplet paths or thousands of global fluid iterations in an accelerated offline or loading-phase pass.
- GPU Compute Shaders: Modern implementations run these algorithms on the graphics card using compute shaders. Particle-based droplet paths can be traced concurrently in workgroups, or grid-based passes can be processed as multi-pass rendering pipelines using ping-pong render targets.
- Staged Alternation: Developers frequently interleave thermal and hydraulic passes. Carving valleys with water creates over-steepened banks, which then trigger thermal slumping passes. The slumped sediment is subsequently washed away by subsequent rain cycles, reproducing the perpetual interplay that drives real-world geomorphology.