Moment Shadow Maps
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.
In the family Visibility, shadows & ambient occlusion, prefiltered shadow maps
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | Built in | HDRP Asset > Lighting > Shadows > Directional Shadow Filtering = Improved Moment Shadows docs HDRP only, directional lights (Improved Moment Shadows). |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
Reach for it when
- 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
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.
Field marks
- 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
Presets
Moment Shadow Maps (MSM) — 2-moment VSM light bleeding under stacked occluders (left) vs 4-moment Hamburger MSM (right)
{
"P_FILTER_RAD": 0.75,
"P_LIGHT_SWEEP": 0.55,
"P_BLEED_DEMO": 0.85,
"P_SPLIT": 0.48
}Show GLSL (156 lines)
const float P_FILTER_RAD = 0.75; // P Filter Penumbra [0.2, 1.5, 0.05]
const float P_LIGHT_SWEEP = 0.55; // P Light Motion [0.0, 1.6, 0.05]
const float P_BLEED_DEMO = 0.85; // P Occluder Depth Gap [0.2, 1.2, 0.05]
const float P_SPLIT = 0.48; // P VSM Bleed / 4-MSM [0.0, 1.0, 0.02]
// Evaluate light-space depth map of two vertically stacked occluders (classic VSM light-bleeding stress test!)
float shadowDepthMap(vec2 lp, float gap) {
float zFloor = 2.60;
// Upper floating slab at closer depth (z = 1.15 - gap * 0.35)
float dTop = max(abs(lp.x - 0.14) - 0.32, abs(lp.y - 0.04) - 0.22);
// Lower bar closer to floor (z = 2.05) overlapping upper slab's penumbra!
float dBot = max(abs(lp.x + 0.10) - 0.42, abs(lp.y + 0.02) - 0.26);
float z = zFloor;
if (dBot < 0.0) z = min(z, 2.02);
if (dTop < 0.0) z = min(z, 1.12 - gap * 0.32);
return z;
}
// 4-moment Hamburger Moment Shadow Map closed-form Cholesky + quadratic solver (Peters & Klein 2015)
float computeMSM4(vec4 b, float zf) {
// Small bias toward uniform distribution for numerical stability
float alpha = 0.002;
vec4 m = mix(b, vec4(0.5, 0.333333, 0.25, 0.2), alpha);
float L21D11 = m.y - m.x * m.x;
float D11 = max(L21D11, 1e-5);
float L21 = (m.z - m.x * m.y) / D11;
float D22 = max(m.w - m.y * m.y - L21 * (m.z - m.x * m.y), 1e-5);
// Solve symmetric positive-definite 3x3 Hankel system for quadratic c0 + c1*z + c2*z^2 = 0
vec3 zVec = vec3(1.0, zf, zf * zf);
float c0 = zVec.x;
float c1 = (zVec.y - m.x * c0) / D11;
float c2 = (zVec.z - m.y * c0 - (m.z - m.x * m.y) * c1) / D22;
float p1 = c1 - L21 * c2;
float p0 = c0 - m.x * p1 - m.y * c2;
// Find roots z2, z3 of p2*z^2 + p1*z + p0 = 0
float A = c2;
float B = p1;
float C = p0;
float disc = max(B * B - 4.0 * A * C, 0.0);
float sD = sqrt(disc);
float r1 = (-B - sD) / (2.0 * A + sign(A) * 1e-6);
float r2 = (-B + sD) / (2.0 * A + sign(A) * 1e-6);
float z2 = min(r1, r2);
float z3 = max(r1, r2);
if (zf <= z2) return 0.0;
if (zf <= z3) {
float num = zf * z3 - m.x * (zf + z3) + m.y;
float den = max((z3 - z2) * (zf - z2), 1e-5);
return clamp(num / den, 0.0, 1.0);
}
float num = z2 * z3 - m.x * (z2 + z3) + m.y;
float den = max((zf - z2) * (zf - z3), 1e-5);
return clamp(1.0 - num / den, 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 filtR = clamp(P_FILTER_RAD, 0.15, 1.6) * 0.09;
float gap = clamp(P_BLEED_DEMO, 0.15, 1.3);
float t = iTime * max(P_LIGHT_SWEEP, 0.0);
vec3 ro = vec3(0.0, 0.95, 1.85);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.42, -1.35));
vec3 lDir = normalize(vec3(0.24 * sin(t * 0.6), 0.95, 0.18 * cos(t * 0.5)));
vec3 col = mix(vec3(0.08, 0.11, 0.17), vec3(0.22, 0.30, 0.44), smoothstep(-0.3, 0.5, uv.y));
// Intersect receiver courtyard floor (y = -0.45) and the two floating caster slabs
float tMin = 1e5;
int hitId = 0;
vec3 hp = vec3(0.0);
vec3 hn = vec3(0.0, 1.0, 0.0);
if (rd.y < -0.005) {
float tf = (-0.45 - ro.y) / rd.y;
if (tf > 0.05 && tf < 14.0) {
tMin = tf; hitId = 1; hp = ro + rd * tf; hn = vec3(0.0, 1.0, 0.0);
}
}
// Two floating occluder slabs above the floor
vec3 invR = 1.0 / (rd + vec3(1e-6));
for (int k = 0; k < 2; k++) {
vec3 bc = (k == 0) ? vec3(-0.10, 0.08, 0.02) : vec3(0.14, 0.56 + gap * 0.16, -0.04);
vec3 br = (k == 0) ? vec3(0.36, 0.045, 0.22) : vec3(0.28, 0.045, 0.18);
vec3 t0 = (bc - br - ro) * invR;
vec3 t1 = (bc + br - ro) * invR;
vec3 tn = min(t0, t1), tf = max(t0, t1);
float tNear = max(max(tn.x, tn.y), tn.z);
float tFar = min(min(tf.x, tf.y), tf.z);
if (tFar > max(tNear, 0.05) && tNear < tMin) {
tMin = tNear; hitId = 2 + k; hp = ro + rd * tNear;
vec3 lp = (hp - bc) / br;
vec3 ap = abs(lp);
hn = (ap.x > ap.y && ap.x > ap.z) ? vec3(sign(lp.x), 0.0, 0.0)
: (ap.y > ap.z ? vec3(0.0, sign(lp.y), 0.0) : vec3(0.0, 0.0, sign(lp.z)));
}
}
if (hitId == 1) {
// Project floor point into light-space coordinates & integrate 5x5 pre-filtered shadow moments!
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));
float zNorm = 0.84; // Normalized depth of receiver floor in [0, 1]
vec4 moments = vec4(0.0);
float wSum = 0.0;
for (int j = -2; j <= 2; j++) {
for (int i = -2; i <= 2; i++) {
vec2 off = vec2(float(i), float(j)) * filtR * 0.55;
float zRaw = shadowDepthMap(lp + off, gap);
float z = clamp(zRaw / 3.0, 0.05, 0.98);
float w = exp(-dot(vec2(float(i), float(j)), vec2(float(i), float(j))) * 0.26);
moments += vec4(z, z * z, z * z * z, z * z * z * z) * w;
wSum += w;
}
}
moments /= max(wSum, 1e-4);
float lit = 1.0;
if (screenX < split) {
// Left: 2-Moment Variance Shadow Map (Chebyshev inequality -> severe light bleeding between stacked occluders!)
float mu = moments.x;
float variance = max(moments.y - mu * mu, 0.0004);
float d = max(zNorm - mu, 0.0);
float pMax = variance / (variance + d * d);
lit = (zNorm <= mu + 0.005) ? 1.0 : pMax;
} else {
// Right: 4-Moment Hamburger Moment Shadow Map -> tight upper bound eliminates light bleeding!
float occ = computeMSM4(moments, zNorm);
lit = 1.0 - occ;
}
vec2 g = hp.xz * 3.0;
float chk = mod(floor(g.x) + floor(g.y), 2.0);
vec3 floorAlb = mix(vec3(0.62, 0.60, 0.56), vec3(0.82, 0.80, 0.75), chk);
col = floorAlb * (vec3(0.18, 0.24, 0.34) + vec3(1.25, 1.14, 0.96) * lit);
col = mix(vec3(0.08, 0.11, 0.17), col, exp(-tMin * 0.12));
} else if (hitId >= 2) {
vec3 alb = (hitId == 2) ? vec3(0.24, 0.62, 0.84) : vec3(0.92, 0.48, 0.22);
float ndl = max(dot(hn, lDir), 0.0);
col = alb * (0.26 + 0.92 * ndl);
}
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.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| moment-shadow-maps-live | Tesla T4 1920x1080 | 6.70× baseline (moderate) · 0.220 ms / 0.235 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| moment-shadow-maps-live | NVIDIA L4 1920x1080 | 6.85× baseline (moderate) · 0.109 ms / 0.109 ms · 2.0× faster on L4 | opengl-timer-query · Cross-architecture validation |
| moment-shadow-maps-live | NVIDIA A100-SXM4-40GB 1920x1080 | 4.77× baseline (light) · 0.138 ms / 0.138 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Shadow Volumes, Shadow map depth bias (constant, slope-scale, normal offset), Percentage-Closer Soft Shadows, Sample Distribution Shadow Maps (SDSM), Shadow Mapping.
Crosses
- Fog shafts that do not flicker: Volumetric fog whose light shafts stay soft and stable behind foliage and fences. Prefiltered moment shadow maps let each froxel fetch the average visibility over its footprint in one lookup instead of point-sampling a hard shadow map.
Sources
- primaryChristoph Peters, Reinhard Klein (2015). Moment shadow mapping. Proceedings of the 19th Symposium on Interactive 3D Graphics and Games.Verified via crossref · 2026-11-29doi:10.1145/2699276.2699277
- tutorialChristoph Peters. Moment Shadow Mapping. momentsingraphics.de.Verified via live page · 2026-11-29