{
 "id": "thermal-erosion",
 "title": "Thermal (Talus) Erosion",
 "aliases": [
  "thermal weathering",
  "talus relaxation"
 ],
 "domain": "procgen",
 "subdomain": "terrain erosion",
 "stage": "procedural",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cpu",
  "houdini",
  "unity",
  "unreal",
  "godot",
  "python"
 ],
 "year_introduced": 1989,
 "inputs": [
  "heightfield"
 ],
 "outputs": [
  "heightfield"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Iteratively moves material from a cell to lower neighbours wherever the slope exceeds an angle of repose, softening steep noise-generated cliffs into talus slopes and aprons.",
 "how_it_works": "For every cell of a heightfield, compare its height with each of its 4 or 8 neighbours. If the drop to a neighbour exceeds the talus threshold (tan of the repose angle times cell spacing), a fraction of the excess is moved to that neighbour, split among all lower neighbours in proportion to their drop. Repeating the pass lets slopes relax toward the threshold angle. It is local, deterministic and embarrassingly parallel, which makes it a GPU-friendly ping-pong pass. Variants add a hardness map so rock layers resist erosion, or move material only when the slope is under a maximum so cliffs are preserved. Musgrave's 1989 paper introduced it alongside hydraulic erosion on fractal terrain.",
 "when_to_use": "Choose it as a cheap finishing pass to knock the spikes off `fractal-brownian-motion` terrain and to build scree slopes under cliffs. Prefer `hydraulic-erosion-stava` or `gpu-pipe-model-erosion` when you need river valleys and sediment deposition, and `stream-power-erosion` for large-scale drainage-driven mountain shapes.",
 "cost": {
  "class": "cheap",
  "notes": "One neighbourhood pass per iteration; dozens to hundreds of iterations are typical for convincing talus, so total cost scales with iteration count."
 },
 "failure_modes": [
  "Few iterations leave the original noise visible; many iterations over-smooth the entire terrain into a blob",
  "Grid-aligned diamond or square slope artifacts with 4-neighbour variants",
  "Without a hardness mask all rock behaves like sand, so crisp cliff bands vanish",
  "Mass is only conserved if transfers are symmetric; naive in-place updates leak or create height"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/74334.74337",
   "type": "paper",
   "title": "The synthesis and rendering of eroded fractal terrains",
   "authors": [
    "F. K. Musgrave",
    "C. E. Kolb",
    "R. S. Mace"
   ],
   "year": 1989,
   "venue": "ACM SIGGRAPH Computer Graphics",
   "url": "https://doi.org/10.1145/74334.74337",
   "ids": {
    "doi": "10.1145/74334.74337"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/74334.74337",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/74334.74337",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/74334.74337",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/74334.74337",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/74334.74337",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "musgrave1989synthesis"
  },
  {
   "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": "thermal-erosion-live",
   "title": "Thermal (Talus) Erosion — steep unstable cliffs > talus angle (left) vs relaxed scree aprons (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_TALUS_SLOPE": 0.65,
    "P_RELAX_AMT": 0.85,
    "P_CAM_ORBIT": 0.38,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_TALUS_SLOPE = 0.65; // P Critical Talus [0.25, 1.2, 0.04]\nconst float P_RELAX_AMT = 0.85; // P Thermal Slump [0.1, 1.0, 0.02]\nconst float P_CAM_ORBIT = 0.38; // P Orbit Speed [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P Steep / Talus Split [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\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// Raw steep mesa / jagged butte formation with vertical cliff walls exceeding talus angle\nfloat rawButte(vec2 p) {\n  float r1 = length(p - vec2(-0.35, -0.10));\n  float r2 = length(p - vec2(0.45, 0.18));\n  float jagged = vnoise(p * 2.4) * 0.26 + vnoise(p * 5.6) * 0.10;\n  // Steep sheer cliffs\n  float m1 = smoothstep(0.95, 0.42, r1 + jagged * 0.55) * 0.92;\n  float m2 = smoothstep(0.78, 0.34, r2 + jagged * 0.45) * 0.72;\n  return max(m1, m2) + jagged * 0.35 - 0.36;\n}\n\n// Thermal-erosion talus relaxation: material slumps downslope to form smooth constant-slope scree cones!\nvec2 talusButte(vec2 p, float talusTan, float relaxAmt) {\n  float hRaw = rawButte(p);\n  // 9-tap neighborhood slope-limited relaxation simulating iterative talus diffusion\n  float hSmooth = 0.0;\n  float hMax = hRaw;\n  float rad = 0.24 * relaxAmt / max(talusTan, 0.25);\n  for (int dy = -1; dy <= 1; dy++) {\n    for (int dx = -1; dx <= 1; dx++) {\n      vec2 off = vec2(float(dx), float(dy)) * rad;\n      float hn = rawButte(p + off);\n      float dist = length(off);\n      // Cone-of-repose lower bound: material from higher neighbor slides down at angle tan(alpha)\n      float talusBound = hn - dist * talusTan * 0.85;\n      hMax = max(hMax, talusBound);\n      hSmooth += hn;\n    }\n  }\n  hSmooth /= 9.0;\n  float hRelax = mix(hRaw, max(hSmooth * 0.65 + hRaw * 0.35, hMax), relaxAmt);\n  float screeMask = clamp((hRelax - hRaw) * 7.5, 0.0, 1.0);\n  return vec2(hRelax, screeMask);\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 isThermal = screenX >= split;\n  float talus = clamp(P_TALUS_SLOPE, 0.2, 1.4);\n  float relax = clamp(P_RELAX_AMT, 0.05, 1.0);\n  float spin = iTime * max(P_CAM_ORBIT, 0.0) * 0.35;\n\n  vec3 ro = vec3(0.0, 1.18, 2.48);\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.92, 0.68, 0.48), vec3(0.20, 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 = isThermal ? talusButte(p.xz, talus, relax).x : rawButte(p.xz);\n    float d = p.y - h;\n    if (d < 0.008) { hit = true; break; }\n    t += max(d * 0.42, 0.025);\n    if (t > 12.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    float e = 0.016;\n    vec2 val = isThermal ? talusButte(p.xz, talus, relax) : vec2(rawButte(p.xz), 0.0);\n    float hx = isThermal ? talusButte(p.xz + vec2(e, 0.0), talus, relax).x : rawButte(p.xz + vec2(e, 0.0));\n    float hz = isThermal ? talusButte(p.xz + vec2(0.0, e), talus, relax).x : rawButte(p.xz + vec2(0.0, e));\n    vec3 n = normalize(vec3((val.x - hx) / e, 1.0, (val.x - hz) / e));\n\n    vec3 sunDir = normalize(vec3(0.68, 0.55, 0.48));\n    float diff = max(dot(n, sunDir), 0.0);\n    // Tangent of local terrain slope = |grad h| = sqrt(1 - n.y^2) / n.y\n    float tanSlope = length(n.xz) / max(n.y, 0.05);\n    float overTalus = smoothstep(talus * 0.85, talus * 1.45, tanSlope);\n\n    // Desert sandstone strata on bedrock vs loose pale gravel scree on talus aprons\n    float strata = 0.5 + 0.5 * sin(val.x * 36.0 + vnoise(p.xz * 4.0) * 2.0);\n    vec3 bedrock = mix(vec3(0.58, 0.30, 0.20), vec3(0.78, 0.48, 0.30), strata);\n    vec3 scree = mix(vec3(0.62, 0.54, 0.44), vec3(0.76, 0.68, 0.56), vnoise(p.xz * 18.0));\n    vec3 floorSand = vec3(0.74, 0.58, 0.42);\n\n    vec3 alb = mix(floorSand, bedrock, smoothstep(-0.22, 0.12, val.x));\n    if (isThermal) {\n      alb = mix(alb, scree, clamp(val.y * 0.92, 0.0, 0.95));\n    } else {\n      // On left side, highlight unstable cliffs exceeding critical talus angle in warning red-orange!\n      alb = mix(alb, vec3(0.98, 0.24, 0.16), overTalus * 0.62);\n    }\n\n    vec3 lit = alb * (0.25 + 0.90 * diff) + vec3(0.24, 0.34, 0.52) * 0.18 * (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": "thermal-erosion",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:57.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.8152,
      "std": 0.0499,
      "min": 0.6039,
      "max": 0.9014
     },
     "image": "/specimens/thermal-erosion-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "fractal-brownian-motion",
  "hydraulic-erosion-stava",
  "gpu-pipe-model-erosion",
  "stream-power-erosion"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "gpu-pipe-model-erosion",
   "why": "Thermal relaxation runs after the hydraulic step to stabilise steep banks the water pass carves."
  }
 ],
 "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/thermal-erosion.json"
 },
 "solves": [
  "noise terrain has spiky steep cliffs",
  "need scree slopes under cliffs",
  "want a cheap finishing pass to soften peaks",
  "slopes steeper than angle of repose look fake"
 ],
 "authority": "Musgrave et al., 1989",
 "url": "https://texelatlas.vercel.app/t/thermal-erosion/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 511.23,
  "tier": "extreme",
  "p50_ms": 16.8195,
  "p95_ms": 17.145,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 16,
  "preset_id": "thermal-erosion-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 432.01,
   "tier": "extreme",
   "p50_ms": 6.869,
   "p95_ms": 6.9927,
   "speedup_x": 2.45,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 367.91,
   "tier": "extreme",
   "p50_ms": 10.5958,
   "p95_ms": 10.7293,
   "speedup_x": 1.59,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}