Interactive Hydraulic Erosion on Heightfields
Simulates rainfall, runoff, sediment pickup and deposition on a terrain, with an interactive layered heightfield and a procedural base, to produce branching river valleys and alluvial fans that noise alone cannot.
Also known as particle hydraulic erosion, layered hydraulic erosion
In the family Procedural generation, terrain erosion
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | No built-in heightfield hydraulic erosion solver. |
| Unity | None found | Terrain Tools ships a hydraulic erosion brush (official), but not the Štʼava et al. method. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Stava and colleagues build on a grid shallow-water model: water height, flux and velocity are stored per cell, rain adds water, and flux moves it downhill. Flow velocity sets a sediment carrying capacity; when carrying less than capacity the water dissolves terrain, when carrying more it deposits. Thermal and talus-like slumping stabilise banks. The paper runs this on a layered representation (bedrock, sediment) so authors can paint rain and source water and see valleys form, then continues the simulation interactively. A widely used simpler cousin is the droplet (particle) method: spawn many water droplets, move each along the gradient with inertia, erode while fast and deposit while slow. Both families need many iterations before channels become visible.
When to choose it
Reach for it when
- terrain from noise lacks realistic river channels
- need physically plausible water erosion on heightfield
- erosion that creates deposits and sharp gullies
- interactive erosion editing for landscape artists
Choose it for authoring plausible mountain valleys and deltas where you can afford seconds-to-minutes of simulation and want local control. Prefer GPU Pipe-Model Hydraulic Erosion for a fully GPU-resident implementation, Stream-Power Erosion (Fluvial Terrain Uplift) when you need continent-scale drainage that is stable and fast, and Terrain from Hydrology (River-First Terrain Synthesis) when rivers must be designed first and terrain derived from them.
Field marks
- Pits and flat basins accumulate water and create blocky lakes unless filled or drained explicitly
- Parameter coupling (capacity, dissolve rate, evaporation) makes results vary wildly; too much dissolve gives canyons with no tributaries
- Resolution dependence: channel width tracks cell size, so erosion tuned at 512 cells looks different at 2048
- Grid-aligned gullies and streak artifacts when flow follows axis directions only
- Mass leakage at tile borders when erosion is run per-tile without halo exchange
Presets
Hydraulic Erosion — raw fBm heightfield (left) vs carved dendritic gullies & alluvial sediment (right)
{
"P_EROSION": 0.85,
"P_SEDIMENT": 0.72,
"P_CAM_ORBIT": 0.4,
"P_SPLIT": 0.48
}Show GLSL (135 lines)
const float P_EROSION = 0.85; // P Gully Erosion [0.05, 1.3, 0.04]
const float P_SEDIMENT = 0.72; // P Sediment Fan [0.0, 1.2, 0.04]
const float P_CAM_ORBIT = 0.40; // P Orbit Speed [0.0, 2.0, 0.05]
const float P_SPLIT = 0.48; // P Raw fBm / Eroded [0.0, 1.0, 0.02]
mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 34.5);
return fract(p.x * p.y);
}
// Value noise returning (value, d/dx, d/dz) analytical gradient for gradient-advected hydraulic erosion
vec3 noiseD(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
vec2 du = 6.0 * f * (1.0 - f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
float v = a + (b - a) * u.x + (c - a) * u.y + (a - b - c + d) * u.x * u.y;
vec2 g = du * vec2((b - a) + (a - b - c + d) * u.y, (c - a) + (a - b - c + d) * u.x);
return vec3(v, g);
}
// Raw un-eroded mountain fBm
float rawTerrain(vec2 p) {
float h = 0.0, amp = 0.55;
vec2 q = p * 0.78;
for (int i = 0; i < 4; i++) {
h += amp * noiseD(q).x;
q = rot2(0.55) * q * 2.02 + vec2(3.7, 1.9);
amp *= 0.48;
}
float peak = exp(-dot(p, p) * 0.42) * 0.85;
return h * 0.65 + peak - 0.52;
}
// Hydraulically eroded heightfield using analytical slope-driven ridge & dendritic gully carving (returns height, sediment)
vec2 erodedTerrain(vec2 p, float eroStr, float sedStr) {
float h = 0.0, amp = 0.55;
vec2 gradAcc = vec2(0.0);
float gullyAcc = 0.0;
vec2 q = p * 0.78;
mat2 m = rot2(0.55);
for (int i = 0; i < 5; i++) {
vec3 nd = noiseD(q);
gradAcc += nd.yz * amp;
float slope = length(gradAcc);
// Steep slopes erode sharp concave dendritic gullies; flat basins accumulate smooth sediment
float ridge = 1.0 - abs(nd.x * 2.0 - 1.0);
float carve = (ridge * ridge) / (1.0 + slope * 3.8 * eroStr);
h += amp * mix(nd.x, carve, clamp(eroStr * 0.85, 0.0, 1.0));
gullyAcc += amp * (nd.x - carve) * eroStr;
q = m * q * 2.04 + vec2(3.7, 1.9) + gradAcc * 0.14 * eroStr;
amp *= 0.48;
}
float r2 = dot(p, p);
float peak = exp(-r2 * 0.42) * 0.85;
// Alluvial sediment deposition apron around base foothills
float sedMask = clamp(smoothstep(0.45, 1.35, r2) * smoothstep(0.65, 0.12, length(gradAcc)) * sedStr + max(gullyAcc * 0.5, 0.0), 0.0, 1.0);
float height = h * 0.65 + peak - 0.52 + sedMask * 0.06;
return vec2(height, sedMask);
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool isEroded = screenX >= split;
float ero = clamp(P_EROSION, 0.05, 1.4);
float sed = clamp(P_SEDIMENT, 0.0, 1.4);
float spin = iTime * max(P_CAM_ORBIT, 0.0) * 0.35;
vec3 ro = vec3(0.0, 1.25, 2.55);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.34, -1.35));
ro.xz = rot2(spin) * ro.xz;
rd.xz = rot2(spin) * rd.xz;
vec3 sky = mix(vec3(0.86, 0.72, 0.58), vec3(0.18, 0.38, 0.68), smoothstep(-0.08, 0.52, rd.y));
vec3 col = sky;
float t = 0.2;
bool hit = false;
for (int i = 0; i < 64; i++) {
vec3 p = ro + rd * t;
float h = isEroded ? erodedTerrain(p.xz, ero, sed).x : rawTerrain(p.xz);
float d = p.y - h;
if (d < 0.008) { hit = true; break; }
t += max(d * 0.45, 0.025);
if (t > 12.0) break;
}
if (hit) {
vec3 p = ro + rd * t;
float e = 0.015;
vec2 cVal = isEroded ? erodedTerrain(p.xz, ero, sed) : vec2(rawTerrain(p.xz), 0.0);
float hx = isEroded ? erodedTerrain(p.xz + vec2(e, 0.0), ero, sed).x : rawTerrain(p.xz + vec2(e, 0.0));
float hz = isEroded ? erodedTerrain(p.xz + vec2(0.0, e), ero, sed).x : rawTerrain(p.xz + vec2(0.0, e));
vec3 n = normalize(vec3((cVal.x - hx) / e, 1.0, (cVal.x - hz) / e));
vec3 sunDir = normalize(vec3(0.68, 0.56, 0.46));
float diff = max(dot(n, sunDir), 0.0);
float slope = 1.0 - n.y;
// Geologic strata: dark granite rock on steep eroded cliffs, ochre alluvial sediment in gullies/fans, snow peaks
vec3 rock = mix(vec3(0.28, 0.26, 0.25), vec3(0.48, 0.44, 0.40), smoothstep(0.15, 0.55, slope));
vec3 grass = vec3(0.22, 0.40, 0.20);
vec3 sedimentCol = vec3(0.76, 0.56, 0.34);
vec3 snow = vec3(0.92, 0.94, 0.98);
vec3 alb = mix(grass, rock, smoothstep(0.14, 0.38, slope));
if (isEroded) {
alb = mix(alb, sedimentCol, clamp(cVal.y * 0.85, 0.0, 0.85));
}
alb = mix(alb, snow, smoothstep(0.44, 0.66, cVal.x) * smoothstep(0.45, 0.16, slope));
vec3 lit = alb * (0.24 + 0.92 * diff) + vec3(0.20, 0.34, 0.56) * 0.20 * (0.5 + 0.5 * n.y);
col = mix(lit, sky, 1.0 - exp(-t * 0.075));
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| hydraulic-erosion-stava-live | Tesla T4 1920x1080 | 251× baseline (extreme) · 8.27 ms / 8.32 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| hydraulic-erosion-stava-live | NVIDIA L4 1920x1080 | 224× baseline (extreme) · 3.57 ms / 3.59 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| hydraulic-erosion-stava-live | NVIDIA A100-SXM4-40GB 1920x1080 | 185× baseline (extreme) · 5.32 ms / 5.37 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- Forests that grow into the gaps: Biomes where terrain, plant placement and each tree's shape are linked. Erosion supplies wet valleys and dry ridges, an ecosystem simulation places species by moisture and competition, and every crown grows only into space its neighbours left free.
- Fractal Brownian Motion and Multifractals: The noise heightfield is the initial terrain that erosion refines.
Sources
- primaryOndrej Stava, Bedrich Benes, Matthew Brisbin, Jaroslav Krivanek (2008). Interactive Terrain Modeling Using Hydraulic Erosion. Eurographics/SIGGRAPH Symposium on Computer Animation.Verified via doi.org · 2026-11-29doi:10.2312/sca/sca08/201-210
- implementationdandrino (2018). dandrino/terrain-erosion-3-ways. Three Ways of Generating Terrain with Erosion FeaturesGitHub API · license MIT · 2026-11-29