---
id: "virtual-shadow-maps"
title: "Virtual Shadow Maps"
domain: "visibility"
stage: "visibility"
realtime: "realtime"
platforms: [desktop-gpu, unreal]
year_introduced: 2021
inputs: [mesh, depth]
outputs: [visibility-mask]
style: "photoreal"
dynamic: "dynamic"
cost: "heavy"
authority: "Games"
url: "https://texelatlas.vercel.app/t/virtual-shadow-maps/"
sources_verified_at: "2026-11-29"
---
# Virtual Shadow Maps (Games)

> A very high-resolution, sparsely allocated shadow map per light, where only pages the camera actually samples are rendered and cached, pairing with virtualised geometry.

## Reach for it when

- shadow resolution too low for big detailed scenes
- need film quality shadows on every light
- cascades flicker and waste memory
- shadows blurry near the camera in open worlds

## How it works

Each light owns a virtual depth texture many thousands of texels wide, divided into pages. A pass analyses the depth buffer to mark which pages are needed at the required resolution (a clipmap for directional lights, mip-style levels for local lights), allocates physical pages, and renders only geometry overlapping them, with Nanite-style culling. Pages whose content did not change are cached between frames and invalidated by moving casters, so static scenes cost almost nothing per frame. Filtering is built from a small number of taps against the fine map and often combined with a screen-space or ray-traced term for contact detail. This is documented as an Unreal Engine 5 feature rather than a published paper.

## When to use it

Choose it when geometry is extremely dense and you need consistent sharp shadows from near to far without hand-tuned cascades, in an engine with virtualised geometry. Prefer [Cascaded Shadow Maps](https://texelatlas.vercel.app/t/cascaded-shadow-maps.md) on mobile, WebGL or lower-end GPUs, and [Ray-Traced Shadows](https://texelatlas.vercel.app/t/ray-traced-shadows.md) when physically soft penumbrae are required.

## Cost

heavy — Depends on cache hit rate and page count; static scenes are cheap, large dynamic casters invalidate many pages.
Measured GPU Weight: 40.43× baseline (heavy) — 1.33 ms median / 1.4198 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 42.92× baseline (heavy) — 0.6824 ms median (1.95× faster on L4).
Ampere A100 scaling: 25.28× baseline (heavy) — 0.7281 ms median (1.83× faster on A100).

## Failure modes

- Page invalidation spikes from fast-moving or large dynamic casters
- Large memory pool for the physical page cache
- Needs a depth-buffer analysis pass and GPU-driven rendering infrastructure
- Alpha-tested or deforming geometry can force costly re-rendering

## Engine support

- blender: builtin — `Light Properties > Shadow (EEVEE uses Virtual Shadow Mapping)` (evidence: https://docs.blender.org/manual/en/5.2/render/eevee/light_settings.html, checked 2026-12-01)
- unreal: builtin — `Project Settings > Rendering > Shadows > Shadow Map Method = Virtual Shadow Maps` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine, checked 2026-12-01)

## Dataflow

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

## Presets

### Virtual Shadow Maps (VSM) — sparse physical page table & dirty-page invalidation (left) vs 1:1 texel-crisp virtual shadows (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_PAGE_GRID": 10,
  "P_CLIPMAP_VIS": 0.65,
  "P_MOVER_SPEED": 0.6,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_PAGE_GRID = 10.00; // P Virtual Page Grid [5.0, 16.0, 1.0]
const float P_CLIPMAP_VIS = 0.65; // P Page State Overlay [0.1, 1.0, 0.05]
const float P_MOVER_SPEED = 0.60; // P Dynamic Caster Speed [0.0, 1.8, 0.05]
const float P_SPLIT = 0.48; // P Page Table / VSM [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);
}

// Courtyard with static fine architectural railing + a dynamic orbiting occluder that invalidates VSM pages!
vec2 mapVSMScene(vec3 p, vec3 moverPos) {
  float dFloor = p.y + 0.52;
  vec2 res = vec2(dFloor, 1.0);

  // Static architectural fence/railing slats (demonstrates crisp 1:1 virtual shadow resolution!)
  for (int i = 0; i < 5; i++) {
    float x = -0.72 + float(i) * 0.22;
    float dPost = sdBox(p - vec3(x, -0.18, -0.35), vec3(0.032, 0.34, 0.032));
    if (dPost < res.x) res = vec2(dPost, 2.0);
  }
  float dRail = sdBox(p - vec3(-0.28, 0.08, -0.35), vec3(0.50, 0.03, 0.04));
  if (dRail < res.x) res = vec2(dRail, 2.0);

  // Dynamic moving sphere occluder (causes VSM dirty-page invalidation on tiles its shadow touches!)
  float dMov = length(p - moverPos) - 0.22;
  if (dMov < res.x) res = vec2(dMov, 3.0);
  return res;
}

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

float traceVSMShadow(vec3 p, vec3 sunDir, vec3 moverPos) {
  float sh = 1.0;
  float t = 0.025;
  for (int i = 0; i < 24; i++) {
    float h = mapVSMScene(p + sunDir * t, moverPos).x;
    if (h < 0.002) return 0.0;
    sh = min(sh, 18.0 * h / t);
    t += max(h, 0.02);
    if (t > 4.0) break;
  }
  return clamp(sh, 0.0, 1.0);
}

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 pageGrid = clamp(floor(P_PAGE_GRID + 0.5), 4.0, 18.0);
  float vis = clamp(P_CLIPMAP_VIS, 0.05, 1.0);
  float t = iTime * max(P_MOVER_SPEED, 0.0);

  vec3 moverPos = vec3(0.38 + 0.28 * cos(t * 0.95), -0.14 + 0.12 * sin(t * 1.4), 0.08 + 0.26 * sin(t * 0.95));
  vec3 ro = vec3(0.0, 0.55, 2.25);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.22, -1.45));
  vec3 sunDir = normalize(vec3(0.42, 0.78, 0.46));
  vec3 sky = mix(vec3(0.70, 0.80, 0.92), vec3(0.18, 0.42, 0.78), smoothstep(-0.1, 0.5, 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 = mapVSMScene(ro + rd * dist, moverPos);
    if (h.x < 0.0025) { hit = vec2(dist, h.y); break; }
    dist += h.x;
    if (dist > 10.0) break;
  }

  if (hit.y > 0.5) {
    vec3 p = ro + rd * hit.x;
    vec3 n = calcNormal(p, moverPos);
    float sh = traceVSMShadow(p + n * 0.008, sunDir, moverPos);

    vec3 alb = vec3(0.76, 0.74, 0.70);
    if (hit.y > 1.5 && hit.y < 2.5) alb = vec3(0.32, 0.36, 0.44);
    else if (hit.y > 2.5) alb = vec3(0.94, 0.52, 0.20);

    float ndl = max(dot(n, sunDir), 0.0);
    vec3 lit = alb * (vec3(0.20, 0.28, 0.42) + vec3(1.32, 1.20, 1.00) * ndl * sh);

    if (screenX < split) {
      // Left: Sparse Virtual Shadow Map clipmap page-table overlay!
      // Light-space virtual coordinates projected onto physical pages:
      vec3 lRight = normalize(cross(vec3(0.0, 1.0, 0.0), sunDir));
      vec3 lUp = cross(sunDir, lRight);
      // Clipmap LOD level halves page frequency with camera distance
      float clipScale = (hit.x > 3.2) ? (pageGrid * 0.5) : pageGrid;
      vec2 vCoord = vec2(dot(p, lRight), dot(p, lUp)) * clipScale * 0.35;
      vec2 pageId = floor(vCoord);
      vec2 pf = fract(vCoord);
      float tileEdge = smoothstep(0.07, 0.015, min(min(pf.x, 1.0 - pf.x), min(pf.y, 1.0 - pf.y)));

      // Check if this virtual page overlaps the moving caster's shadow footprint -> INVALIDATED (amber/red) vs CACHED (cyan/emerald)!
      vec2 moverShadowCoord = vec2(dot(moverPos, lRight), dot(moverPos, lUp)) * clipScale * 0.35;
      bool dirtyPage = length(pageId + 0.5 - moverShadowCoord) < 1.35;

      vec3 pageTint = dirtyPage ? vec3(1.0, 0.42, 0.16)
                    : ((hit.x > 3.2) ? vec3(0.22, 0.62, 0.98) : vec3(0.16, 0.90, 0.68));
      col = mix(lit, lit * 0.55 + pageTint * 0.65, vis * 0.55);
      col = mix(col, pageTint * 1.4, tileEdge * vis * 0.72);
    } else {
      col = lit;
    }
    if (hit.y < 1.5) col = mix(sky, col, exp(-hit.x * 0.08));
  }

  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 [Shadow Mapping](https://texelatlas.vercel.app/t/shadow-mapping.md)

## Sources

1. [primary] Epic Games Virtual Shadow Maps in Unreal Engine. dev.epicgames.com. https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine (verified via http on 2026-11-29)

## Cite this entry

Texel. "Virtual Shadow Maps." https://texelatlas.vercel.app/t/virtual-shadow-maps/ (accessed 2026-12-01).
