{
 "id": "cdlod-terrain",
 "title": "CDLOD terrain",
 "aliases": [
  "Continuous Distance-Dependent LOD",
  "CDLOD"
 ],
 "domain": "performance",
 "subdomain": "terrain LOD",
 "stage": "performance",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "unity",
  "unreal"
 ],
 "year_introduced": 2010,
 "inputs": [
  "heightfield"
 ],
 "outputs": [
  "mesh"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Select quadtree nodes by distance to the camera, draw each as the same small grid mesh, and morph vertices in the shader so every LOD change is continuous.",
 "how_it_works": "The heightmap is covered by a quadtree. Each frame, the tree is traversed from the root: a node is drawn at its level if the camera lies beyond that level's range, otherwise it splits into four children. Ranges are chosen per level, usually doubling, and nodes are also frustum-culled using min/max height bounds stored per node.\n\nEvery selected node renders one shared grid mesh, scaled and offset to the node. In the vertex shader the morph factor, derived from distance within the level's transition band, slides odd vertices onto the coarser grid, so geometry is identical to the parent's LOD at the boundary and no popping or stitching meshes are needed.\n\nNeighboring nodes at different levels agree at their shared edges because the morph reaches full by the range edge, which also removes T-junction cracks.",
 "when_to_use": "Choose it for heightfield terrain where you want a simple, robust LOD with no seam geometry and adaptive node selection, with ranges tunable per level. Prefer `geometry-clipmaps-terrain` when you want toroidal update of the height data and a fixed, flatter workload. Prefer `nanite-virtualized-geometry` for non-heightfield terrain. Use `hydraulic-erosion-stava` or `gpu-pipe-model-erosion` output as the input heightmap.",
 "cost": {
  "class": "cheap",
  "notes": "Node selection on CPU is tiny; GPU cost is a few hundred instanced grid draws with texture-fetched heights."
 },
 "failure_modes": [
  "Heightfield only: no overhangs or caves",
  "Range settings that do not cover the morph band cause visible LOD swimming near transitions",
  "Very distant flat areas still draw full-resolution nodes unless ranges are tuned",
  "Per-node min/max bounds must be recomputed if terrain is edited at runtime, or culling becomes wrong",
  "Texture and normal maps sampled at one LOD while the mesh morphs can show slight shading slide"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1080/2151237x.2009.10129287",
   "type": "paper",
   "title": "Continuous Distance-Dependent Level of Detail for Rendering Heightmaps",
   "authors": [
    "Filip Strugar"
   ],
   "year": 2009,
   "venue": "Journal of Graphics, GPU, and Game Tools",
   "url": "https://doi.org/10.1080/2151237x.2009.10129287",
   "ids": {
    "doi": "10.1080/2151237x.2009.10129287"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2009.10129287",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2009.10129287",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2009.10129287",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2009.10129287",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2009.10129287",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "strugar2009continuous"
  },
  {
   "role": "implementation",
   "key": "gh:fstrugar/cdlod",
   "type": "code",
   "title": "fstrugar/CDLOD",
   "description": "",
   "authors": [
    "fstrugar"
   ],
   "year": 2017,
   "venue": "GitHub",
   "url": "https://github.com/fstrugar/CDLOD",
   "ids": {
    "repo": "fstrugar/CDLOD"
   },
   "license": "MIT",
   "extra": {
    "stars": 245,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2018-03-11T02:32:20Z",
    "language": "C++",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/fstrugar/CDLOD",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/fstrugar/CDLOD",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/fstrugar/CDLOD",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/fstrugar/CDLOD",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/fstrugar/CDLOD",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/fstrugar/CDLOD",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "fstrugar2017fstrugar"
  }
 ],
 "presets": [
  {
   "id": "cdlod-terrain-live",
   "title": "CDLOD terrain — continuous distance-dependent quadtree morphing & LOD ring visualization",
   "runtime": "glsl-fragment",
   "params": {
    "P_LOD_BIAS": 1,
    "P_MORPH_BAND": 0.42,
    "P_GRID_OVERLAY": 0.82,
    "P_FLY_SPEED": 1
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_LOD_BIAS = 1.0; // P LOD Bias [0.4, 2.2, 0.05]\nconst float P_MORPH_BAND = 0.42; // P Morph Band [0.1, 0.85, 0.02]\nconst float P_GRID_OVERLAY = 0.82; // P Quadtree Grid [0.0, 1.5, 0.04]\nconst float P_FLY_SPEED = 1.0; // P Fly Speed [0.0, 2.5, 0.05]\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  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 alpine ridge heightfield with smooth LOD truncation\nfloat terrainHeight(vec2 p, float lodFloat) {\n  float h = 0.0;\n  float amp = 1.05;\n  float freq = 0.24;\n  mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);\n  vec2 q = p;\n  for (int i = 0; i < 6; i++) {\n    float fi = float(i);\n    // Smoothly attenuate high-frequency octaves according to continuous CDLOD level\n    float octWeight = clamp(1.0 - max(lodFloat - (4.5 - fi), 0.0), 0.0, 1.0);\n    float n = 1.0 - abs(vnoise(q * freq) * 2.0 - 1.0);\n    h += n * n * amp * octWeight;\n    q = rot * q;\n    freq *= 2.06;\n    amp *= 0.48;\n  }\n  return h - 0.55;\n}\n\n// Continuous morph between snapped coarse grid and fine grid\nfloat cdlodHeight(vec2 p, vec2 camXZ, float lodBias, float morphBand, out float lodLevel, out float morphAmt) {\n  float d = max(length(p - camXZ), 0.35);\n  float rawLod = log2(d * 0.45 * lodBias);\n  lodLevel = clamp(floor(rawLod), 0.0, 4.0);\n  float fracLod = clamp(rawLod - lodLevel, 0.0, 1.0);\n  morphAmt = smoothstep(1.0 - morphBand, 1.0, fracLod);\n\n  // Sample fine grid & morphed coarse grid coordinates (exact CDLOD vertex-morph principle)\n  float stepFine = 0.16 * pow(2.0, lodLevel);\n  float stepCoarse = stepFine * 2.0;\n  vec2 snapFine = floor(p / stepFine + 0.5) * stepFine;\n  vec2 snapCoarse = floor(p / stepCoarse + 0.5) * stepCoarse;\n  vec2 pMorph = mix(p, mix(snapFine, snapCoarse, morphAmt), 0.28);\n\n  float hFine = terrainHeight(pMorph, lodLevel);\n  float hCoarse = terrainHeight(pMorph, lodLevel + 1.0);\n  return mix(hFine, hCoarse, morphAmt);\n}\n\nvec3 lodColor(float lvl) {\n  if (lvl < 0.5) return vec3(0.12, 0.92, 0.82);\n  if (lvl < 1.5) return vec3(0.28, 0.88, 0.36);\n  if (lvl < 2.5) return vec3(0.98, 0.78, 0.20);\n  if (lvl < 3.5) return vec3(0.96, 0.36, 0.24);\n  return vec3(0.76, 0.32, 0.96);\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 tAnim = iTime * max(P_FLY_SPEED, 0.0);\n  float lodBias = clamp(P_LOD_BIAS, 0.35, 2.5);\n  float morphBand = clamp(P_MORPH_BAND, 0.08, 0.9);\n  float gridVis = clamp(P_GRID_OVERLAY, 0.0, 1.6);\n\n  vec3 ro = vec3(tAnim * 0.7, 2.25 + 0.18 * sin(tAnim * 0.4), -tAnim * 1.15);\n  vec3 ta = ro + vec3(0.6 * sin(tAnim * 0.22), -0.95, -3.2);\n  vec3 fw = normalize(ta - ro);\n  vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));\n  vec3 up = cross(rt, fw);\n  vec3 rd = normalize(fw * 1.45 + rt * uv.x + up * uv.y);\n\n  // Atmospheric mountain sky\n  vec3 sunDir = normalize(vec3(0.65, 0.42, -0.62));\n  float sunAmt = max(dot(rd, sunDir), 0.0);\n  vec3 sky = mix(vec3(0.54, 0.68, 0.82), vec3(0.14, 0.28, 0.54), pow(clamp(rd.y * 2.2 + 0.1, 0.0, 1.0), 0.65));\n  sky += vec3(1.0, 0.82, 0.55) * pow(sunAmt, 10.0) * 0.55;\n  vec3 col = sky;\n\n  // Raymarch terrain heightfield\n  float t = 0.2;\n  bool hit = false;\n  float lodLvl = 0.0;\n  float morph = 0.0;\n  for (int i = 0; i < 68; i++) {\n    vec3 p = ro + rd * t;\n    float h = cdlodHeight(p.xz, ro.xz, lodBias, morphBand, lodLvl, morph);\n    float diff = p.y - h;\n    if (diff < 0.008 * t) {\n      // Binary refine hit\n      t -= diff * 0.5;\n      hit = true;\n      break;\n    }\n    t += max(diff * 0.48, 0.035 + t * 0.022);\n    if (t > 28.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    float lDummy, mDummy;\n    float eps = 0.04 + t * 0.008;\n    float hC = cdlodHeight(p.xz, ro.xz, lodBias, morphBand, lodLvl, morph);\n    float hX = cdlodHeight(p.xz + vec2(eps, 0.0), ro.xz, lodBias, morphBand, lDummy, mDummy);\n    float hZ = cdlodHeight(p.xz + vec2(0.0, eps), ro.xz, lodBias, morphBand, lDummy, mDummy);\n    vec3 n = normalize(vec3(hC - hX, eps, hC - hZ));\n\n    // Biome shading: rocky cliff, alpine moss, snow peaks\n    float slope = 1.0 - n.y;\n    vec3 rock = vec3(0.28, 0.26, 0.25);\n    vec3 moss = vec3(0.22, 0.34, 0.18);\n    vec3 snow = vec3(0.86, 0.90, 0.96);\n    vec3 alb = mix(moss, rock, smoothstep(0.18, 0.48, slope));\n    alb = mix(alb, snow, smoothstep(0.32, 0.72, p.y - slope * 0.45));\n\n    float diffL = max(dot(n, sunDir), 0.0);\n    float amb = 0.24 + 0.18 * n.y;\n    vec3 shaded = alb * (amb * vec3(0.65, 0.78, 1.0) + diffL * vec3(1.15, 0.98, 0.80));\n\n    // CDLOD Quadtree patch grid & morphed sub-grid lines\n    float nodeSize = 0.65 * pow(2.0, lodLvl);\n    vec2 qf = abs(fract(p.xz / nodeSize - 0.5) - 0.5);\n    float nodeEdge = smoothstep(0.045, 0.012, min(qf.x, qf.y));\n    vec2 subF = abs(fract(p.xz / (nodeSize * 0.25) - 0.5) - 0.5);\n    float subEdge = smoothstep(0.055, 0.015, min(subF.x, subF.y)) * (1.0 - morph * 0.75);\n\n    vec3 tierCol = lodColor(lodLvl);\n    vec3 nextTierCol = lodColor(min(lodLvl + 1.0, 4.0));\n    vec3 activeTint = mix(tierCol, nextTierCol, morph);\n\n    // Subtle LOD tint + crisp quadtree borders + morph transition highlight\n    shaded = mix(shaded, shaded * (0.65 + 0.55 * activeTint), 0.28 * min(gridVis, 1.0));\n    shaded = mix(shaded, activeTint * 1.25, nodeEdge * 0.68 * min(gridVis, 1.2));\n    shaded += activeTint * subEdge * 0.22 * gridVis;\n    // Glowing white-gold ribbon showing the active vertex-morph transition zone\n    float morphGlow = smoothstep(0.05, 0.5, morph) * smoothstep(1.0, 0.5, morph);\n    shaded += vec3(0.95, 0.92, 0.78) * morphGlow * 0.22 * gridVis;\n\n    float fog = 1.0 - exp(-t * 0.048);\n    col = mix(shaded, sky, fog);\n  }\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": "cdlod-terrain",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:27.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7524,
      "std": 0.0834,
      "min": 0.508,
      "max": 0.9168
     },
     "image": "/specimens/cdlod-terrain-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "geometry-clipmaps-terrain",
  "hydraulic-erosion-stava",
  "gpu-pipe-model-erosion",
  "virtual-texturing"
 ],
 "extends": [
  "geometry-clipmaps-terrain"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "gpu-pipe-model-erosion",
   "why": "Eroded heightmaps produced on the GPU are streamed straight into the node height textures."
  }
 ],
 "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/cdlod-terrain.json"
 },
 "solves": [
  "terrain lod seams and cracks between chunks",
  "heightmap quadtree lod without popping",
  "smooth morphing between terrain detail levels",
  "render large terrain with few draw calls",
  "distance based terrain tessellation without hardware tessellation"
 ],
 "authority": "Strugar, 2009",
 "url": "https://texelatlas.vercel.app/t/cdlod-terrain/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 457.8,
  "tier": "extreme",
  "p50_ms": 14.375,
  "p95_ms": 14.5044,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 20,
  "preset_id": "cdlod-terrain-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 412.48,
   "tier": "extreme",
   "p50_ms": 6.5172,
   "p95_ms": 6.5818,
   "speedup_x": 2.21,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 330.47,
   "tier": "extreme",
   "p50_ms": 9.5176,
   "p95_ms": 9.5858,
   "speedup_x": 1.51,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}