{
 "id": "gpu-pipe-model-erosion",
 "title": "GPU Pipe-Model Hydraulic Erosion",
 "aliases": [
  "virtual pipes erosion",
  "Mei et al. erosion"
 ],
 "domain": "procgen",
 "subdomain": "terrain erosion",
 "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",
 "summary": "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.",
 "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": "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 `hydraulic-erosion-stava` when you need layered strata and artist control over rock hardness, and `stream-power-erosion` when you need large-scale, resolution-independent drainage rather than local gullies.",
 "cost": {
  "class": "medium",
  "notes": "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."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1109/pg.2007.15",
   "type": "paper",
   "title": "Fast Hydraulic Erosion Simulation and Visualization on GPU",
   "authors": [
    "Xing Mei",
    "Philippe Decaudin",
    "Bao-Gang Hu"
   ],
   "year": 2007,
   "venue": "15th Pacific Conference on Computer Graphics and Applications (PG'07)",
   "url": "https://doi.org/10.1109/pg.2007.15",
   "ids": {
    "doi": "10.1109/pg.2007.15"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/pg.2007.15",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/pg.2007.15",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/pg.2007.15",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/pg.2007.15",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/pg.2007.15",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "mei2007fast"
  },
  {
   "role": "implementation",
   "key": "gh:dandrino/terrain-erosion-3-ways",
   "type": "code",
   "title": "dandrino/terrain-erosion-3-ways",
   "description": "Three Ways of Generating Terrain with Erosion Features",
   "authors": [
    "dandrino"
   ],
   "year": 2018,
   "venue": "GitHub",
   "url": "https://github.com/dandrino/terrain-erosion-3-ways",
   "ids": {
    "repo": "dandrino/terrain-erosion-3-ways"
   },
   "license": "MIT",
   "extra": {
    "stars": 964,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2022-11-22T07:53:38Z",
    "language": "Python",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/dandrino/terrain-erosion-3-ways",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/dandrino/terrain-erosion-3-ways",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/dandrino/terrain-erosion-3-ways",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/dandrino/terrain-erosion-3-ways",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/dandrino/terrain-erosion-3-ways",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/dandrino/terrain-erosion-3-ways",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "dandrino2018dandrino"
  }
 ],
 "presets": [
  {
   "id": "gpu-pipe-model-erosion-live",
   "title": "GPU Pipe-Model Erosion — virtual-pipe flux & water depth map (left) vs active flowing shallow-water channels (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_RAINFALL": 0.78,
    "P_FLOW_SPEED": 1,
    "P_CARVE_DEPTH": 0.85,
    "P_SPLIT": 0.46
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_RAINFALL = 0.78; // P Water Flux [0.1, 1.4, 0.04]\nconst float P_FLOW_SPEED = 1.0; // P Flow Velocity [0.0, 2.5, 0.05]\nconst float P_CARVE_DEPTH = 0.85; // P Channel Carve [0.1, 1.4, 0.04]\nconst float P_SPLIT = 0.46; // P Flux Map / Water 3D [0.0, 1.0, 0.02]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\nfloat vnoise(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  vec2 u = f * f * (3.0 - 2.0 * f);\n  return mix(\n    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),\n    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),\n    u.y\n  );\n}\n\n// Compute terrain height + shallow-water pipe channel mask + downstream flow coordinate\nvec3 evalPipeBasin(vec2 xz, float carve, float rain) {\n  // Sloping alpine watershed draining from -z toward +z\n  float baseSlope = -xz.y * 0.24 + 0.12 * abs(xz.x);\n  // Two braided meandering river channels converging into a main trunk\n  float mainRiver = abs(xz.x - 0.34 * sin(xz.y * 1.45 + 0.4));\n  float tribRiver = abs((xz.x - 0.58) + (xz.y + 0.4) * 0.42 - 0.14 * sin(xz.y * 2.8));\n  float dChan = min(mainRiver, tribRiver * 1.15);\n\n  float hills = vnoise(xz * 1.2) * 0.48 + vnoise(xz * 2.7) * 0.18 + vnoise(xz * 5.8) * 0.06;\n  float channelCut = exp(-dChan * dChan * 18.0) * 0.34 * carve;\n  float terrainH = baseSlope + hills - channelCut - 0.38;\n\n  // Shallow-water column height d(x,z) concentrated in pipe channels + sheet-flow tributaries\n  float waterD = exp(-dChan * dChan * 22.0) * 0.16 * rain;\n  float rills = smoothstep(0.62, 0.88, sin(xz.x * 10.0 + hills * 8.0) * 0.5 + 0.5) * 0.03 * rain;\n  waterD += rills * smoothstep(0.08, 0.35, dChan);\n  return vec3(terrainH, waterD, dChan);\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isFluxVis = screenX < split;\n  float rain = clamp(P_RAINFALL, 0.08, 1.6);\n  float flowT = iTime * max(P_FLOW_SPEED, 0.0);\n  float carve = clamp(P_CARVE_DEPTH, 0.1, 1.5);\n\n  vec3 ro = vec3(0.0, 1.28, 2.30);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.38, -1.32));\n  vec3 sky = mix(vec3(0.66, 0.78, 0.90), vec3(0.14, 0.32, 0.62), smoothstep(-0.08, 0.52, rd.y));\n  vec3 col = sky;\n\n  float t = 0.2;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec3 p = ro + rd * t;\n    vec3 b = evalPipeBasin(p.xz, carve, rain);\n    float d = p.y - (b.x + b.y * 0.55);\n    if (d < 0.008) { hit = true; break; }\n    t += max(d * 0.45, 0.025);\n    if (t > 12.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    float e = 0.018;\n    vec3 bC = evalPipeBasin(p.xz, carve, rain);\n    float hX = evalPipeBasin(p.xz + vec2(e, 0.0), carve, rain).x;\n    float hZ = evalPipeBasin(p.xz + vec2(0.0, e), carve, rain).x;\n    vec3 n = normalize(vec3((bC.x - hX) / e, 1.0, (bC.x - hZ) / e));\n\n    vec3 sunDir = normalize(vec3(0.60, 0.72, 0.42));\n    float diff = max(dot(n, sunDir), 0.0);\n    float wet = smoothstep(0.018, 0.095, bC.y);\n    float flowRipple = 0.5 + 0.5 * sin(p.z * 26.0 - flowT * 5.2 + sin(p.x * 12.0));\n\n    if (isFluxVis) {\n      // Left: Virtual-pipe grid cells & shallow-water velocity flux heatmap\n      vec2 grid = abs(fract(p.xz * 6.0) - 0.5);\n      float cellLine = smoothstep(0.055, 0.015, min(grid.x, grid.y));\n      float flux = clamp(bC.y * 8.5, 0.0, 1.0);\n      vec3 heat = mix(vec3(0.07, 0.11, 0.18), vec3(0.08, 0.76, 0.94), smoothstep(0.0, 0.55, flux));\n      heat = mix(heat, vec3(0.98, 0.86, 0.24), smoothstep(0.50, 0.95, flux));\n      heat *= (0.48 + 0.65 * diff);\n      // Animated downstream pipe-flux dashes\n      float pulse = smoothstep(0.55, 0.92, flowRipple) * flux;\n      col = heat + vec3(0.95, 0.98, 1.0) * pulse * 0.48 + vec3(0.18, 0.34, 0.50) * cellLine * 0.35;\n    } else {\n      // Right: Shaded carved basin with glistening shallow-water river & suspended sediment foam\n      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));\n      vec3 bank = vec3(0.24, 0.42, 0.22);\n      vec3 ground = mix(bank, rock, smoothstep(0.10, 0.35, 1.0 - n.y));\n      vec3 waterCol = mix(vec3(0.06, 0.36, 0.48), vec3(0.18, 0.76, 0.86), flowRipple * 0.45 + 0.35);\n      vec3 alb = mix(ground, waterCol, wet);\n      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));\n      float spec = pow(max(dot(nW, normalize(sunDir - rd)), 0.0), 48.0) * wet;\n      col = alb * (0.26 + 0.86 * diff) + vec3(0.95, 0.98, 1.0) * spec * 0.95;\n      col += vec3(0.88, 0.94, 0.98) * smoothstep(0.75, 0.98, flowRipple) * wet * 0.22;\n    }\n    col = mix(col, sky, 1.0 - exp(-t * 0.075));\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "gpu-pipe-model-erosion",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:49.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7511,
      "std": 0.0714,
      "min": 0.6071,
      "max": 0.9305
     },
     "image": "/specimens/gpu-pipe-model-erosion-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "hydraulic-erosion-stava",
  "thermal-erosion",
  "stream-power-erosion"
 ],
 "extends": [
  "thermal-erosion"
 ],
 "supersedes": [],
 "combines_with": [],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/procgen/gpu-pipe-model-erosion.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Mei et al., 2007",
 "url": "https://texelatlas.vercel.app/t/gpu-pipe-model-erosion/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 108.59,
  "tier": "extreme",
  "p50_ms": 3.5727,
  "p95_ms": 3.813,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "gpu-pipe-model-erosion-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 98.31,
   "tier": "extreme",
   "p50_ms": 1.5631,
   "p95_ms": 1.5733,
   "speedup_x": 2.29,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 80.27,
   "tier": "extreme",
   "p50_ms": 2.3117,
   "p95_ms": 2.3296,
   "speedup_x": 1.55,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}