---
id: "cdlod-terrain"
title: "CDLOD terrain"
aliases: [Continuous Distance-Dependent LOD, CDLOD]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, unity, unreal]
year_introduced: 2010
inputs: [heightfield]
outputs: [mesh]
style: "both"
dynamic: "both"
cost: "cheap"
authority: "Strugar, 2009"
url: "https://texelatlas.vercel.app/t/cdlod-terrain/"
sources_verified_at: "2026-11-29"
---
# CDLOD terrain (Strugar, 2009)

> 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.

## Reach for it when

- 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

## 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.

Every 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.

Neighboring 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 it

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](https://texelatlas.vercel.app/t/geometry-clipmaps-terrain.md) when you want toroidal update of the height data and a fixed, flatter workload. Prefer [Nanite virtualized geometry](https://texelatlas.vercel.app/t/nanite-virtualized-geometry.md) for non-heightfield terrain. Use [Interactive Hydraulic Erosion on Heightfields](https://texelatlas.vercel.app/t/hydraulic-erosion-stava.md) or [GPU Pipe-Model Hydraulic Erosion](https://texelatlas.vercel.app/t/gpu-pipe-model-erosion.md) output as the input heightmap.

## Cost

cheap — Node selection on CPU is tiny; GPU cost is a few hundred instanced grid draws with texture-fetched heights.
Measured GPU Weight: 457.8× baseline (extreme) — 14.375 ms median / 14.5044 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 412.48× baseline (extreme) — 6.5172 ms median (2.21× faster on L4).
Ampere A100 scaling: 330.47× baseline (extreme) — 9.5176 ms median (1.51× faster on A100).

## 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

## Dataflow

- Inputs: heightfield
- Outputs: mesh
- Platforms: webgl2, webgpu, desktop-gpu, unity, unreal

## Presets

### CDLOD terrain — continuous distance-dependent quadtree morphing & LOD ring visualization (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_LOD_BIAS": 1,
  "P_MORPH_BAND": 0.42,
  "P_GRID_OVERLAY": 0.82,
  "P_FLY_SPEED": 1
}
```

```glsl
const float P_LOD_BIAS = 1.0; // P LOD Bias [0.4, 2.2, 0.05]
const float P_MORPH_BAND = 0.42; // P Morph Band [0.1, 0.85, 0.02]
const float P_GRID_OVERLAY = 0.82; // P Quadtree Grid [0.0, 1.5, 0.04]
const float P_FLY_SPEED = 1.0; // P Fly Speed [0.0, 2.5, 0.05]

float hash21(vec2 p) {
  p = fract(p * vec2(127.1, 311.7));
  p += dot(p, p + 34.5);
  return fract(p.x * p.y);
}

float vnoise(vec2 p) {
  vec2 i = floor(p);
  vec2 f = fract(p);
  f = f * f * (3.0 - 2.0 * f);
  return mix(
    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), f.x),
    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), f.x),
    f.y
  );
}

// Multi-octave alpine ridge heightfield with smooth LOD truncation
float terrainHeight(vec2 p, float lodFloat) {
  float h = 0.0;
  float amp = 1.05;
  float freq = 0.24;
  mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);
  vec2 q = p;
  for (int i = 0; i < 6; i++) {
    float fi = float(i);
    // Smoothly attenuate high-frequency octaves according to continuous CDLOD level
    float octWeight = clamp(1.0 - max(lodFloat - (4.5 - fi), 0.0), 0.0, 1.0);
    float n = 1.0 - abs(vnoise(q * freq) * 2.0 - 1.0);
    h += n * n * amp * octWeight;
    q = rot * q;
    freq *= 2.06;
    amp *= 0.48;
  }
  return h - 0.55;
}

// Continuous morph between snapped coarse grid and fine grid
float cdlodHeight(vec2 p, vec2 camXZ, float lodBias, float morphBand, out float lodLevel, out float morphAmt) {
  float d = max(length(p - camXZ), 0.35);
  float rawLod = log2(d * 0.45 * lodBias);
  lodLevel = clamp(floor(rawLod), 0.0, 4.0);
  float fracLod = clamp(rawLod - lodLevel, 0.0, 1.0);
  morphAmt = smoothstep(1.0 - morphBand, 1.0, fracLod);

  // Sample fine grid & morphed coarse grid coordinates (exact CDLOD vertex-morph principle)
  float stepFine = 0.16 * pow(2.0, lodLevel);
  float stepCoarse = stepFine * 2.0;
  vec2 snapFine = floor(p / stepFine + 0.5) * stepFine;
  vec2 snapCoarse = floor(p / stepCoarse + 0.5) * stepCoarse;
  vec2 pMorph = mix(p, mix(snapFine, snapCoarse, morphAmt), 0.28);

  float hFine = terrainHeight(pMorph, lodLevel);
  float hCoarse = terrainHeight(pMorph, lodLevel + 1.0);
  return mix(hFine, hCoarse, morphAmt);
}

vec3 lodColor(float lvl) {
  if (lvl < 0.5) return vec3(0.12, 0.92, 0.82);
  if (lvl < 1.5) return vec3(0.28, 0.88, 0.36);
  if (lvl < 2.5) return vec3(0.98, 0.78, 0.20);
  if (lvl < 3.5) return vec3(0.96, 0.36, 0.24);
  return vec3(0.76, 0.32, 0.96);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float tAnim = iTime * max(P_FLY_SPEED, 0.0);
  float lodBias = clamp(P_LOD_BIAS, 0.35, 2.5);
  float morphBand = clamp(P_MORPH_BAND, 0.08, 0.9);
  float gridVis = clamp(P_GRID_OVERLAY, 0.0, 1.6);

  vec3 ro = vec3(tAnim * 0.7, 2.25 + 0.18 * sin(tAnim * 0.4), -tAnim * 1.15);
  vec3 ta = ro + vec3(0.6 * sin(tAnim * 0.22), -0.95, -3.2);
  vec3 fw = normalize(ta - ro);
  vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));
  vec3 up = cross(rt, fw);
  vec3 rd = normalize(fw * 1.45 + rt * uv.x + up * uv.y);

  // Atmospheric mountain sky
  vec3 sunDir = normalize(vec3(0.65, 0.42, -0.62));
  float sunAmt = max(dot(rd, sunDir), 0.0);
  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));
  sky += vec3(1.0, 0.82, 0.55) * pow(sunAmt, 10.0) * 0.55;
  vec3 col = sky;

  // Raymarch terrain heightfield
  float t = 0.2;
  bool hit = false;
  float lodLvl = 0.0;
  float morph = 0.0;
  for (int i = 0; i < 68; i++) {
    vec3 p = ro + rd * t;
    float h = cdlodHeight(p.xz, ro.xz, lodBias, morphBand, lodLvl, morph);
    float diff = p.y - h;
    if (diff < 0.008 * t) {
      // Binary refine hit
      t -= diff * 0.5;
      hit = true;
      break;
    }
    t += max(diff * 0.48, 0.035 + t * 0.022);
    if (t > 28.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    float lDummy, mDummy;
    float eps = 0.04 + t * 0.008;
    float hC = cdlodHeight(p.xz, ro.xz, lodBias, morphBand, lodLvl, morph);
    float hX = cdlodHeight(p.xz + vec2(eps, 0.0), ro.xz, lodBias, morphBand, lDummy, mDummy);
    float hZ = cdlodHeight(p.xz + vec2(0.0, eps), ro.xz, lodBias, morphBand, lDummy, mDummy);
    vec3 n = normalize(vec3(hC - hX, eps, hC - hZ));

    // Biome shading: rocky cliff, alpine moss, snow peaks
    float slope = 1.0 - n.y;
    vec3 rock = vec3(0.28, 0.26, 0.25);
    vec3 moss = vec3(0.22, 0.34, 0.18);
    vec3 snow = vec3(0.86, 0.90, 0.96);
    vec3 alb = mix(moss, rock, smoothstep(0.18, 0.48, slope));
    alb = mix(alb, snow, smoothstep(0.32, 0.72, p.y - slope * 0.45));

    float diffL = max(dot(n, sunDir), 0.0);
    float amb = 0.24 + 0.18 * n.y;
    vec3 shaded = alb * (amb * vec3(0.65, 0.78, 1.0) + diffL * vec3(1.15, 0.98, 0.80));

    // CDLOD Quadtree patch grid & morphed sub-grid lines
    float nodeSize = 0.65 * pow(2.0, lodLvl);
    vec2 qf = abs(fract(p.xz / nodeSize - 0.5) - 0.5);
    float nodeEdge = smoothstep(0.045, 0.012, min(qf.x, qf.y));
    vec2 subF = abs(fract(p.xz / (nodeSize * 0.25) - 0.5) - 0.5);
    float subEdge = smoothstep(0.055, 0.015, min(subF.x, subF.y)) * (1.0 - morph * 0.75);

    vec3 tierCol = lodColor(lodLvl);
    vec3 nextTierCol = lodColor(min(lodLvl + 1.0, 4.0));
    vec3 activeTint = mix(tierCol, nextTierCol, morph);

    // Subtle LOD tint + crisp quadtree borders + morph transition highlight
    shaded = mix(shaded, shaded * (0.65 + 0.55 * activeTint), 0.28 * min(gridVis, 1.0));
    shaded = mix(shaded, activeTint * 1.25, nodeEdge * 0.68 * min(gridVis, 1.2));
    shaded += activeTint * subEdge * 0.22 * gridVis;
    // Glowing white-gold ribbon showing the active vertex-morph transition zone
    float morphGlow = smoothstep(0.05, 0.5, morph) * smoothstep(1.0, 0.5, morph);
    shaded += vec3(0.95, 0.92, 0.78) * morphGlow * 0.22 * gridVis;

    float fog = 1.0 - exp(-t * 0.048);
    col = mix(shaded, sky, fog);
  }

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Lineage

- extends [Geometry clipmaps](https://texelatlas.vercel.app/t/geometry-clipmaps-terrain.md)

## Combines with

- [GPU Pipe-Model Hydraulic Erosion](https://texelatlas.vercel.app/t/gpu-pipe-model-erosion.md): Eroded heightmaps produced on the GPU are streamed straight into the node height textures.

## Sources

1. [primary] Filip Strugar (2009) Continuous Distance-Dependent Level of Detail for Rendering Heightmaps. Journal of Graphics, GPU, and Game Tools. https://doi.org/10.1080/2151237x.2009.10129287 (verified via crossref on 2026-11-29)
2. [implementation] fstrugar (2017) fstrugar/CDLOD. https://github.com/fstrugar/CDLOD License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "CDLOD terrain." https://texelatlas.vercel.app/t/cdlod-terrain/ (accessed 2026-12-01).
