---
id: "hydraulic-erosion-stava"
title: "Interactive Hydraulic Erosion on Heightfields"
aliases: [particle hydraulic erosion, layered hydraulic erosion]
domain: "procgen"
stage: "procedural"
realtime: "interactive"
platforms: [cpu, desktop-gpu, cuda, houdini, unity, unreal, godot, python]
year_introduced: 2008
inputs: [heightfield]
outputs: [heightfield]
style: "photoreal"
dynamic: "static"
cost: "offline"
authority: "Stava et al., 2008"
url: "https://texelatlas.vercel.app/t/hydraulic-erosion-stava/"
sources_verified_at: "2026-11-29"
---
# Interactive Hydraulic Erosion on Heightfields (Stava et al., 2008)

> 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.

## 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

## 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 use it

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](https://texelatlas.vercel.app/t/gpu-pipe-model-erosion.md) for a fully GPU-resident implementation, [Stream-Power Erosion (Fluvial Terrain Uplift)](https://texelatlas.vercel.app/t/stream-power-erosion.md) when you need continent-scale drainage that is stable and fast, and [Terrain from Hydrology (River-First Terrain Synthesis)](https://texelatlas.vercel.app/t/hydrology-terrain-synthesis.md) when rivers must be designed first and terrain derived from them.

## Cost

offline — Many iterations over the entire grid; interactive for moderate resolutions on GPU, minutes to hours for large high-resolution terrains.
Measured GPU Weight: 251.29× baseline (extreme) — 8.2673 ms median / 8.3171 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 224.28× baseline (extreme) — 3.5661 ms median (2.32× faster on L4).
Ampere A100 scaling: 184.71× baseline (extreme) — 5.3197 ms median (1.55× faster on A100).

## Failure modes

- 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

## Dataflow

- Inputs: heightfield
- Outputs: heightfield
- Platforms: cpu, desktop-gpu, cuda, houdini, unity, unreal, godot, python

## Presets

### Hydraulic Erosion — raw fBm heightfield (left) vs carved dendritic gullies & alluvial sediment (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_EROSION": 0.85,
  "P_SEDIMENT": 0.72,
  "P_CAM_ORBIT": 0.4,
  "P_SPLIT": 0.48
}
```

```glsl
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.

## Lineage

- extends [GPU Pipe-Model Hydraulic Erosion](https://texelatlas.vercel.app/t/gpu-pipe-model-erosion.md)

## Combines with

- [Fractal Brownian Motion and Multifractals](https://texelatlas.vercel.app/t/fractal-brownian-motion.md): The noise heightfield is the initial terrain that erosion refines.

## Combination ideas

- [Forests that grow into the gaps](https://texelatlas.vercel.app/ideas/eroded-biome-forests/)

## Sources

1. [primary] Ondrej Stava, Bedrich Benes, Matthew Brisbin, Jaroslav Krivanek (2008) Interactive Terrain Modeling Using Hydraulic Erosion. Eurographics/SIGGRAPH Symposium on Computer Animation. https://doi.org/10.2312/sca/sca08/201-210 (verified via doi.org on 2026-11-29)
2. [implementation] SebLague (2019) SebLague/Hydraulic-Erosion. https://github.com/SebLague/Hydraulic-Erosion License: MIT. (verified via github on 2026-11-29)
3. [implementation] dandrino (2018) dandrino/terrain-erosion-3-ways. https://github.com/dandrino/terrain-erosion-3-ways License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Interactive Hydraulic Erosion on Heightfields." https://texelatlas.vercel.app/t/hydraulic-erosion-stava/ (accessed 2026-12-01).
