{
 "id": "virtual-shadow-maps",
 "title": "Virtual Shadow Maps",
 "aliases": [],
 "domain": "visibility",
 "subdomain": "shadow map partitioning",
 "stage": "visibility",
 "realtime": "realtime",
 "platforms": [
  "desktop-gpu",
  "unreal"
 ],
 "year_introduced": 2021,
 "inputs": [
  "mesh",
  "depth"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "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.",
 "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": "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` on mobile, WebGL or lower-end GPUs, and `ray-traced-shadows` when physically soft penumbrae are required.",
 "cost": {
  "class": "heavy",
  "notes": "Depends on cache hit rate and page count; static scenes are cheap, large dynamic casters invalidate many pages."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine",
   "type": "web",
   "title": "Virtual Shadow Maps in Unreal Engine",
   "authors": [
    "Epic Games"
   ],
   "year": null,
   "venue": "dev.epicgames.com",
   "url": "https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261015100109/https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine",
     "timestamp": "20261015100109"
    },
    "page_title": "Virtual Shadow Maps in Unreal Engine  | Unreal Engine 5.9 Documentation | Epic Developer Community",
    "host": "dev.epicgames.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://dev.epicgames.com/documentation/en-us/unreal-engine/virtual-shadow-maps-in-unreal-engine → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "gamesvirtual"
  }
 ],
 "presets": [
  {
   "id": "virtual-shadow-maps-live",
   "title": "Virtual Shadow Maps (VSM) — sparse physical page table & dirty-page invalidation (left) vs 1:1 texel-crisp virtual shadows (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_PAGE_GRID": 10,
    "P_CLIPMAP_VIS": 0.65,
    "P_MOVER_SPEED": 0.6,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_PAGE_GRID = 10.00; // P Virtual Page Grid [5.0, 16.0, 1.0]\nconst float P_CLIPMAP_VIS = 0.65; // P Page State Overlay [0.1, 1.0, 0.05]\nconst float P_MOVER_SPEED = 0.60; // P Dynamic Caster Speed [0.0, 1.8, 0.05]\nconst float P_SPLIT = 0.48; // P Page Table / VSM [0.0, 1.0, 0.02]\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\n// Courtyard with static fine architectural railing + a dynamic orbiting occluder that invalidates VSM pages!\nvec2 mapVSMScene(vec3 p, vec3 moverPos) {\n  float dFloor = p.y + 0.52;\n  vec2 res = vec2(dFloor, 1.0);\n\n  // Static architectural fence/railing slats (demonstrates crisp 1:1 virtual shadow resolution!)\n  for (int i = 0; i < 5; i++) {\n    float x = -0.72 + float(i) * 0.22;\n    float dPost = sdBox(p - vec3(x, -0.18, -0.35), vec3(0.032, 0.34, 0.032));\n    if (dPost < res.x) res = vec2(dPost, 2.0);\n  }\n  float dRail = sdBox(p - vec3(-0.28, 0.08, -0.35), vec3(0.50, 0.03, 0.04));\n  if (dRail < res.x) res = vec2(dRail, 2.0);\n\n  // Dynamic moving sphere occluder (causes VSM dirty-page invalidation on tiles its shadow touches!)\n  float dMov = length(p - moverPos) - 0.22;\n  if (dMov < res.x) res = vec2(dMov, 3.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p, vec3 moverPos) {\n  vec2 e = vec2(0.0022, 0.0);\n  return normalize(vec3(\n    mapVSMScene(p + e.xyy, moverPos).x - mapVSMScene(p - e.xyy, moverPos).x,\n    mapVSMScene(p + e.yxy, moverPos).x - mapVSMScene(p - e.yxy, moverPos).x,\n    mapVSMScene(p + e.yyx, moverPos).x - mapVSMScene(p - e.yyx, moverPos).x\n  ));\n}\n\nfloat traceVSMShadow(vec3 p, vec3 sunDir, vec3 moverPos) {\n  float sh = 1.0;\n  float t = 0.025;\n  for (int i = 0; i < 24; i++) {\n    float h = mapVSMScene(p + sunDir * t, moverPos).x;\n    if (h < 0.002) return 0.0;\n    sh = min(sh, 18.0 * h / t);\n    t += max(h, 0.02);\n    if (t > 4.0) break;\n  }\n  return clamp(sh, 0.0, 1.0);\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  float pageGrid = clamp(floor(P_PAGE_GRID + 0.5), 4.0, 18.0);\n  float vis = clamp(P_CLIPMAP_VIS, 0.05, 1.0);\n  float t = iTime * max(P_MOVER_SPEED, 0.0);\n\n  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));\n  vec3 ro = vec3(0.0, 0.55, 2.25);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.22, -1.45));\n  vec3 sunDir = normalize(vec3(0.42, 0.78, 0.46));\n  vec3 sky = mix(vec3(0.70, 0.80, 0.92), vec3(0.18, 0.42, 0.78), smoothstep(-0.1, 0.5, rd.y));\n  vec3 col = sky;\n\n  float dist = 0.05;\n  vec2 hit = vec2(12.0, 0.0);\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapVSMScene(ro + rd * dist, moverPos);\n    if (h.x < 0.0025) { hit = vec2(dist, h.y); break; }\n    dist += h.x;\n    if (dist > 10.0) break;\n  }\n\n  if (hit.y > 0.5) {\n    vec3 p = ro + rd * hit.x;\n    vec3 n = calcNormal(p, moverPos);\n    float sh = traceVSMShadow(p + n * 0.008, sunDir, moverPos);\n\n    vec3 alb = vec3(0.76, 0.74, 0.70);\n    if (hit.y > 1.5 && hit.y < 2.5) alb = vec3(0.32, 0.36, 0.44);\n    else if (hit.y > 2.5) alb = vec3(0.94, 0.52, 0.20);\n\n    float ndl = max(dot(n, sunDir), 0.0);\n    vec3 lit = alb * (vec3(0.20, 0.28, 0.42) + vec3(1.32, 1.20, 1.00) * ndl * sh);\n\n    if (screenX < split) {\n      // Left: Sparse Virtual Shadow Map clipmap page-table overlay!\n      // Light-space virtual coordinates projected onto physical pages:\n      vec3 lRight = normalize(cross(vec3(0.0, 1.0, 0.0), sunDir));\n      vec3 lUp = cross(sunDir, lRight);\n      // Clipmap LOD level halves page frequency with camera distance\n      float clipScale = (hit.x > 3.2) ? (pageGrid * 0.5) : pageGrid;\n      vec2 vCoord = vec2(dot(p, lRight), dot(p, lUp)) * clipScale * 0.35;\n      vec2 pageId = floor(vCoord);\n      vec2 pf = fract(vCoord);\n      float tileEdge = smoothstep(0.07, 0.015, min(min(pf.x, 1.0 - pf.x), min(pf.y, 1.0 - pf.y)));\n\n      // Check if this virtual page overlaps the moving caster's shadow footprint -> INVALIDATED (amber/red) vs CACHED (cyan/emerald)!\n      vec2 moverShadowCoord = vec2(dot(moverPos, lRight), dot(moverPos, lUp)) * clipScale * 0.35;\n      bool dirtyPage = length(pageId + 0.5 - moverShadowCoord) < 1.35;\n\n      vec3 pageTint = dirtyPage ? vec3(1.0, 0.42, 0.16)\n                    : ((hit.x > 3.2) ? vec3(0.22, 0.62, 0.98) : vec3(0.16, 0.90, 0.68));\n      col = mix(lit, lit * 0.55 + pageTint * 0.65, vis * 0.55);\n      col = mix(col, pageTint * 1.4, tileEdge * vis * 0.72);\n    } else {\n      col = lit;\n    }\n    if (hit.y < 1.5) col = mix(sky, col, exp(-hit.x * 0.08));\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.98, 1.0), sep);\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": "virtual-shadow-maps",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:28.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.84,
      "std": 0.0787,
      "min": 0.3824,
      "max": 0.9022
     },
     "image": "/specimens/virtual-shadow-maps-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "cascaded-shadow-maps",
  "shadow-mapping",
  "ray-traced-shadows"
 ],
 "extends": [
  "shadow-mapping"
 ],
 "supersedes": [],
 "combines_with": [],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/visibility/virtual-shadow-maps.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Games",
 "url": "https://texelatlas.vercel.app/t/virtual-shadow-maps/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 40.43,
  "tier": "heavy",
  "p50_ms": 1.33,
  "p95_ms": 1.4198,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "virtual-shadow-maps-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 42.92,
   "tier": "heavy",
   "p50_ms": 0.6824,
   "p95_ms": 0.6945,
   "speedup_x": 1.95,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 25.28,
   "tier": "heavy",
   "p50_ms": 0.7281,
   "p95_ms": 0.7355,
   "speedup_x": 1.83,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}