Overview
Three.js offers several shadow map filtering modes, and choosing one affects both how shadows look and what artefacts appear. This demo renders the same animated scene three times side by side, with PCFShadowMap, PCFSoftShadowMap and VSMShadowMap, under identical lighting, so you can compare them directly and tune the shared parameters.
How it works
All three modes start from the same depth map rendered from the light's point of view. They differ in how a pixel decides whether it is shadowed:
- PCF (percentage-closer filtering) compares the pixel's depth against several nearby texels in the shadow map and averages the pass/fail results, giving slightly softened, mostly crisp edges.
- PCFSoft uses a wider sampling pattern for smoother edges at a modest extra cost. The
radiussetting has limited effect with it. - VSM (variance shadow maps) stores the depth and the square of the depth, blurs them, and uses Chebyshev's inequality to estimate how much of the pixel is shadowed. It supports large, smooth blurs controlled by
shadow.radiusandblurSamples, but can show light bleeding where several occluders overlap.
The demo renders the scene into three viewport regions each frame, switching renderer.shadowMap.type between them, with shared controls for map size, bias, radius and light intensity.
Exploring the demo
Compare the edge of the same shadow across the three panels. Increase the radius and watch VSM soften while the PCF variants change much less. Lower the map size to expose each method's behaviour with fewer texels, and adjust the bias to find the point where shadow acne disappears without shadows detaching from objects.
Practical advice
PCFSoftShadowMap is a good default for most scenes. Use VSM when you want broad, soft shadows and can tolerate or design around light bleeding. Shadow quality is limited more by map resolution and frustum fit than by filtering, so tune those first using the directional shadow visualiser. For large scenes see cascaded shadow maps, and for soft grounding see contact shadows.