Moment Shadow Maps × Froxel Volumetric Fog
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.
Open in StudioReproduced203× · 6.31 ms
Verified proof

Split-screen WebGL2 proof comparing hard point-sampled shadow-map lookups inside a froxel volumetric fog hall (left, producing quantized jagged beam slicing behind thin architectural louvres) against 4-moment Hamburger Moment Shadow Maps (MSM) prefiltered at the froxel footprint (right, yielding smooth non-flickering light shafts and matching soft surface shadows).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · replaces binary shadow-texel shaft aliasing behind thin louvre mullions with footprint-prefiltered 4-moment Hamburger visibility across 32 exponential froxel slices
Show GLSL proof (187 lines)
const float FOG_DENSITY = 0.44; // P
const float SCATTER_G = 0.72; // P
const float FILTER_FOOTPRINT = 1.35; // P
const float BEAM_INTENSITY = 3.20; // P
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);
}
// Sunlit brutalist colonnade nave with narrow slatted overhead skylight bays casting crisp diagonal shafts
float mapHall(vec3 p) {
float fl = p.y + 1.05;
float backW = p.z + 4.8;
float sideWalls = 2.05 - abs(p.x);
float ceilSlab = 1.62 - p.y;
float skyCut = sdBox(p - vec3(0.0, 1.70, -1.75), vec3(1.15, 0.35, 2.25));
float ceiling = max(ceilSlab, -skyCut);
// Bold roof coffer beams separating 4 distinct skylight bays
vec3 lp = p - vec3(0.0, 1.58, -1.75);
float bayZ = abs(fract(lp.z * 0.95 + 0.5) - 0.5) / 0.95;
float beams = max(max(abs(lp.y) - 0.12, abs(lp.x) - 1.25), max(abs(lp.z) - 2.30, bayZ - 0.24));
// Side colonnade pillars
vec3 cp = p;
cp.z = mod(cp.z + 0.55, 1.25) - 0.625;
float pillars = sdBox(vec3(abs(cp.x) - 1.32, cp.y - 0.28, cp.z), vec3(0.16, 1.38, 0.16));
// Central dark basalt altar plinth catching the volumetric pools
float plinth = sdBox(p - vec3(0.0, -0.78, -2.05), vec3(0.42, 0.28, 0.34)) - 0.02;
float d = min(min(fl, backW), min(sideWalls, ceiling));
d = min(d, min(beams, min(pillars, plinth)));
return d;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0025, -0.0025);
return normalize(e.xyy * mapHall(p + e.xyy) + e.yyx * mapHall(p + e.yyx) + e.yxy * mapHall(p + e.yxy) + e.xxx * mapHall(p + e.xxx));
}
// Analytic directional light shadow-map depth z in [0, 1] on the overhead skylight plane (blocks ~62% for bold shaft contrast)
float shadowMapDepth(vec2 suv) {
float xSky = suv.x;
float zSky = suv.y;
if (abs(xSky) > 1.12 || abs(zSky + 1.75) > 2.22) return 0.14;
// Wide transverse roof coffer beams (create dark gaps between bright sunbeams)
float bayCell = abs(fract((zSky + 1.75) * 0.95 + 0.5) - 0.5) / 0.95;
if (bayCell < 0.26) return 0.16;
// Thin high-frequency louvre slats inside each bay (trigger severe point-sampling flicker & slicing on left!)
float slatZ = abs(fract((zSky + 1.75) * 4.75 + 0.25) - 0.5) / 4.75;
if (slatZ < 0.045) return 0.19;
float slatX = abs(fract(xSky * 3.4 + 0.5) - 0.5) / 3.4;
if (slatX < 0.052) return 0.20;
return 0.96;
}
// 4-Moment Hamburger Moment Shadow Map solver (Peters & Klein 2015)
float solveHamburgerMSM(vec4 b, float zf) {
const float alpha = 0.0025;
b = mix(b, vec4(0.5, 0.5, 0.5, 0.5), alpha);
float L21D11 = b.x;
float L31D11 = b.y;
float D22 = max(b.y - b.x * b.x, 1e-5);
float L32D22 = b.z - b.y * b.x;
float L32 = L32D22 / D22;
float D33 = max(b.w - b.y * b.y - L32 * L32D22, 1e-5);
vec3 c = vec3(1.0, zf, zf * zf);
c.y -= L21D11 * c.x;
c.z -= L31D11 * c.x + L32 * c.y;
c.y /= D22;
c.z /= D33;
c.y -= L32 * c.z;
c.x -= L21D11 * c.y + L31D11 * c.z;
float disc = max(c.y * c.y - 4.0 * c.z * c.x, 0.0);
float sq = sqrt(disc);
float inv2a = 1.0 / (abs(c.z) > 1e-6 ? 2.0 * c.z : 1e-6);
float z2 = (-c.y - sq) * inv2a;
float z3 = (-c.y + sq) * inv2a;
if (z2 > z3) { float tmp = z2; z2 = z3; z3 = tmp; }
float occ = 0.0;
if (zf <= z2) {
occ = 0.0;
} else if (zf <= z3) {
float denom = max((z3 - z2) * (zf - z2), 1e-5);
occ = clamp((zf * z3 - b.x * (zf + z3) + b.y) / denom, 0.0, 1.0);
} else {
float denom = max((zf - z2) * (zf - z3), 1e-5);
occ = clamp(1.0 - (z2 * z3 - b.x * (z2 + z3) + b.y) / denom, 0.0, 1.0);
}
return 1.0 - clamp(occ, 0.0, 1.0);
}
float evalShadowVis(vec3 p, vec3 lightDir, float footprint, bool useMSM) {
float tToSky = (1.58 - p.y) / max(lightDir.y, 0.08);
vec3 onSky = p + lightDir * tToSky;
vec2 suv = vec2(onSky.x, onSky.z);
float zf = clamp((1.72 - p.y) / 3.0, 0.02, 0.98);
if (!useMSM) {
// Point-sampled coarse shadow-map texel grid -> quantized jagged light shafts & flicker behind thin slats
float texel = 0.115;
vec2 qsu = (floor(suv / texel) + 0.5) * texel;
float zOcc = shadowMapDepth(qsu);
return step(zf, zOcc + 0.01);
}
// Prefiltered 4-moment shadow map lookup over froxel shadow-space footprint
vec4 b = vec4(0.0);
float wSum = 0.0;
float rad = clamp(footprint * FILTER_FOOTPRINT, 0.025, 0.34);
for (int ix = -1; ix <= 1; ix++) {
for (int iz = -2; iz <= 2; iz++) {
vec2 o = vec2(float(ix), float(iz) * 0.5);
float w = exp(-0.5 * dot(o, o));
float z = shadowMapDepth(suv + o * rad);
float z2 = z * z;
b += w * vec4(z, z2, z2 * z, z2 * z2);
wSum += w;
}
}
b /= wSum;
return solveHamburgerMSM(b, zf);
}
float hgPhase(float cosTheta, float g) {
float g2 = g * g;
return (1.0 - g2) / (4.0 * 3.1415926 * pow(max(1.0 + g2 - 2.0 * g * cosTheta, 0.05), 1.5));
}
vec3 acesTone(vec3 x) {
return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
bool useMSM = uv.x > 0.0;
vec2 suv = vec2(useMSM ? uv.x - 0.25 : uv.x + 0.25, uv.y);
vec3 ro = vec3(0.14 * sin(iTime * 0.26), 0.02, 1.58);
vec3 ta = vec3(0.0, -0.02, -2.1);
vec3 fw = normalize(ta - ro);
vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));
vec3 up = cross(rt, fw);
vec3 rd = normalize(fw * 1.42 + rt * (suv.x * 1.25) + up * suv.y);
// Warm afternoon sun pouring diagonally forward-downward through the overhead skylight louvers
vec3 sunDir = normalize(vec3(-0.32, 0.78, -0.54 + 0.04 * sin(iTime * 0.35)));
float tHit = 0.0;
bool hit = false;
for (int i = 0; i < 84; i++) {
float d = mapHall(ro + rd * tHit);
if (d < 0.0025) { hit = true; break; }
tHit += d;
if (tHit > 10.5) break;
}
vec3 surfCol = vec3(0.008, 0.015, 0.032);
if (hit) {
vec3 pos = ro + rd * tHit;
vec3 n = calcNormal(pos);
if (pos.y > 1.60 && abs(pos.x) < 1.14 && abs(pos.z + 1.75) < 2.24) {
surfCol = vec3(5.2, 3.4, 1.55);
} else {
float block = 0.88 + 0.12 * sin(pos.x * 8.0) * cos(pos.z * 6.0 + pos.y * 5.0);
vec3 alb = vec3(0.16, 0.17, 0.19) * block;
if (pos.y < -1.02) alb *= 0.85;
float vis = evalShadowVis(pos + n * 0.03, sunDir, 0.055, useMSM);
float ndl = max(dot(n, sunDir), 0.0);
vec3 direct = vec3(4.8, 2.85, 1.15) * ndl * vis;
vec3 ambient = mix(vec3(0.010, 0.022, 0.052), vec3(0.045, 0.065, 0.105), 0.5 + 0.5 * n.y);
surfCol = alb * (direct + ambient);
}
}
// 32 exponential froxel depth slices integrating volumetric in-scattering & Beer-Lambert transmittance
float maxT = hit ? tHit : 8.5;
const int SLICES = 32;
vec3 inScatter = vec3(0.0);
float trans = 1.0;
float phase = hgPhase(dot(rd, sunDir), clamp(SCATTER_G, 0.05, 0.90)) * 2.6;
vec3 beamCol = vec3(1.0, 0.62, 0.20) * BEAM_INTENSITY;
vec3 ambFog = vec3(0.009, 0.022, 0.058);
float j = fract(52.9829189 * fract(dot(fragCoord.xy, vec2(0.06711056, 0.00583715))));
float prevT = 0.22;
for (int i = 0; i < SLICES; i++) {
float u1 = (float(i) + 0.5 + (useMSM ? (j - 0.5) * 0.85 : 0.0)) / float(SLICES);
float nextT = mix(0.22, maxT, u1 * u1 * 0.45 + u1 * 0.55);
float ds = max(nextT - prevT, 0.01);
float midT = 0.5 * (prevT + nextT);
vec3 fpPos = ro + rd * midT;
float froxelFp = 0.032 + midT * 0.028;
float vis = evalShadowVis(fpPos, sunDir, froxelFp, useMSM);
float dust = FOG_DENSITY * (0.24 + 0.14 * exp(-max(fpPos.y + 1.05, 0.0) * 1.15) + 0.04 * sin(fpPos.z * 2.4 + iTime * 0.45));
float stepTrans = exp(-dust * ds);
vec3 light = beamCol * vis * (0.14 + phase) + ambFog;
inScatter += trans * light * (1.0 - stepTrans);
trans *= stepTrans;
prevT = nextT;
}
vec3 col = surfCol * trans + inScatter;
col = acesTone(col);
if (abs(uv.x) < 0.003) col = vec3(0.95, 0.92, 0.86);
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Why they connect
Moment Shadow Maps consumes the light's depth and outputs a visibility-mask reconstructed from four filtered depth moments. Froxel Volumetric Fog takes visibility-mask as an input when it lights each froxel: instead of a point sample, it reads the moment map at a mip level matching the froxel's footprint in shadow-map space, so thin casters contribute partial visibility rather than flickering on and off. The fog then integrates in-scattering and transmittance along depth and outputs radiance and volume-density for compositing.
How to build it
Unity, Godot or a custom renderer. Render a four-moment shadow map per light or cascade into a 16-bit target with the paper's optimised quantisation transform, then blur and mip it. In the froxel lighting pass, project each froxel's corners into shadow space to estimate footprint size and choose the mip, then reconstruct visibility with the moment solve. Keep the usual temporal jitter and history blend. Use the same moment map for surface shadows with a smaller filter, so fog and surfaces agree on where shadows fall.
Field marks
- Residual moment-map leaks show as faint glowing fog behind occluders.
- Memory per cascade is higher than for plain depth maps.
- Wrong mip selection over- or under-blurs the shafts.
- Large blurs remove shafts that should stay crisp near the caster.
Prior art
No prior art found on 2026-11-29.
Searches run (4)
- arXiv: all:"moment shadow maps" AND all:"single scattering" → 0 results
- GitHub repos: "moment shadow maps" "single scattering" → 0 results
- arXiv: all:"volumetric fog" AND all:"filtered shadow maps" → 0 results
- GitHub repos: "volumetric fog" "filtered shadow maps" → 0 results