---
id: "gpu-pipe-model-erosion"
title: "GPU Pipe-Model Hydraulic Erosion"
aliases: [virtual pipes erosion, Mei et al. erosion]
domain: "procgen"
stage: "procedural"
realtime: "interactive"
platforms: [webgl2, webgpu, desktop-gpu, cuda, unity, unreal, godot]
year_introduced: 2007
inputs: [heightfield]
outputs: [heightfield, normals]
style: "photoreal"
dynamic: "static"
cost: "medium"
authority: "Mei et al., 2007"
url: "https://texelatlas.vercel.app/t/gpu-pipe-model-erosion/"
sources_verified_at: "2026-11-29"
---
# GPU Pipe-Model Hydraulic Erosion (Mei et al., 2007)

> A fully GPU-resident erosion solver using virtual pipes between grid cells to move water, with sediment transport and thermal slumping implemented as fragment or compute passes.

## Reach for it when

- procedural terrain looks too smooth and fake
- real-time erosion of heightmaps on gpu
- carve river valleys and ridges into noise terrain
- interactive terrain sculpting with water flow

## How it works

Each cell stores terrain height, water height, suspended sediment and outflow flux to four neighbours, treating adjacent cells as connected by virtual pipes. Per step: add rainfall, compute outflow flux from hydrostatic height difference with a scaling that prevents negative water, update water height and velocity from net flux, then erode or deposit based on a capacity that depends on speed and local tilt. Sediment is advected semi-Lagrangian along the velocity, evaporation removes water, and a thermal pass limits slopes. Everything is a per-cell stencil, so each step is a handful of texture passes or compute dispatches and runs at interactive rates even for large grids.

## When to use it

Choose it for in-engine or in-browser erosion where the heightfield already lives on the GPU and you want visual feedback while sculpting. Prefer [Interactive Hydraulic Erosion on Heightfields](https://texelatlas.vercel.app/t/hydraulic-erosion-stava.md) when you need layered strata and artist control over rock hardness, and [Stream-Power Erosion (Fluvial Terrain Uplift)](https://texelatlas.vercel.app/t/stream-power-erosion.md) when you need large-scale, resolution-independent drainage rather than local gullies.

## Cost

medium — Several full-grid passes per step; interactive iterations per second at 1k to 4k grids on a desktop GPU, but meaningful erosion needs hundreds to thousands of steps.
Measured GPU Weight: 108.59× baseline (extreme) — 3.5727 ms median / 3.813 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 98.31× baseline (extreme) — 1.5631 ms median (2.29× faster on L4).
Ampere A100 scaling: 80.27× baseline (extreme) — 2.3117 ms median (1.55× faster on A100).

## Failure modes

- Flux clamping artifacts: too large a timestep makes water oscillate and checkerboard
- Semi-Lagrangian sediment advection diffuses sediment, smearing deposits
- Pooling water in basins creates flat lake plateaus that never drain
- Grid-axis bias from four-neighbour pipes: gullies run along rows and columns
- Needs float render targets with linear filtering, which mobile WebGL2 may lack

## Engine support

- unity: official — `Package Manager > Terrain Tools > Paint Terrain > Erosion > Hydraulic (GPU hydraulic and thermal erosion brush)` (evidence: https://docs.unity3d.com/Packages/com.unity.terrain-tools@5.1/manual/erosion-hydraulic.html, checked 2026-12-01) — Official Terrain Tools package.

## Dataflow

- Inputs: heightfield
- Outputs: heightfield, normals
- Platforms: webgl2, webgpu, desktop-gpu, cuda, unity, unreal, godot

## Presets

### GPU Pipe-Model Erosion — virtual-pipe flux & water depth map (left) vs active flowing shallow-water channels (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_RAINFALL": 0.78,
  "P_FLOW_SPEED": 1,
  "P_CARVE_DEPTH": 0.85,
  "P_SPLIT": 0.46
}
```

```glsl
const float P_RAINFALL = 0.78; // P Water Flux [0.1, 1.4, 0.04]
const float P_FLOW_SPEED = 1.0; // P Flow Velocity [0.0, 2.5, 0.05]
const float P_CARVE_DEPTH = 0.85; // P Channel Carve [0.1, 1.4, 0.04]
const float P_SPLIT = 0.46; // P Flux Map / Water 3D [0.0, 1.0, 0.02]

float hash21(vec2 p) {
  p = fract(p * vec2(127.1, 311.7));
  p += dot(p, p + 34.5);
  return fract(p.x * p.y);
}

float vnoise(vec2 p) {
  vec2 i = floor(p);
  vec2 f = fract(p);
  vec2 u = f * f * (3.0 - 2.0 * f);
  return mix(
    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),
    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),
    u.y
  );
}

// Compute terrain height + shallow-water pipe channel mask + downstream flow coordinate
vec3 evalPipeBasin(vec2 xz, float carve, float rain) {
  // Sloping alpine watershed draining from -z toward +z
  float baseSlope = -xz.y * 0.24 + 0.12 * abs(xz.x);
  // Two braided meandering river channels converging into a main trunk
  float mainRiver = abs(xz.x - 0.34 * sin(xz.y * 1.45 + 0.4));
  float tribRiver = abs((xz.x - 0.58) + (xz.y + 0.4) * 0.42 - 0.14 * sin(xz.y * 2.8));
  float dChan = min(mainRiver, tribRiver * 1.15);

  float hills = vnoise(xz * 1.2) * 0.48 + vnoise(xz * 2.7) * 0.18 + vnoise(xz * 5.8) * 0.06;
  float channelCut = exp(-dChan * dChan * 18.0) * 0.34 * carve;
  float terrainH = baseSlope + hills - channelCut - 0.38;

  // Shallow-water column height d(x,z) concentrated in pipe channels + sheet-flow tributaries
  float waterD = exp(-dChan * dChan * 22.0) * 0.16 * rain;
  float rills = smoothstep(0.62, 0.88, sin(xz.x * 10.0 + hills * 8.0) * 0.5 + 0.5) * 0.03 * rain;
  waterD += rills * smoothstep(0.08, 0.35, dChan);
  return vec3(terrainH, waterD, dChan);
}

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 isFluxVis = screenX < split;
  float rain = clamp(P_RAINFALL, 0.08, 1.6);
  float flowT = iTime * max(P_FLOW_SPEED, 0.0);
  float carve = clamp(P_CARVE_DEPTH, 0.1, 1.5);

  vec3 ro = vec3(0.0, 1.28, 2.30);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.38, -1.32));
  vec3 sky = mix(vec3(0.66, 0.78, 0.90), vec3(0.14, 0.32, 0.62), 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;
    vec3 b = evalPipeBasin(p.xz, carve, rain);
    float d = p.y - (b.x + b.y * 0.55);
    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.018;
    vec3 bC = evalPipeBasin(p.xz, carve, rain);
    float hX = evalPipeBasin(p.xz + vec2(e, 0.0), carve, rain).x;
    float hZ = evalPipeBasin(p.xz + vec2(0.0, e), carve, rain).x;
    vec3 n = normalize(vec3((bC.x - hX) / e, 1.0, (bC.x - hZ) / e));

    vec3 sunDir = normalize(vec3(0.60, 0.72, 0.42));
    float diff = max(dot(n, sunDir), 0.0);
    float wet = smoothstep(0.018, 0.095, bC.y);
    float flowRipple = 0.5 + 0.5 * sin(p.z * 26.0 - flowT * 5.2 + sin(p.x * 12.0));

    if (isFluxVis) {
      // Left: Virtual-pipe grid cells & shallow-water velocity flux heatmap
      vec2 grid = abs(fract(p.xz * 6.0) - 0.5);
      float cellLine = smoothstep(0.055, 0.015, min(grid.x, grid.y));
      float flux = clamp(bC.y * 8.5, 0.0, 1.0);
      vec3 heat = mix(vec3(0.07, 0.11, 0.18), vec3(0.08, 0.76, 0.94), smoothstep(0.0, 0.55, flux));
      heat = mix(heat, vec3(0.98, 0.86, 0.24), smoothstep(0.50, 0.95, flux));
      heat *= (0.48 + 0.65 * diff);
      // Animated downstream pipe-flux dashes
      float pulse = smoothstep(0.55, 0.92, flowRipple) * flux;
      col = heat + vec3(0.95, 0.98, 1.0) * pulse * 0.48 + vec3(0.18, 0.34, 0.50) * cellLine * 0.35;
    } else {
      // Right: Shaded carved basin with glistening shallow-water river & suspended sediment foam
      vec3 rock = mix(vec3(0.32, 0.28, 0.24), vec3(0.56, 0.46, 0.36), smoothstep(0.18, 0.52, 1.0 - n.y));
      vec3 bank = vec3(0.24, 0.42, 0.22);
      vec3 ground = mix(bank, rock, smoothstep(0.10, 0.35, 1.0 - n.y));
      vec3 waterCol = mix(vec3(0.06, 0.36, 0.48), vec3(0.18, 0.76, 0.86), flowRipple * 0.45 + 0.35);
      vec3 alb = mix(ground, waterCol, wet);
      vec3 nW = normalize(mix(n, normalize(vec3(sin(p.z * 24.0 - flowT * 5.0) * 0.08, 1.0, cos(p.x * 20.0) * 0.08)), wet));
      float spec = pow(max(dot(nW, normalize(sunDir - rd)), 0.0), 48.0) * wet;
      col = alb * (0.26 + 0.86 * diff) + vec3(0.95, 0.98, 1.0) * spec * 0.95;
      col += vec3(0.88, 0.94, 0.98) * smoothstep(0.75, 0.98, flowRipple) * wet * 0.22;
    }
    col = mix(col, 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 [Thermal (Talus) Erosion](https://texelatlas.vercel.app/t/thermal-erosion.md)
- extended by [Interactive Hydraulic Erosion on Heightfields](https://texelatlas.vercel.app/t/hydraulic-erosion-stava.md)

## Combination ideas

- [Overhang-capable voxel erosion with pipe-model water](https://texelatlas.vercel.app/ideas/margolus-voxel-erosion-pipe-water/)

## Sources

1. [primary] Xing Mei, Philippe Decaudin, Bao-Gang Hu (2007) Fast Hydraulic Erosion Simulation and Visualization on GPU. 15th Pacific Conference on Computer Graphics and Applications (PG'07). https://doi.org/10.1109/pg.2007.15 (verified via crossref on 2026-11-29)
2. [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. "GPU Pipe-Model Hydraulic Erosion." https://texelatlas.vercel.app/t/gpu-pipe-model-erosion/ (accessed 2026-12-01).
