{
 "id": "hydraulic-erosion-stava",
 "title": "Interactive Hydraulic Erosion on Heightfields",
 "aliases": [
  "particle hydraulic erosion",
  "layered hydraulic erosion"
 ],
 "domain": "procgen",
 "subdomain": "terrain erosion",
 "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",
 "summary": "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.",
 "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": "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-erosion` for a fully GPU-resident implementation, `stream-power-erosion` when you need continent-scale drainage that is stable and fast, and `hydrology-terrain-synthesis` when rivers must be designed first and terrain derived from them.",
 "cost": {
  "class": "offline",
  "notes": "Many iterations over the entire grid; interactive for moderate resolutions on GPU, minutes to hours for large high-resolution terrains."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.2312/sca/sca08/201-210",
   "type": "paper",
   "title": "Interactive Terrain Modeling Using Hydraulic Erosion",
   "authors": [
    "Ondrej Stava",
    "Bedrich Benes",
    "Matthew Brisbin",
    "Jaroslav Krivanek"
   ],
   "year": 2008,
   "venue": "Eurographics/SIGGRAPH Symposium on Computer Animation",
   "url": "https://doi.org/10.2312/sca/sca08/201-210",
   "ids": {
    "doi": "10.2312/sca/sca08/201-210"
   },
   "license": null,
   "extra": {
    "csl_type": "article"
   },
   "provenance": {
    "title": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/sca/sca08/201-210 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/sca/sca08/201-210 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/sca/sca08/201-210 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/sca/sca08/201-210 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/sca/sca08/201-210 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "stava2008interactive"
  },
  {
   "role": "implementation",
   "key": "gh:seblague/hydraulic-erosion",
   "type": "code",
   "title": "SebLague/Hydraulic-Erosion",
   "description": "",
   "authors": [
    "SebLague"
   ],
   "year": 2019,
   "venue": "GitHub",
   "url": "https://github.com/SebLague/Hydraulic-Erosion",
   "ids": {
    "repo": "SebLague/Hydraulic-Erosion"
   },
   "license": "MIT",
   "extra": {
    "stars": 1047,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2024-01-04T21:38:11Z",
    "language": "C#",
    "homepage": "https://www.youtube.com/watch?v=eaXk97ujbPQ",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/SebLague/Hydraulic-Erosion",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/SebLague/Hydraulic-Erosion",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/SebLague/Hydraulic-Erosion",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/SebLague/Hydraulic-Erosion",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/SebLague/Hydraulic-Erosion",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/SebLague/Hydraulic-Erosion",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "seblague2019seblague"
  },
  {
   "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": "hydraulic-erosion-stava-live",
   "title": "Hydraulic Erosion — raw fBm heightfield (left) vs carved dendritic gullies & alluvial sediment (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_EROSION": 0.85,
    "P_SEDIMENT": 0.72,
    "P_CAM_ORBIT": 0.4,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_EROSION = 0.85; // P Gully Erosion [0.05, 1.3, 0.04]\nconst float P_SEDIMENT = 0.72; // P Sediment Fan [0.0, 1.2, 0.04]\nconst float P_CAM_ORBIT = 0.40; // P Orbit Speed [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P Raw fBm / Eroded [0.0, 1.0, 0.02]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\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\n// Value noise returning (value, d/dx, d/dz) analytical gradient for gradient-advected hydraulic erosion\nvec3 noiseD(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  vec2 u = f * f * (3.0 - 2.0 * f);\n  vec2 du = 6.0 * f * (1.0 - f);\n  float a = hash21(i);\n  float b = hash21(i + vec2(1.0, 0.0));\n  float c = hash21(i + vec2(0.0, 1.0));\n  float d = hash21(i + vec2(1.0, 1.0));\n  float v = a + (b - a) * u.x + (c - a) * u.y + (a - b - c + d) * u.x * u.y;\n  vec2 g = du * vec2((b - a) + (a - b - c + d) * u.y, (c - a) + (a - b - c + d) * u.x);\n  return vec3(v, g);\n}\n\n// Raw un-eroded mountain fBm\nfloat rawTerrain(vec2 p) {\n  float h = 0.0, amp = 0.55;\n  vec2 q = p * 0.78;\n  for (int i = 0; i < 4; i++) {\n    h += amp * noiseD(q).x;\n    q = rot2(0.55) * q * 2.02 + vec2(3.7, 1.9);\n    amp *= 0.48;\n  }\n  float peak = exp(-dot(p, p) * 0.42) * 0.85;\n  return h * 0.65 + peak - 0.52;\n}\n\n// Hydraulically eroded heightfield using analytical slope-driven ridge & dendritic gully carving (returns height, sediment)\nvec2 erodedTerrain(vec2 p, float eroStr, float sedStr) {\n  float h = 0.0, amp = 0.55;\n  vec2 gradAcc = vec2(0.0);\n  float gullyAcc = 0.0;\n  vec2 q = p * 0.78;\n  mat2 m = rot2(0.55);\n\n  for (int i = 0; i < 5; i++) {\n    vec3 nd = noiseD(q);\n    gradAcc += nd.yz * amp;\n    float slope = length(gradAcc);\n    // Steep slopes erode sharp concave dendritic gullies; flat basins accumulate smooth sediment\n    float ridge = 1.0 - abs(nd.x * 2.0 - 1.0);\n    float carve = (ridge * ridge) / (1.0 + slope * 3.8 * eroStr);\n    h += amp * mix(nd.x, carve, clamp(eroStr * 0.85, 0.0, 1.0));\n    gullyAcc += amp * (nd.x - carve) * eroStr;\n    q = m * q * 2.04 + vec2(3.7, 1.9) + gradAcc * 0.14 * eroStr;\n    amp *= 0.48;\n  }\n  float r2 = dot(p, p);\n  float peak = exp(-r2 * 0.42) * 0.85;\n  // Alluvial sediment deposition apron around base foothills\n  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);\n  float height = h * 0.65 + peak - 0.52 + sedMask * 0.06;\n  return vec2(height, sedMask);\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 isEroded = screenX >= split;\n  float ero = clamp(P_EROSION, 0.05, 1.4);\n  float sed = clamp(P_SEDIMENT, 0.0, 1.4);\n  float spin = iTime * max(P_CAM_ORBIT, 0.0) * 0.35;\n\n  vec3 ro = vec3(0.0, 1.25, 2.55);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.34, -1.35));\n  ro.xz = rot2(spin) * ro.xz;\n  rd.xz = rot2(spin) * rd.xz;\n\n  vec3 sky = mix(vec3(0.86, 0.72, 0.58), vec3(0.18, 0.38, 0.68), 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    float h = isEroded ? erodedTerrain(p.xz, ero, sed).x : rawTerrain(p.xz);\n    float d = p.y - h;\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.015;\n    vec2 cVal = isEroded ? erodedTerrain(p.xz, ero, sed) : vec2(rawTerrain(p.xz), 0.0);\n    float hx = isEroded ? erodedTerrain(p.xz + vec2(e, 0.0), ero, sed).x : rawTerrain(p.xz + vec2(e, 0.0));\n    float hz = isEroded ? erodedTerrain(p.xz + vec2(0.0, e), ero, sed).x : rawTerrain(p.xz + vec2(0.0, e));\n    vec3 n = normalize(vec3((cVal.x - hx) / e, 1.0, (cVal.x - hz) / e));\n\n    vec3 sunDir = normalize(vec3(0.68, 0.56, 0.46));\n    float diff = max(dot(n, sunDir), 0.0);\n    float slope = 1.0 - n.y;\n\n    // Geologic strata: dark granite rock on steep eroded cliffs, ochre alluvial sediment in gullies/fans, snow peaks\n    vec3 rock = mix(vec3(0.28, 0.26, 0.25), vec3(0.48, 0.44, 0.40), smoothstep(0.15, 0.55, slope));\n    vec3 grass = vec3(0.22, 0.40, 0.20);\n    vec3 sedimentCol = vec3(0.76, 0.56, 0.34);\n    vec3 snow = vec3(0.92, 0.94, 0.98);\n\n    vec3 alb = mix(grass, rock, smoothstep(0.14, 0.38, slope));\n    if (isEroded) {\n      alb = mix(alb, sedimentCol, clamp(cVal.y * 0.85, 0.0, 0.85));\n    }\n    alb = mix(alb, snow, smoothstep(0.44, 0.66, cVal.x) * smoothstep(0.45, 0.16, slope));\n\n    vec3 lit = alb * (0.24 + 0.92 * diff) + vec3(0.20, 0.34, 0.56) * 0.20 * (0.5 + 0.5 * n.y);\n    col = mix(lit, 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": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "hydraulic-erosion-stava",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:50.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.816,
      "std": 0.0444,
      "min": 0.6115,
      "max": 0.9014
     },
     "image": "/specimens/hydraulic-erosion-stava-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "gpu-pipe-model-erosion",
  "thermal-erosion",
  "stream-power-erosion",
  "hydrology-terrain-synthesis",
  "fractal-brownian-motion"
 ],
 "extends": [
  "gpu-pipe-model-erosion"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "fractal-brownian-motion",
   "why": "The noise heightfield is the initial terrain that erosion refines."
  }
 ],
 "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/hydraulic-erosion-stava.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Stava et al., 2008",
 "url": "https://texelatlas.vercel.app/t/hydraulic-erosion-stava/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 251.29,
  "tier": "extreme",
  "p50_ms": 8.2673,
  "p95_ms": 8.3171,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "hydraulic-erosion-stava-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 224.28,
   "tier": "extreme",
   "p50_ms": 3.5661,
   "p95_ms": 3.5927,
   "speedup_x": 2.32,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 184.71,
   "tier": "extreme",
   "p50_ms": 5.3197,
   "p95_ms": 5.3705,
   "speedup_x": 1.55,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}