Soft Shadows for Multi-Light glTF Scenes
Simulating realistic soft shadows in multi-light glTF scenes requires balancing visual fidelity with strict rendering performance constraints. This article examines the primary real-time techniques used in modern WebGL and WebGPU engines—such as Percentage-Closer Soft Shadows, shadow atlasing, pre-filtered shadow mapping, and screen-space passes—to achieve physically plausible, contact-hardening shadows across complex environments populated by multiple light sources.
Percentage-Closer Soft Shadows (PCSS)
Percentage-Closer Soft Shadows remain the industry standard for generating dynamic, contact-hardening shadows where the penumbra widens as the distance between the occluder and the receiver increases.
In a glTF rendering pipeline, PCSS operates in three distinct phases per light:
- Blocker Search: Samples the shadow map to calculate the average depth of potential occluders relative to the receiver.
- Penumbra Estimation: Computes the filter kernel size using parallel-plane approximations based on light source size, receiver depth, and blocker depth.
- Percentage-Closer Filtering (PCF): Applies Poisson-disk or stochastic sampling over the dynamically sized kernel to produce a smooth, anti-aliased gradient.
While physically convincing, PCSS is computationally heavy. Running
full PCSS across scenes with numerous glTF punctual lights (defined via
the KHR_lights_punctual extension) can quickly exhaust
texture sampling bandwidth.
Shadow Atlasing and Clustered Shading
Handling soft shadows across multiple lights requires architectural management of GPU memory. Creating distinct shadow maps for dozens of lights causes severe overhead due to constant framebuffer switching.
- Shadow Atlasing: Engines pack all shadow-casting lights into a single, high-resolution texture atlas. Dynamic allocation algorithms adjust the viewport resolution for each light based on screen-space coverage, distance to the camera, and light intensity.
- Clustered Forward or Deferred Rendering: The viewing frustum is subdivided into a 3D grid of clusters. Only the lights and corresponding shadow atlas viewports affecting a specific cluster are evaluated in the fragment shader, preventing unnecessary shadow map lookups on non-illuminated glTF geometry.
Variance and Exponential Shadow Maps (VSM and ESM)
For multi-light environments where dynamic PCSS sampling loops are too costly, pre-filterable shadow algorithms like Variance Shadow Maps (VSM) and Exponential Shadow Maps (ESM) offer a practical alternative.
- Separable Filtering: Unlike standard depth maps, VSM and ESM store depth distributions that allow standard image-space blurring (such as Gaussian or box filters) to be applied directly to the shadow maps before scene rendering.
- Performance Gains: Because the shadow map is pre-filtered, the scene shader only requires a few samples rather than an extensive PCF loop, significantly reducing per-pixel texture fetches across multiple lights.
- Trade-offs: These methods can introduce light-bleeding artifacts in complex, overlapping glTF geometries unless constrained by geometric bias algorithms or minimum variance clamping.
Screen-Space Contact Shadows (SSCS)
glTF assets often contain intricate mechanical or architectural details that standard shadow maps lack the resolution to capture, leading to "peter-panning" (shadow detachment).
Screen-Space Contact Shadows cast short-range rays through the depth buffer directly in screen space. When combined with medium-resolution shadow maps or atlases, SSCS injects sharp, immediate occlusion at the base of glTF meshes. This allows developers to soften global shadow maps aggressively without losing critical contact fidelity at geometric intersections.
Real-Time Ray Tracing and Denoising
In modern WebGPU and native pipelines, hybrid ray-traced shadows represent the state of the art. Rays are cast directly into acceleration structures built from glTF scene nodes:
- A low number of rays (often one or two rays per pixel per light) are cast toward an area light source to check for line-of-sight occlusion.
- Spatiotemporal denoisers, such as Spatiotemporal Variance-Guided Filtering (SVGF), accumulate samples over time and blur noisy data along geometric normal and depth edges.
This produces physically accurate penumbras, naturally supports arbitrary light shapes, and scales efficiently across multi-light configurations by utilizing temporal coherence rather than high per-frame sample counts.