Daniel Gray

Thoughts, Notes, Ideas, Projects

← Back to home

Erosion Simulation in Terrain Generation

Erosion simulation is a crucial technique for creating realistic terrain. Natural landscapes are shaped by water, wind, and gravity over millions of years. Simulating these processes can dramatically improve the realism of procedurally generated terrain.

Overview

Erosion simulation models natural processes that shape terrain:

  • Hydraulic Erosion: Water flow carves valleys and riverbeds

  • Thermal Erosion: Material movement down slopes creates talus and smooths sharp edges

  • Wind Erosion: Wind shapes desert landscapes and creates dunes

Hydraulic Erosion

Hydraulic erosion simulates the effect of water flow on terrain. Water flows downhill, carrying sediment and carving channels.

Basic Algorithm

  1. Water Droplet Simulation: Place water droplets on the terrain

  2. Flow Calculation: Calculate water flow direction based on gradient

  3. Sediment Transport: Move sediment based on water velocity

  4. Erosion/Deposition: Erode terrain where water flows fast, deposit where it slows

Implementation Concepts


// Simplified hydraulic erosion

function simulateHydraulicErosion(

heightMap: number[][],

iterations: number,

dropletCount: number

) {

for (let i = 0; i < iterations; i++) {

for (let d = 0; d < dropletCount; d++) {

// Place droplet at random position

let x = Math.random() * width;

let y = Math.random() * height;

let water = 1.0;

let sediment = 0.0;

// Simulate droplet path

for (let step = 0; step < maxSteps; step++) {

// Calculate gradient

const gradient = calculateGradient(heightMap, x, y);

const direction = normalize(gradient);

// Move droplet downhill

x += direction.x * stepSize;

y += direction.y * stepSize;

// Calculate erosion capacity

const capacity = water * velocity * slope;

// Erode or deposit

if (sediment < capacity) {

const erosion = (capacity - sediment) * erosionRate;

heightMap[x][y] -= erosion;

sediment += erosion;

} else {

const deposition = (sediment - capacity) * depositionRate;

heightMap[x][y] += deposition;

sediment -= deposition;

}

// Evaporate water

water *= (1 - evaporationRate);

}

}

}

}

Thermal Erosion

Thermal erosion (also called talus or slope-based erosion) models the gradual movement of material down slopes due to gravity.

Algorithm

  1. Slope Calculation: Calculate slope at each point

  2. Material Movement: Move material from steep areas to adjacent lower areas

  3. Iteration: Repeat until slopes stabilize

Implementation


function simulateThermalErosion(

heightMap: number[][],

iterations: number,

talusAngle: number

) {

for (let i = 0; i < iterations; i++) {

for (let x = 1; x < width - 1; x++) {

for (let y = 1; y < height - 1; y++) {

const height = heightMap[x][y];

const neighbors = [

{ x: x - 1, y, height: heightMap[x - 1][y] },

{ x: x + 1, y, height: heightMap[x + 1][y] },

{ x, y: y - 1, height: heightMap[x][y - 1] },

{ x, y: y + 1, height: heightMap[x][y + 1] },

];

// Find steepest descent

let maxDiff = 0;

let steepestNeighbor = null;

for (const neighbor of neighbors) {

const diff = height - neighbor.height;

if (diff > maxDiff && diff > talusAngle) {

maxDiff = diff;

steepestNeighbor = neighbor;

}

}

// Move material

if (steepestNeighbor) {

const amount = maxDiff * 0.5; // Move half the difference

heightMap[x][y] -= amount;

heightMap[steepestNeighbor.x][steepestNeighbor.y] += amount;

}

}

}

}

}

Wind Erosion

Wind erosion shapes desert landscapes and creates dunes. It's less commonly implemented but can add realism to desert terrain.

Characteristics

  • Directional: Wind flows in specific directions

  • Selective: Affects certain materials more than others

  • Deposition: Creates dunes and sand accumulations

References

Academic Papers

  • Kelley, A. D., et al. (1988). "Terrain Simulation Using a Model of Stream Erosion." ACM SIGGRAPH Computer Graphics, 22(4), 263-268. DOI

  • Musgrave, F. K., et al. (1989). "The Synthesis and Rendering of Eroded Fractal Terrains." ACM SIGGRAPH Computer Graphics, 23(3), 41-50. DOI

  • Chiba, N., et al. (1998). "Two-dimensional Visual Simulation of Landslides, Debris Flows, and Rockfalls." International Journal of Geographical Information Science, 12(7), 709-723. DOI

  • Mei, X., et al. (2007). "A Fast Hydraulic Erosion Model for Real-Time Terrain Generation." Journal of Computer Graphics Techniques, 1-16.

Online Resources

Related Articles

  • Terrain Generation - How erosion fits into terrain generation, providing the base terrain that erosion processes can then refine and shape

  • An adventure with 3js 3d Backgrounds - Overview of the animated background system where erosion could enhance realism

  • Noise Functions - Foundation for terrain generation that creates the initial height maps before erosion is applied

Future Implementation

The current terrain system uses noise-based generation. Future enhancements could include:

  • Hydraulic Erosion: Add water flow simulation to carve realistic river valleys

  • Thermal Erosion: Smooth sharp edges and create more natural mountain slopes

  • Combined Approach: Use noise for initial terrain, then apply erosion for realism

Related Content

The 3D Background

The 3D Background The animated 3D background is a procedurally generated landscape that creates an infinite, dynamically rendered terrain with fractal trees, atmospheric effects, and interactive camer...