GPU Pipe-Model Hydraulic Erosion
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.
Also known as virtual pipes erosion, Mei et al. 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 | Godot has no built-in terrain system or GPU pipe-model erosion solver. |
| Unity | Official add-on | Package Manager > Terrain Tools > Paint Terrain > Erosion > Hydraulic (GPU hydraulic and thermal erosion brush) docs Official Terrain Tools package. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
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 when you need layered strata and artist control over rock hardness, and Stream-Power Erosion (Fluvial Terrain Uplift) when you need large-scale, resolution-independent drainage rather than local gullies.
Field marks
- 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
Presets
GPU Pipe-Model Erosion — virtual-pipe flux & water depth map (left) vs active flowing shallow-water channels (right)
{
"P_RAINFALL": 0.78,
"P_FLOW_SPEED": 1,
"P_CARVE_DEPTH": 0.85,
"P_SPLIT": 0.46
}Show GLSL (116 lines)
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.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| gpu-pipe-model-erosion-live | Tesla T4 1920x1080 | 109× baseline (extreme) · 3.57 ms / 3.81 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| gpu-pipe-model-erosion-live | NVIDIA L4 1920x1080 | 98.3× baseline (extreme) · 1.56 ms / 1.57 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| gpu-pipe-model-erosion-live | NVIDIA A100-SXM4-40GB 1920x1080 | 80.3× baseline (extreme) · 2.31 ms / 2.33 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Shallow Water Equations (Height-field Water), Weathering simulation (weathered stone), Stable Fluids.
Crosses
- Overhang-capable voxel erosion with pipe-model water: Interactive hydraulic erosion that carves real 3D caves, undercut banks, and collapsing arches instead of flat 2.5D heightfields. A fast pipe-model water solver drives surface runoff and scouring, a mass-conserving 3D Margolus cellular automaton moves loosened sand and rock voxels through overhangs, and exact DDA ray traversal renders the evolving volume with zero remeshing.
Sources
- primaryXing 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).Verified via crossref · 2026-11-29doi:10.1109/pg.2007.15
- implementationdandrino (2018). dandrino/terrain-erosion-3-ways. Three Ways of Generating Terrain with Erosion FeaturesGitHub API · license MIT · 2026-11-29