Shadow Map Types Comparison (r183 roadmap)

Three-way split viewport that compares `PCFShadowMap`, `PCFSoftShadowMap`, and `VSMShadowMap` on the same animated scene and light setup.

Key topics: three.js shadows, pcf shadow map, pcfsoftshadowmap, vsmshadowmap, shadow quality

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 radius setting 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.radius and blurSamples, 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.

What this code does

- Side-by-Side Method: renders the same camera view three times per frame using different `renderer.shadowMap.type` values.
- Shadow Quality Tradeoff: PCF is sharper, PCFSoft is smoother, and VSM can produce soft penumbras with different artifact behavior.
- Shared Scene Baseline: identical geometry, animated motion, and light direction make differences easier to judge.
- Shadow Tuning Controls: includes map size, bias, radius, and light intensity sliders for practical balancing.
- Engineering Use: useful when selecting a default shadow method for product visuals versus stylized scenes.

Continue Learning

JavaScript Implementation

ES6+
renderer.shadowMap.enabled = true

// Compare map types by rendering the same scene with different values:
renderer.shadowMap.type = THREE.PCFShadowMap
renderer.render(scene, camera)

renderer.shadowMap.type = THREE.PCFSoftShadowMap
renderer.render(scene, camera)

renderer.shadowMap.type = THREE.VSMShadowMap
renderer.render(scene, camera)

Related demos

Trending this week

Most popular