{
 "id": "geometry-clipmaps-terrain",
 "title": "Geometry clipmaps",
 "aliases": [
  "clipmap terrain",
  "geometry clipmap"
 ],
 "domain": "performance",
 "subdomain": "terrain LOD",
 "stage": "performance",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "unity",
  "unreal"
 ],
 "year_introduced": 2004,
 "inputs": [
  "heightfield"
 ],
 "outputs": [
  "mesh"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Cache terrain heights as a stack of nested, camera-centered regular grids of equal size but doubling spacing, updated incrementally as the viewer moves.",
 "how_it_works": "Each LOD level is a square window of the heightmap of fixed vertex count; level k covers twice the world extent of level k-1 at half the sampling density. All levels are centered on the viewer, so detail falls off roughly with distance and the triangle count is nearly constant.\n\nAs the camera moves, each level shifts in toroidal fashion: only the strip of new rows and columns entering the window is uploaded or generated, the rest is reused. Because the grids are regular, they are drawn as instanced ring meshes with heights fetched in the vertex shader.\n\nSeams between levels are hidden by blending heights over a transition band at each ring's outer edge (geomorphing) and by stitching or skirt triangles; the original also compresses the height data and synthesizes extra detail at the finest levels.",
 "when_to_use": "Choose it for very large heightfield terrain viewed from near the ground, when you want constant triangle budget and no CPU quadtree traversal. Prefer `cdlod-terrain` when you want adaptive detail per quadtree node (flat areas cost less) and smoother per-node morphing. Prefer `nanite-virtualized-geometry` when terrain is arbitrary mesh rather than a heightfield, and use `hydraulic-erosion-stava` style data as the height source.",
 "cost": {
  "class": "cheap",
  "notes": "Fixed vertex budget per frame, mostly vertex-texture fetch cost; update cost is proportional to camera movement."
 },
 "failure_modes": [
  "Cannot represent overhangs, caves or cliffs, since terrain is a single-valued height function",
  "Vertices swim or visibly pop when the clip window snaps and morphing is too short",
  "Cracks between rings if stitching and morph ranges disagree",
  "Uniform detail in flat regions wastes triangles compared with adaptive schemes",
  "Normals computed from coarse levels look faceted unless a separate normal map is used"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/1015706.1015799",
   "type": "paper",
   "title": "Geometry clipmaps",
   "authors": [
    "Frank Losasso",
    "Hugues Hoppe"
   ],
   "year": 2004,
   "venue": "ACM Transactions on Graphics",
   "url": "https://doi.org/10.1145/1015706.1015799",
   "ids": {
    "doi": "10.1145/1015706.1015799"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1015706.1015799",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1015706.1015799",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1015706.1015799",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1015706.1015799",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1015706.1015799",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "losasso2004geometry"
  }
 ],
 "presets": [
  {
   "id": "geometry-clipmaps-terrain-live",
   "title": "Geometry Clipmaps — nested doubling LOD rings & morph bands (left) vs blended alpine terrain (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_RING_SCALE": 1,
    "P_WIRE_GAIN": 0.9,
    "P_CAM_SPEED": 0.7,
    "P_SPLIT": 0.5
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_RING_SCALE = 1.0; // P Clipmap Scale [0.5, 2.0, 0.05]\nconst float P_WIRE_GAIN = 0.90; // P Grid Wireframe [0.0, 1.5, 0.05]\nconst float P_CAM_SPEED = 0.70; // P Flyover Speed [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.50; // P LOD Rings / Lit Split [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 noise2(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  f = f * f * (3.0 - 2.0 * f);\n  return mix(\n    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), f.x),\n    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), f.x),\n    f.y\n  );\n}\n\n// Multi-octave ridged alpine terrain heightfield\nfloat terrainH(vec2 p) {\n  float h = 0.0;\n  float amp = 0.55;\n  float freq = 0.45;\n  for (int i = 0; i < 5; i++) {\n    float n = 1.0 - abs(noise2(p * freq) * 2.0 - 1.0);\n    h += n * n * amp;\n    p = mat2(0.8, 0.6, -0.6, 0.8) * p;\n    freq *= 2.05;\n    amp *= 0.48;\n  }\n  return h - 0.58;\n}\n\nvec3 terrainNormal(vec2 p) {\n  float e = 0.025;\n  float hx = terrainH(p + vec2(e, 0.0)) - terrainH(p - vec2(e, 0.0));\n  float hz = terrainH(p + vec2(0.0, e)) - terrainH(p - vec2(0.0, e));\n  return normalize(vec3(-hx, 2.0 * e, -hz));\n}\n\nvec3 lodPalette(float lvl) {\n  if (lvl < 0.5) return vec3(0.18, 0.90, 0.82); // L0 finest\n  if (lvl < 1.5) return vec3(0.28, 0.72, 0.98); // L1 2x\n  if (lvl < 2.5) return vec3(0.96, 0.78, 0.22); // L2 4x\n  if (lvl < 3.5) return vec3(0.96, 0.44, 0.20); // L3 8x\n  return vec3(0.76, 0.30, 0.88);                // L4 16x\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 isLit = screenX >= split;\n  float ringScale = clamp(P_RING_SCALE, 0.45, 2.2);\n  float wireGain = clamp(P_WIRE_GAIN, 0.0, 1.5);\n  float flyZ = -iTime * max(P_CAM_SPEED, 0.0) * 1.1;\n\n  vec3 ro = vec3(0.0, 1.85, 2.2 + flyZ);\n  vec3 ta = vec3(0.0, 0.15, -3.2 + flyZ);\n  vec3 fwd = normalize(ta - ro);\n  vec3 right = normalize(cross(fwd, vec3(0.0, 1.0, 0.0)));\n  vec3 up = cross(right, fwd);\n  vec3 rd = normalize(fwd * 1.45 + right * uv.x + up * uv.y);\n\n  // Horizon sky\n  vec3 skyCol = mix(vec3(0.46, 0.62, 0.82), vec3(0.10, 0.20, 0.42), smoothstep(-0.08, 0.55, rd.y));\n  vec3 col = skyCol;\n\n  // Raymarch heightfield terrain\n  float t = 0.2;\n  bool hit = false;\n  for (int i = 0; i < 80; i++) {\n    vec3 p = ro + rd * t;\n    float h = terrainH(p.xz);\n    float d = p.y - h;\n    if (d < 0.008 * t) { hit = true; break; }\n    t += max(d * 0.55, 0.035);\n    if (t > 26.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = terrainNormal(p.xz);\n    vec3 lDir = normalize(vec3(0.62, 0.68, 0.40));\n    float diff = max(dot(n, lDir), 0.0);\n\n    // Clipmap center anchored on camera XZ footprint: Chebyshev L-infinity square rings!\n    vec2 rel = abs(p.xz - ro.xz) / ringScale;\n    float cheb = max(rel.x, rel.y);\n    float contLvl = max(log2(max(cheb * 0.48, 0.5)), 0.0);\n    float lvl = floor(contLvl);\n    float ringFrac = fract(contLvl);\n\n    // Doubling grid cell spacing per clipmap level: 2^lvl * baseSpacing\n    float spacing = 0.18 * pow(2.0, min(lvl, 5.0)) * ringScale;\n    vec2 gUV = p.xz / spacing;\n    vec2 gf = abs(fract(gUV - 0.5) - 0.5);\n    float wire = smoothstep(0.075, 0.015, min(gf.x, gf.y));\n    // Diagonal triangle split edge inside each clipmap quad\n    float diag = smoothstep(0.06, 0.012, abs(fract(gUV.x + gUV.y) - 0.5));\n    wire = max(wire, diag * 0.45);\n\n    // Highlight concentric square ring transition morph band (outer 15% of each ring)\n    float morphBand = smoothstep(0.82, 0.96, ringFrac);\n    float ringSeam = smoothstep(0.04, 0.008, abs(ringFrac - 0.98));\n\n    // Natural alpine coloring (valley forest -> rock -> snow peaks)\n    float snow = smoothstep(0.08, 0.36, p.y) * smoothstep(0.45, 0.78, n.y);\n    vec3 ground = mix(vec3(0.16, 0.28, 0.18), vec3(0.38, 0.35, 0.32), smoothstep(-0.22, 0.16, p.y));\n    ground = mix(ground, vec3(0.92, 0.95, 0.98), snow);\n    vec3 litTerrain = ground * (0.24 + 0.92 * diff) + vec3(0.12, 0.20, 0.34) * (0.5 + 0.5 * n.y) * 0.28;\n\n    if (!isLit) {\n      // Left: nested clipmap LOD rings color-coded with doubling grid resolution & morph bands\n      vec3 ringCol = lodPalette(lvl);\n      vec3 nextCol = lodPalette(lvl + 1.0);\n      vec3 lodMix = mix(ringCol, nextCol, morphBand * 0.65);\n      col = mix(litTerrain * 0.42, lodMix * (0.35 + 0.75 * diff), 0.74);\n      col = mix(col, vec3(0.03, 0.05, 0.09), wire * 0.68 * min(wireGain, 1.2));\n      col = mix(col, vec3(1.0, 0.98, 0.85), ringSeam * 0.85);\n    } else {\n      // Right: seamless shaded terrain with subtle morph-band wireframe hint\n      col = litTerrain;\n      col = mix(col, vec3(0.10, 0.16, 0.24), wire * 0.12 * min(wireGain, 1.0));\n    }\n\n    float fog = 1.0 - exp(-t * t * 0.0045);\n    col = mix(col, skyCol, clamp(fog, 0.0, 0.88));\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": "geometry-clipmaps-terrain",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:27.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7549,
      "std": 0.0833,
      "min": 0.4626,
      "max": 0.9087
     },
     "image": "/specimens/geometry-clipmaps-terrain-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "cdlod-terrain",
  "nanite-virtualized-geometry",
  "hydraulic-erosion-stava",
  "virtual-texturing"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "virtual-texturing",
   "why": "Clipmap rings give a camera-centered mesh whose color and normals come from a streamed virtual texture."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/performance/geometry-clipmaps-terrain.json"
 },
 "solves": [
  "terrain mesh needs lod around the camera",
  "huge heightmap rendering with constant triangle count",
  "terrain vertices pop when lod changes",
  "open world ground detail near viewer only",
  "avoid cpu quadtree traversal for terrain"
 ],
 "authority": "Losasso & Hoppe, 2004",
 "url": "https://texelatlas.vercel.app/t/geometry-clipmaps-terrain/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 181.9,
  "tier": "extreme",
  "p50_ms": 5.6388,
  "p95_ms": 5.739,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "geometry-clipmaps-terrain-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 163.19,
   "tier": "extreme",
   "p50_ms": 2.5948,
   "p95_ms": 2.6071,
   "speedup_x": 2.17,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 132.66,
   "tier": "extreme",
   "p50_ms": 3.8205,
   "p95_ms": 3.8483,
   "speedup_x": 1.48,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}