---
id: "sample-distribution-shadow-maps"
title: "Sample Distribution Shadow Maps (SDSM)"
aliases: [SDSM]
domain: "visibility"
stage: "visibility"
realtime: "realtime"
platforms: [desktop-gpu, webgpu, unity, unreal]
year_introduced: 2011
inputs: [depth, mesh]
outputs: [visibility-mask]
style: "both"
dynamic: "dynamic"
cost: "medium"
authority: "Lauritzen et al., 2011"
url: "https://texelatlas.vercel.app/t/sample-distribution-shadow-maps/"
sources_verified_at: "2026-11-29"
---
# Sample Distribution Shadow Maps (SDSM) (Lauritzen et al., 2011)

> Analyses the depth buffer each frame to fit cascade split positions and light-space bounds tightly around the pixels that will actually sample the shadow map.

## Reach for it when

- cascaded shadows waste resolution when looking at a wall
- shadow quality changes a lot depending on view direction
- cascade splits do not match the visible depth range
- want tighter shadow map fitting around visible pixels
- distant sun shadows blurry although camera sees little depth

## How it works

Classic cascaded shadow maps place split planes with a fixed scheme and fit each cascade to the whole sub-frustum, wasting texels on empty space. SDSM first renders the scene depth and runs a GPU reduction to find the minimum and maximum visible view depth. It can then (a) set split planes from a logarithmic partition of that real range, or from a depth histogram, so cascades follow where pixels exist, and (b) for each cascade compute the tight light-space bounding box of just the visible samples, using min/max reductions of the projected positions. The resulting orthographic projections are read back or consumed by indirect dispatch, then used to render the maps. Snapping extents to texel increments keeps shadows stable under camera motion, and conservative expansion handles reduction latency.

## When to use it

Choose it when [Cascaded Shadow Maps](https://texelatlas.vercel.app/t/cascaded-shadow-maps.md) waste resolution because the visible depth range varies a lot, as in outdoor scenes that alternate between looking at a wall and looking at the horizon. Prefer [Virtual Shadow Maps](https://texelatlas.vercel.app/t/virtual-shadow-maps.md) when geometry density and uniform quality matter more than fitting, and keep plain stabilised CSM for mobile where an extra depth reduction is too costly. Pair with normal-offset bias from [Shadow map depth bias (constant, slope-scale, normal offset)](https://texelatlas.vercel.app/t/shadow-map-bias-slope-scale-normal-offset.md) per cascade.

## Cost

medium — Adds a depth prepass and a compute reduction; the savings come from rendering smaller, tighter shadow maps. Cost is qualitative and scene dependent.
Measured GPU Weight: 48.99× baseline (heavy) — 1.6119 ms median / 1.6824 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 55.66× baseline (heavy) — 0.885 ms median (1.82× faster on L4).
Ampere A100 scaling: 32.78× baseline (heavy) — 0.9441 ms median (1.71× faster on A100).

## Failure modes

- Shadow shimmering when cascade bounds change every frame without stabilisation or hysteresis
- One-frame latency in bounds when reductions are read back, causing pop at fast camera turns
- Tight fit excludes off-screen casters unless the near plane is extended toward the light
- Depth outliers (sky, tiny particles) must be masked or the reduction loosens again

## Dataflow

- Inputs: depth, mesh
- Outputs: visibility-mask
- Platforms: desktop-gpu, webgpu, unity, unreal

## Presets

### Sample Distribution Shadow Maps (SDSM) — fixed CSM wasted cascades & aliasing (left) vs depth-fitted tight SDSM cascades (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_CASCADES": 4,
  "P_BAND_VIS": 0.55,
  "P_SUN_SWEEP": 0.5,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_CASCADES = 4.00; // P Cascade Count [2.0, 5.0, 1.0]
const float P_BAND_VIS = 0.55; // P Cascade Tint [0.0, 1.0, 0.05]
const float P_SUN_SWEEP = 0.50; // P Sun Sweep [0.0, 1.5, 0.05]
const float P_SPLIT = 0.48; // P Fixed CSM / SDSM [0.0, 1.0, 0.02]

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// Long architectural vista with foreground + mid-ground + distant monoliths and empty depth gap in between
vec2 mapVista(vec3 p) {
  float dFloor = p.y + 0.55;
  vec2 res = vec2(dFloor, 1.0);

  // Repeating rows of tall monoliths along -Z
  for (int i = 0; i < 4; i++) {
    float z = -0.35 - float(i) * 1.35;
    float dL = sdBox(p - vec3(-0.62, 0.05, z), vec3(0.16, 0.60, 0.16));
    float dR = sdBox(p - vec3(0.62, 0.05, z), vec3(0.16, 0.60, 0.16));
    float dTop = sdBox(p - vec3(0.0, 0.58, z), vec3(0.80, 0.09, 0.16));
    float dArch = min(min(dL, dR), dTop);
    if (dArch < res.x) res = vec2(dArch, 2.0);
  }
  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.003, 0.0);
  return normalize(vec3(
    mapVista(p + e.xyy).x - mapVista(p - e.xyy).x,
    mapVista(p + e.yxy).x - mapVista(p - e.yxy).x,
    mapVista(p + e.yyx).x - mapVista(p - e.yyx).x
  ));
}

// Trace shadow ray from quantized shadow-map texel position to visualize real texel-resolution difference!
float traceShadowAt(vec3 p, vec3 sunDir, float texelSize) {
  // Snap point onto light-space shadow-map texel grid of size texelSize
  vec3 lUp = vec3(0.0, 1.0, 0.0);
  vec3 lRight = normalize(cross(lUp, sunDir));
  vec3 lOrtho = cross(sunDir, lRight);
  float u = floor(dot(p, lRight) / texelSize + 0.5) * texelSize;
  float v = floor(dot(p, lOrtho) / texelSize + 0.5) * texelSize;
  float w = dot(p, sunDir);
  vec3 pSnap = lRight * u + lOrtho * v + sunDir * w;

  float t = 0.05;
  for (int i = 0; i < 20; i++) {
    float h = mapVista(pSnap + sunDir * t).x;
    if (h < 0.005) return 0.0;
    t += max(h, 0.04);
    if (t > 4.0) break;
  }
  return 1.0;
}

vec3 cascadeColor(float idx) {
  if (idx < 0.5) return vec3(0.18, 0.92, 0.56);
  if (idx < 1.5) return vec3(0.20, 0.72, 1.0);
  if (idx < 2.5) return vec3(0.98, 0.78, 0.22);
  if (idx < 3.5) return vec3(0.98, 0.36, 0.32);
  return vec3(0.84, 0.38, 0.98);
}

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 screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  float numCasc = clamp(floor(P_CASCADES + 0.5), 2.0, 5.0);
  float bandVis = clamp(P_BAND_VIS, 0.0, 1.0);
  float t = iTime * max(P_SUN_SWEEP, 0.0);

  vec3 ro = vec3(0.16 * sin(t * 0.4), 0.36, 2.20);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.10, -1.45));
  vec3 sunDir = normalize(vec3(0.68 * cos(t * 0.35 + 0.4), 0.62, 0.38));
  vec3 sky = mix(vec3(0.72, 0.80, 0.90), vec3(0.18, 0.42, 0.76), smoothstep(-0.08, 0.55, rd.y));
  vec3 col = sky;

  float dist = 0.05;
  vec2 hit = vec2(12.0, 0.0);
  for (int i = 0; i < 64; i++) {
    vec2 h = mapVista(ro + rd * dist);
    if (h.x < 0.003) { hit = vec2(dist, h.y); break; }
    dist += h.x;
    if (dist > 11.0) break;
  }

  if (hit.y > 0.5) {
    vec3 p = ro + rd * hit.x;
    vec3 n = calcNormal(p);
    float viewZ = hit.x;

    float cascIdx = 0.0;
    float texelSz = 0.02;
    if (screenX < split) {
      // Left: Fixed naive CSM splits spanning [0.1 .. 24.0] -> wastes cascade 0 in empty air near camera,
      // forcing visible geometry into coarse cascades with blocky aliased shadows!
      float zFrac = clamp(log(max(viewZ, 0.1) / 0.1) / log(24.0 / 0.1), 0.0, 0.999);
      cascIdx = floor(zFrac * numCasc);
      texelSz = 0.032 * pow(1.75, cascIdx);
    } else {
      // Right: SDSM reduces actual visible depth bounds [zMin=1.6 .. zMax=8.2] each frame ->
      // tightly fits all cascades around real scene samples for 3-4x crisper shadow texels!
      float zMin = 1.55;
      float zMax = 8.40;
      float zFrac = clamp(log(max(viewZ, zMin) / zMin) / log(zMax / zMin), 0.0, 0.999);
      cascIdx = floor(zFrac * numCasc);
      texelSz = 0.008 * pow(1.42, cascIdx);
    }

    float sh = traceShadowAt(p + n * 0.01, sunDir, texelSz);
    vec3 alb = (hit.y < 1.5) ? vec3(0.74, 0.72, 0.68) : vec3(0.86, 0.82, 0.76);
    float ndl = max(dot(n, sunDir), 0.0);
    vec3 lit = alb * (vec3(0.20, 0.28, 0.42) + vec3(1.32, 1.18, 0.96) * ndl * sh);

    // Subtle cascade split band tint & boundary line
    vec3 cTint = cascadeColor(cascIdx);
    col = mix(lit, lit * (0.55 + 0.75 * cTint), bandVis * 0.48);
    col = mix(sky, col, exp(-viewZ * 0.06));
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.98, 1.0), sep);
  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Lineage

- extends [Cascaded Shadow Maps](https://texelatlas.vercel.app/t/cascaded-shadow-maps.md)

## Combines with

- [Hierarchical-Z occlusion culling](https://texelatlas.vercel.app/t/hierarchical-z-occlusion-culling.md): The depth pyramid built for culling can provide the min/max depth the SDSM reduction needs.

## Sources

1. [primary] Andrew Lauritzen, Marco Salvi, Aaron Lefohn (2011) Sample distribution shadow maps. Symposium on Interactive 3D Graphics and Games. https://doi.org/10.1145/1944745.1944761 (verified via crossref on 2026-11-29)
2. [implementation] TheRealMJP (2016) TheRealMJP/Shadows. https://github.com/TheRealMJP/Shadows License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Sample Distribution Shadow Maps (SDSM)." https://texelatlas.vercel.app/t/sample-distribution-shadow-maps/ (accessed 2026-12-01).
