{
 "id": "moment-shadow-maps",
 "title": "Moment Shadow Maps",
 "aliases": [],
 "domain": "visibility",
 "subdomain": "prefiltered shadow maps",
 "stage": "visibility",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2015,
 "inputs": [
  "depth"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Stores four power moments of depth per texel so that filtered shadow maps give a tight bound on visibility, avoiding most of the light bleeding of variance shadow maps.",
 "how_it_works": "Where VSM keeps two moments, moment shadow mapping stores the first four (z, z^2, z^3, z^4), usually after a small optimised linear transform that improves quantisation in 16-bit targets. Moments are linear, so the map is blurred or mipmapped like any texture. At shade time the filtered moments define a canonical distribution, and a short closed-form solve (a Cholesky decomposition and a quadratic or cubic root find) yields the extremal fraction of the footprint that can be in front of the receiver, which is the shadow intensity. The extra moments encode more of the depth histogram than a mean and variance, which is why overlapping occluders no longer produce large leaks.",
 "when_to_use": "Choose it when you want filterable soft shadows and plain VSM or EVSM bleed visibly, and you can afford a four-channel target. Prefer `exponential-variance-shadow-maps` when you prefer simpler shader maths, `percentage-closer-soft-shadows` for contact hardening, and `percentage-closer-filtering` when a depth-only map is mandatory.",
 "cost": {
  "class": "cheap",
  "notes": "Four channels per texel plus a blur pass; shading includes a small per-pixel solve, more arithmetic than VSM."
 },
 "failure_modes": [
  "Residual leaks and ringing when the moment problem is near-singular",
  "Needs a positive bias on moments to keep the solver stable",
  "Higher memory per cascade than VSM",
  "Float16 storage requires the paper's optimised transform"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/2699276.2699277",
   "type": "paper",
   "title": "Moment shadow mapping",
   "authors": [
    "Christoph Peters",
    "Reinhard Klein"
   ],
   "year": 2015,
   "venue": "Proceedings of the 19th Symposium on Interactive 3D Graphics and Games",
   "url": "https://doi.org/10.1145/2699276.2699277",
   "ids": {
    "doi": "10.1145/2699276.2699277"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2699276.2699277",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2699276.2699277",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2699276.2699277",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2699276.2699277",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2699276.2699277",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "peters2015moment"
  },
  {
   "role": "tutorial",
   "key": "url:https://momentsingraphics.de/I3D2015.html",
   "type": "tutorial",
   "title": "Moment Shadow Mapping",
   "authors": [
    "Christoph Peters"
   ],
   "year": null,
   "venue": "momentsingraphics.de",
   "url": "https://momentsingraphics.de/I3D2015.html",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261103101528/http://momentsingraphics.de/I3D2015.html",
     "timestamp": "20261103101528"
    },
    "page_title": "Moment Shadow Mapping",
    "host": "momentsingraphics.de",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://momentsingraphics.de/I3D2015.html → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://momentsingraphics.de/I3D2015.html → 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://momentsingraphics.de/I3D2015.html → 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": 1,
   "__bib": "petersmoment"
  }
 ],
 "presets": [
  {
   "id": "moment-shadow-maps-live",
   "title": "Moment Shadow Maps (MSM) — 2-moment VSM light bleeding under stacked occluders (left) vs 4-moment Hamburger MSM (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_FILTER_RAD": 0.75,
    "P_LIGHT_SWEEP": 0.55,
    "P_BLEED_DEMO": 0.85,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_FILTER_RAD = 0.75; // P Filter Penumbra [0.2, 1.5, 0.05]\nconst float P_LIGHT_SWEEP = 0.55; // P Light Motion [0.0, 1.6, 0.05]\nconst float P_BLEED_DEMO = 0.85; // P Occluder Depth Gap [0.2, 1.2, 0.05]\nconst float P_SPLIT = 0.48; // P VSM Bleed / 4-MSM [0.0, 1.0, 0.02]\n\n// Evaluate light-space depth map of two vertically stacked occluders (classic VSM light-bleeding stress test!)\nfloat shadowDepthMap(vec2 lp, float gap) {\n  float zFloor = 2.60;\n  // Upper floating slab at closer depth (z = 1.15 - gap * 0.35)\n  float dTop = max(abs(lp.x - 0.14) - 0.32, abs(lp.y - 0.04) - 0.22);\n  // Lower bar closer to floor (z = 2.05) overlapping upper slab's penumbra!\n  float dBot = max(abs(lp.x + 0.10) - 0.42, abs(lp.y + 0.02) - 0.26);\n  float z = zFloor;\n  if (dBot < 0.0) z = min(z, 2.02);\n  if (dTop < 0.0) z = min(z, 1.12 - gap * 0.32);\n  return z;\n}\n\n// 4-moment Hamburger Moment Shadow Map closed-form Cholesky + quadratic solver (Peters & Klein 2015)\nfloat computeMSM4(vec4 b, float zf) {\n  // Small bias toward uniform distribution for numerical stability\n  float alpha = 0.002;\n  vec4 m = mix(b, vec4(0.5, 0.333333, 0.25, 0.2), alpha);\n  float L21D11 = m.y - m.x * m.x;\n  float D11 = max(L21D11, 1e-5);\n  float L21 = (m.z - m.x * m.y) / D11;\n  float D22 = max(m.w - m.y * m.y - L21 * (m.z - m.x * m.y), 1e-5);\n\n  // Solve symmetric positive-definite 3x3 Hankel system for quadratic c0 + c1*z + c2*z^2 = 0\n  vec3 zVec = vec3(1.0, zf, zf * zf);\n  float c0 = zVec.x;\n  float c1 = (zVec.y - m.x * c0) / D11;\n  float c2 = (zVec.z - m.y * c0 - (m.z - m.x * m.y) * c1) / D22;\n\n  float p1 = c1 - L21 * c2;\n  float p0 = c0 - m.x * p1 - m.y * c2;\n\n  // Find roots z2, z3 of p2*z^2 + p1*z + p0 = 0\n  float A = c2;\n  float B = p1;\n  float C = p0;\n  float disc = max(B * B - 4.0 * A * C, 0.0);\n  float sD = sqrt(disc);\n  float r1 = (-B - sD) / (2.0 * A + sign(A) * 1e-6);\n  float r2 = (-B + sD) / (2.0 * A + sign(A) * 1e-6);\n  float z2 = min(r1, r2);\n  float z3 = max(r1, r2);\n\n  if (zf <= z2) return 0.0;\n  if (zf <= z3) {\n    float num = zf * z3 - m.x * (zf + z3) + m.y;\n    float den = max((z3 - z2) * (zf - z2), 1e-5);\n    return clamp(num / den, 0.0, 1.0);\n  }\n  float num = z2 * z3 - m.x * (z2 + z3) + m.y;\n  float den = max((zf - z2) * (zf - z3), 1e-5);\n  return clamp(1.0 - num / den, 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 filtR = clamp(P_FILTER_RAD, 0.15, 1.6) * 0.09;\n  float gap = clamp(P_BLEED_DEMO, 0.15, 1.3);\n  float t = iTime * max(P_LIGHT_SWEEP, 0.0);\n\n  vec3 ro = vec3(0.0, 0.95, 1.85);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.42, -1.35));\n  vec3 lDir = normalize(vec3(0.24 * sin(t * 0.6), 0.95, 0.18 * cos(t * 0.5)));\n  vec3 col = mix(vec3(0.08, 0.11, 0.17), vec3(0.22, 0.30, 0.44), smoothstep(-0.3, 0.5, uv.y));\n\n  // Intersect receiver courtyard floor (y = -0.45) and the two floating caster slabs\n  float tMin = 1e5;\n  int hitId = 0;\n  vec3 hp = vec3(0.0);\n  vec3 hn = vec3(0.0, 1.0, 0.0);\n\n  if (rd.y < -0.005) {\n    float tf = (-0.45 - ro.y) / rd.y;\n    if (tf > 0.05 && tf < 14.0) {\n      tMin = tf; hitId = 1; hp = ro + rd * tf; hn = vec3(0.0, 1.0, 0.0);\n    }\n  }\n\n  // Two floating occluder slabs above the floor\n  vec3 invR = 1.0 / (rd + vec3(1e-6));\n  for (int k = 0; k < 2; k++) {\n    vec3 bc = (k == 0) ? vec3(-0.10, 0.08, 0.02) : vec3(0.14, 0.56 + gap * 0.16, -0.04);\n    vec3 br = (k == 0) ? vec3(0.36, 0.045, 0.22) : vec3(0.28, 0.045, 0.18);\n    vec3 t0 = (bc - br - ro) * invR;\n    vec3 t1 = (bc + br - ro) * invR;\n    vec3 tn = min(t0, t1), tf = max(t0, t1);\n    float tNear = max(max(tn.x, tn.y), tn.z);\n    float tFar = min(min(tf.x, tf.y), tf.z);\n    if (tFar > max(tNear, 0.05) && tNear < tMin) {\n      tMin = tNear; hitId = 2 + k; hp = ro + rd * tNear;\n      vec3 lp = (hp - bc) / br;\n      vec3 ap = abs(lp);\n      hn = (ap.x > ap.y && ap.x > ap.z) ? vec3(sign(lp.x), 0.0, 0.0)\n         : (ap.y > ap.z ? vec3(0.0, sign(lp.y), 0.0) : vec3(0.0, 0.0, sign(lp.z)));\n    }\n  }\n\n  if (hitId == 1) {\n    // Project floor point into light-space coordinates & integrate 5x5 pre-filtered shadow moments!\n    vec2 lp = hp.xz + (hp.y + 0.45) * lDir.xz / max(lDir.y, 0.2) + vec2(0.16 * sin(t * 0.6), 0.08 * cos(t * 0.5));\n    float zNorm = 0.84; // Normalized depth of receiver floor in [0, 1]\n    vec4 moments = vec4(0.0);\n    float wSum = 0.0;\n    for (int j = -2; j <= 2; j++) {\n      for (int i = -2; i <= 2; i++) {\n        vec2 off = vec2(float(i), float(j)) * filtR * 0.55;\n        float zRaw = shadowDepthMap(lp + off, gap);\n        float z = clamp(zRaw / 3.0, 0.05, 0.98);\n        float w = exp(-dot(vec2(float(i), float(j)), vec2(float(i), float(j))) * 0.26);\n        moments += vec4(z, z * z, z * z * z, z * z * z * z) * w;\n        wSum += w;\n      }\n    }\n    moments /= max(wSum, 1e-4);\n\n    float lit = 1.0;\n    if (screenX < split) {\n      // Left: 2-Moment Variance Shadow Map (Chebyshev inequality -> severe light bleeding between stacked occluders!)\n      float mu = moments.x;\n      float variance = max(moments.y - mu * mu, 0.0004);\n      float d = max(zNorm - mu, 0.0);\n      float pMax = variance / (variance + d * d);\n      lit = (zNorm <= mu + 0.005) ? 1.0 : pMax;\n    } else {\n      // Right: 4-Moment Hamburger Moment Shadow Map -> tight upper bound eliminates light bleeding!\n      float occ = computeMSM4(moments, zNorm);\n      lit = 1.0 - occ;\n    }\n\n    vec2 g = hp.xz * 3.0;\n    float chk = mod(floor(g.x) + floor(g.y), 2.0);\n    vec3 floorAlb = mix(vec3(0.62, 0.60, 0.56), vec3(0.82, 0.80, 0.75), chk);\n    col = floorAlb * (vec3(0.18, 0.24, 0.34) + vec3(1.25, 1.14, 0.96) * lit);\n    col = mix(vec3(0.08, 0.11, 0.17), col, exp(-tMin * 0.12));\n  } else if (hitId >= 2) {\n    vec3 alb = (hitId == 2) ? vec3(0.24, 0.62, 0.84) : vec3(0.92, 0.48, 0.22);\n    float ndl = max(dot(hn, lDir), 0.0);\n    col = alb * (0.26 + 0.92 * ndl);\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": "moment-shadow-maps",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:16.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7665,
      "std": 0.0937,
      "min": 0.4618,
      "max": 0.9014
     },
     "image": "/specimens/moment-shadow-maps-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "variance-shadow-maps",
  "exponential-variance-shadow-maps"
 ],
 "extends": [
  "variance-shadow-maps"
 ],
 "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/moment-shadow-maps.json"
 },
 "solves": [
  "variance shadow maps still leak light",
  "need filterable shadows with accurate occlusion",
  "soft shadow prefiltering without bleeding artifacts",
  "high quality blurred shadows on modest gpu memory"
 ],
 "authority": "Peters & Klein, 2015",
 "url": "https://texelatlas.vercel.app/t/moment-shadow-maps/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 6.7,
  "tier": "moderate",
  "p50_ms": 0.2203,
  "p95_ms": 0.2353,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "moment-shadow-maps-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 6.85,
   "tier": "moderate",
   "p50_ms": 0.1089,
   "p95_ms": 0.1092,
   "speedup_x": 2.02,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 4.77,
   "tier": "light",
   "p50_ms": 0.1375,
   "p95_ms": 0.1379,
   "speedup_x": 1.6,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}