{
 "id": "reflective-shadow-maps",
 "title": "Reflective Shadow Maps",
 "aliases": [
  "RSM"
 ],
 "domain": "gi",
 "subdomain": "image-space GI",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu"
 ],
 "year_introduced": 2005,
 "inputs": [
  "depth",
  "normals",
  "gbuffer"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Extends a shadow map with per-texel world position, normal and reflected flux, treating each lit texel as a tiny light. One-bounce indirect light is gathered by sampling nearby texels around each shaded point.",
 "how_it_works": "A shadow map already holds every surface point that a light directly illuminates. A reflective shadow map stores, for each texel of that map, the depth (or world position), the normal and the **reflected radiant flux** (albedo times incoming light). Each texel is therefore a small secondary source that emits diffusely.\n\nTo compute indirect light at a shaded point, project it into the RSM and take a set of samples in a disc around the projection, with a larger sampling density near the centre. Each sample contributes `flux * max(0, n_pixel . (x_pixel - x_sample)) * max(0, n_sample . (x_sample - x_pixel)) / |dist|^4`. Because that gather is expensive, implementations run it at lower resolution and upsample with an edge-aware filter, or precompute a rotating sampling pattern per pixel.\n\nThe method has no visibility test for the secondary light, so indirect shadows are missing, but it needs no pre-computation and works for animated lights and geometry.",
 "when_to_use": "Choose it for a cheap one-bounce indirect term from a single shadow-casting light (a flashlight or sun) in an engine that already renders shadow maps.\n\nPrefer [light-propagation-volumes](light-propagation-volumes) when you want to inject the RSM into a grid and get multi-bounce, no per-pixel gather. Prefer [instant-radiosity](instant-radiosity) when you need indirect shadows. Prefer [ddgi](ddgi) or [lumen-gi](lumen-gi) for modern dynamic GI.",
 "cost": {
  "class": "medium",
  "notes": "Per-pixel cost is the number of RSM samples (tens to hundreds) at reduced resolution, plus shadow map generation."
 },
 "failure_modes": [
  "No occlusion for indirect light: light leaks through walls and floors between the RSM and the shaded point",
  "Only one bounce, and only light that is visible to the light's shadow camera",
  "Undersampling gives noise or flickering unless the pattern is rotated and filtered",
  "Wide-angle spot or sun light needs large, high-resolution RSMs to cover the visible area"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/1053427.1053460",
   "type": "paper",
   "title": "Reflective shadow maps",
   "authors": [
    "Carsten Dachsbacher",
    "Marc Stamminger"
   ],
   "year": 2005,
   "venue": "Proceedings of the 2005 symposium on Interactive 3D graphics and games",
   "url": "https://doi.org/10.1145/1053427.1053460",
   "ids": {
    "doi": "10.1145/1053427.1053460"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1053427.1053460",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1053427.1053460",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1053427.1053460",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1053427.1053460",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1053427.1053460",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "dachsbacher2005reflective"
  }
 ],
 "presets": [
  {
   "id": "reflective-shadow-maps-live",
   "title": "Reflective Shadow Maps — direct spotlight flux VPL taps & single-bounce indirect gather",
   "runtime": "glsl-fragment",
   "params": {
    "P_RSM_GAIN": 1.4,
    "P_SPOT_SWEEP": 1,
    "P_VPL_DOTS": 1,
    "P_SPLIT": 0.38
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_RSM_GAIN = 1.4; // P RSM Indirect Gain [0.0, 2.8, 0.05]\nconst float P_SPOT_SWEEP = 1.0; // P Spot Motion [0.0, 2.5, 0.05]\nconst float P_VPL_DOTS = 1.0; // P RSM VPL Taps [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.38; // P Direct / RSM Split [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// Gallery room with painted floor strips (crimson, gold, emerald) so moving spotlight spawns colored RSM bounce!\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(1.0 + p.y, 1.0); // floor\n  float cD = 1.0 - p.y; if (cD < res.x) res = vec2(cD, 2.0);\n  float bD = 1.45 + p.z; if (bD < res.x) res = vec2(bD, 2.0);\n  float lD = 1.45 + p.x; if (lD < res.x) res = vec2(lD, 2.0);\n  float rD = 1.45 - p.x; if (rD < res.x) res = vec2(rD, 2.0);\n\n  // Two matte white sculptural columns & floating orb to catch indirect RSM bounce light\n  float dCol1 = sdBox(p - vec3(-0.72, -0.35, -0.55), vec3(0.22, 0.65, 0.22)) - 0.02;\n  if (dCol1 < res.x) res = vec2(dCol1, 3.0);\n  float dCol2 = sdBox(p - vec3(0.72, -0.35, -0.55), vec3(0.22, 0.65, 0.22)) - 0.02;\n  if (dCol2 < res.x) res = vec2(dCol2, 3.0);\n  float dOrb = length(p - vec3(0.0, 0.12, -0.45)) - 0.34;\n  if (dOrb < res.x) res = vec2(dOrb, 3.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,\n    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,\n    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x\n  ));\n}\n\n// Vivid painted floor mosaic so the RSM bounce color changes dramatically as the spotlight sweeps across it\nvec3 floorMosaic(vec2 xz) {\n  if (xz.x < -0.38) return vec3(0.92, 0.18, 0.16);\n  if (xz.x > 0.38) return vec3(0.12, 0.72, 0.94);\n  return vec3(0.96, 0.68, 0.14);\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 rsmGain = max(P_RSM_GAIN, 0.0);\n  float tAnim = iTime * max(P_SPOT_SWEEP, 0.0);\n  float vplVis = clamp(P_VPL_DOTS, 0.0, 1.6);\n\n  vec3 ro = vec3(0.0, 0.12, 2.38);\n  vec3 rd = normalize(vec3(uv, -1.48));\n\n  // Sweeping overhead spotlight hitting the painted floor mosaic\n  vec3 spotOrig = vec3(0.0, 0.94, 0.30);\n  vec3 spotTarget = vec3(0.82 * sin(tAnim * 0.62), -1.0, -0.22 + 0.32 * cos(tAnim * 0.48));\n  vec3 spotAxis = normalize(spotTarget - spotOrig);\n\n  vec3 col = vec3(0.02);\n  float t = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapScene(ro + rd * t);\n    if (h.x < 0.002) { hit = true; matId = h.y; break; }\n    t += h.x;\n    if (t > 10.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n\n    vec3 alb = vec3(0.76, 0.77, 0.78);\n    if (matId < 1.5) alb = floorMosaic(p.xz);\n    else if (matId > 2.5) alb = vec3(0.86, 0.86, 0.84);\n\n    // Direct spotlight illumination with shadow ray\n    vec3 toL = spotOrig - p;\n    float dL = length(toL);\n    vec3 lDir = toL / max(dL, 1e-4);\n    float spotCone = smoothstep(0.86, 0.96, dot(-lDir, spotAxis));\n    float sh = 1.0;\n    float ts = 0.03;\n    for (int i = 0; i < 24; i++) {\n      float dh = mapScene(p + lDir * ts).x;\n      if (dh < 0.004) { sh = 0.0; break; }\n      ts += dh;\n      if (ts > dL - 0.08) break;\n    }\n    vec3 direct = alb * vec3(3.2, 2.95, 2.6) * max(dot(n, lDir), 0.0) * spotCone * sh / (1.0 + 0.22 * dL * dL);\n\n    // Reflective Shadow Map (RSM) Gather: 12 importance-sampled pixel light VPLs inside the spotlight patch!\n    vec3 rsmIndirect = vec3(0.0);\n    float vplDotGlow = 0.0;\n    vec3 vplDotCol = vec3(0.0);\n    for (int k = 0; k < 12; k++) {\n      float fk = float(k);\n      // Golden-angle concentric disk sampling of the RSM texel footprint\n      float rDisk = sqrt((fk + 0.5) / 12.0) * 0.42;\n      float ang = fk * 2.399963 + 0.3;\n      vec3 vplPos = vec3(\n        clamp(spotTarget.x + cos(ang) * rDisk, -1.38, 1.38),\n        -0.995,\n        clamp(spotTarget.z + sin(ang) * rDisk, -1.38, 0.85)\n      );\n      vec3 vplN = vec3(0.0, 1.0, 0.0);\n      vec3 vplFlux = floorMosaic(vplPos.xz) * (1.0 - rDisk * 1.4);\n\n      vec3 toVpl = vplPos - p;\n      float dist2 = dot(toVpl, toVpl);\n      float dist = sqrt(max(dist2, 1e-5));\n      vec3 dirV = toVpl / dist;\n\n      // RSM form factor: max(0, dot(n_p, dir)) * max(0, dot(n_vpl, -dir)) / (d^2 + clamp)^2\n      float cosP = max(dot(n, dirV), 0.0);\n      float cosV = max(dot(vplN, -dirV), 0.0);\n      float geom = (cosP * cosV) / pow(max(dist2 + 0.16, 0.16), 1.35);\n      rsmIndirect += vplFlux * geom;\n\n      // Visible VPL sample indicator dot on the lit floor patch\n      if (matId < 1.5 && vplVis > 0.01) {\n        float dotM = smoothstep(0.042, 0.016, length(p.xz - vplPos.xz));\n        vplDotGlow = max(vplDotGlow, dotM);\n        if (dotM > 0.05) vplDotCol = vplFlux * 1.8 + vec3(0.4);\n      }\n    }\n    rsmIndirect = alb * (rsmIndirect / 12.0) * 4.8 * rsmGain;\n\n    vec3 leftCol = direct + alb * vec3(0.025, 0.03, 0.04);\n    vec3 rightCol = direct + rsmIndirect + alb * vec3(0.025, 0.03, 0.04);\n    rightCol = mix(rightCol, vplDotCol, vplDotGlow * 0.85 * min(vplVis, 1.2));\n    col = (screenX < split) ? leftCol : rightCol;\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "reduced-sandbox",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "reflective-shadow-maps",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:36.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.3997,
      "std": 0.2794,
      "min": 0.0727,
      "max": 0.9713
     },
     "image": "/specimens/reflective-shadow-maps-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "light-propagation-volumes",
  "instant-radiosity",
  "screen-space-gi"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "light-propagation-volumes",
   "why": "The RSM's flux, normals and positions are injected as virtual point lights into the volume."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/gi/reflective-shadow-maps.json"
 },
 "solves": [
  "first bounce indirect light for dynamic scenes",
  "color bleeding from a spot or sun light",
  "cheap gi using light's view of the scene",
  "indirect illumination without baking or ray tracing"
 ],
 "authority": "Dachsbacher & Stamminger, 2005",
 "url": "https://texelatlas.vercel.app/t/reflective-shadow-maps/",
 "execution_fidelity": "reduced-sandbox",
 "fidelity_label": "Analytic Sandbox",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 40.68,
  "tier": "heavy",
  "p50_ms": 1.2774,
  "p95_ms": 1.3466,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "reflective-shadow-maps-live",
  "execution_fidelity": "reduced-sandbox",
  "fidelity_label": "Analytic Sandbox",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 41.77,
   "tier": "heavy",
   "p50_ms": 0.66,
   "p95_ms": 0.6622,
   "speedup_x": 1.94,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 24.93,
   "tier": "heavy",
   "p50_ms": 0.718,
   "p95_ms": 0.7201,
   "speedup_x": 1.78,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}