three.js Lights and Shadows

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A light in three.js is an Object3D that contributes radiance to every lit material in the scene, and a shadow is an extra rendering pass that asks, for every light that is allowed to cast one, "what does the nearest surface look like from here?". This page explains the light classes and their units, the shadow map technique that three.js uses, every shadow option that matters, how to tune the artifacts it produces, and what the older books on the library got wrong because the defaults changed.

The facts were checked in November 2026 against three.js r187 (npm three@0.187.0) and its manual and API documentation. Everything here applies to the WebGLRenderer, which runs on WebGL 2 in every evergreen browser; the WebGPURenderer uses the same light classes and similar shadow properties, with the differences noted in the final sections and in WebGPURenderer and TSL. The examples are ES modules built with Vite, as set up in three.js Getting Started.

In the Bookshelf three.js track this page is the step where the shelf, loaded from bookshelf.glb in Loading Models and glTF, gets a desk lamp and soft shadows. The materials that react to these lights are in Materials and PBR, and the same ideas written by hand in a shader are in Lighting in Shaders. The renderer-independent theory is in Lighting and Shading Models and Shadows and Global Illumination.

The light classes

Six panels for AmbientLight, HemisphereLight, DirectionalLight, PointLight, SpotLight and RectAreaLight, with the intensity units and the number of shadow renders per light
Figure 1. The light classes, their shadow support and the units of their intensity

All lights share the base properties color, intensity and the castShadow flag (honoured only by the classes that can cast one). Lights are scene graph objects: a light can be a child of a group, moves with it, and is switched off with visible = false. Changing the number of lights, or the number of shadow-casting lights, makes three.js recompile the affected materials, so decide the set of lights up front and animate their intensity rather than adding and removing them.

Class What it models Main options Shadows

AmbientLight

Uniform light from every direction. It lifts the shadows evenly and carries no direction, so it flattens form.

color, intensity

No

HemisphereLight

A sky colour from above blended to a ground colour from below, the cheap stand-in for an outdoor or room environment.

color (sky), groundColor, intensity

No

DirectionalLight

Parallel rays from an infinitely distant source, such as the sun. Direction runs from position to target.position.

color, intensity, target

Yes, orthographic shadow camera

PointLight

A bare bulb that emits in all directions from a point.

color, intensity, distance, decay

Yes, six renders into a cube map

SpotLight

A cone from a point toward a target, like a desk lamp or a torch.

color, intensity, distance, angle, penumbra, decay

Yes, perspective shadow camera

RectAreaLight

A rectangular emitter such as a window or a softbox. It replaced the old AreaLight.

color, intensity, width, height

No

Three classes need a short note.

  • RectAreaLight works only with MeshStandardMaterial and MeshPhysicalMaterial, it has no castShadow, and it needs a one-time RectAreaLightUniformsLib.init() call (from three/addons/lights/RectAreaLightUniformsLib.js) before the first render.

  • DirectionalLight and SpotLight aim at their target object. The target is not in the scene by default, so its position is (0, 0, 0) unless you set it; if you move the target, add it to the scene (scene.add( light.target )) so that its world matrix is updated.

  • LightProbe and the environment texture are image-based lighting rather than punctual lights. They are covered with environment maps in Textures and Color Management.

Physically based units

Since r155 the renderer works in physical units by default, and the documentation of the light classes states them. The defaults changed in several steps (see Where the books are outdated), so older code shows lights that look much darker or brighter than the numbers suggest.

Light intensity unit Notes

PointLight

candela (cd)

power is the same quantity in lumens (lm); the relationship in the source is power = intensity * 4 * Math.PI. Setting one changes the other.

SpotLight

candela (cd)

power is also exposed; for a spot it also depends on the cone angle.

DirectionalLight

lux (lx)

Independent of distance, because the source is at infinity.

RectAreaLight

nits (cd per square metre)

Brightness of the emitting surface, so a larger rectangle lights more.

AmbientLight, HemisphereLight

illuminance-like value

No distance falloff. Treat the number as a fill level and tune it by eye.

The falloff of point and spot lights is controlled by two properties:

  • decay defaults to 2, the physically correct inverse-square law. The documentation advises leaving it alone for physically correct rendering. Before r147 the default was 1, which is why legacy scenes needed much smaller intensities.

  • distance defaults to 0, which means "no limit": the light attenuates by the inverse-square law all the way to infinity. A non-zero value fades the light smoothly to zero at that distance. This is useful as a performance and art-direction cutoff but is not physically correct.

Because the unit is candela, a point light at three metres from a surface with intensity = 100 delivers about \( 100 / 3^2 \approx 11 \) lux there. The scene scale matters: model the Bookshelf in metres (a shelf about a metre wide) and the numbers in the example below behave sensibly. Colour management and tone mapping decide how those values turn into display values; they are covered in Textures and Color Management.

How a shadow map works

three.js implements shadows with shadow mapping, in two passes per shadow-casting light, shown below.

Left panel: a light renders depth of the book and the shelf board into a shadow map. Right panel: the camera pass transforms each fragment into light space and compares its depth with the stored depth to decide lit or in shadow
Figure 2. Shadow mapping in two passes
  1. Depth pass. The renderer draws every object with castShadow = true from the point of view of the light, using the light’s shadow.camera, into a depth texture of shadow.mapSize pixels. The result is light.shadow.map.

  2. Lookup in the main pass. While shading, each fragment of an object with receiveShadow = true is transformed into the light’s clip space with light.shadow.matrix. Its depth is compared with the stored depth (plus the bias); if the fragment is farther, something is between it and the light, and the light’s contribution is removed.

This is the same technique taught in Shadows and Global Illumination and implemented by hand in the Bookshelf raw WebGL track. Three consequences follow, and every shadow option below is a way to manage one of them:

  • the depth texture has finite resolution, so shadows are blocky or blurry where one texel covers a large screen area;

  • the depth comparison has finite precision, so surfaces can shadow themselves ("acne") unless offset by a bias;

  • only the region covered by the shadow camera is shadowed, so it must be fitted to the scene.

Enabling shadows

Three switches must all be on, and forgetting one is the most common reason for "no shadows":

Where Property Meaning

Renderer

renderer.shadowMap.enabled = true

Turns the whole feature on. It is off by default (older books used renderer.shadowMapEnabled).

Light

light.castShadow = true

This light renders a shadow map. Only DirectionalLight, PointLight and SpotLight honour it.

Caster

mesh.castShadow = true

The mesh is drawn into the shadow map.

Receiver

mesh.receiveShadow = true

The mesh is darkened by shadow maps. A mesh can be both caster and receiver, which is what a book on a shelf board needs.

The flags are per Mesh, and Group and Object3D ignore them, which matters for models loaded from glTF: set them in a traverse loop, as in the example. The glTF format itself carries no shadow flags.

Shadow map types

renderer.shadowMap.type selects the filtering used when the map is sampled.

Constant Behaviour Use it when

THREE.BasicShadowMap

One depth comparison per fragment: hard, aliased edges. Cheapest.

Prototyping, or a deliberately hard-edged look.

THREE.PCFShadowMap

Percentage-closer filtering: several comparisons averaged, giving soft edges. The default, and since r182 it is soft as well. shadow.radius controls the width of the blur.

The normal choice.

THREE.PCFSoftShadowMap

Deprecated with WebGLRenderer in r182 (the migration guide says to use PCFShadowMap, "which is now soft as well"). With WebGPURenderer it was removed in r186.

Do not use in new code.

THREE.VSMShadowMap

Variance shadow maps: blurred with radius and blurSamples. Soft, but can show light bleeding where casters overlap.

Large soft shadows when the PCF result is too noisy.

The shadow object

Every shadow-capable light has a light.shadow object (DirectionalLightShadow, PointLightShadow or SpotLightShadow, all derived from LightShadow).

Property Default Purpose

mapSize

512 x 512

Resolution of the depth texture, a Vector2. Doubling both sides quadruples memory and fill cost. Typical values are 1024 to 4096. Set it before the first render or call shadow.map.dispose() after changing it.

camera

depends on the light

The camera that renders the depth pass. Directional: an OrthographicCamera; spot: a PerspectiveCamera whose field of view follows the light angle; point: a 90 degree PerspectiveCamera used six times.

bias

0

A constant offset added to the compared depth. Small negative values such as \( -0.0005 \) remove acne. Too large and shadows detach from their casters.

normalBias

0

Offsets the lookup position along the surface normal. It scales with slope, so it handles grazing angles better than bias and is the better first knob.

radius

1

Blur width for PCFShadowMap and VSMShadowMap.

blurSamples

8

Sample count for the VSMShadowMap blur.

autoUpdate, needsUpdate

true, false

With autoUpdate = false the map is rendered only when needsUpdate = true, then the flag resets. This is how static scenes avoid the depth pass entirely.

Fitting the shadow camera

The shadow camera is the main quality lever, because the map’s texels are spread across whatever the camera sees. A directional light’s orthographic camera defaults to a 10 by 10 unit box (left, right, top, bottom of -5 to 5) with near = 0.5 and far = 500. For a one metre shelf that wastes most of the resolution, so shrink it to the shelf:

const d = 1.2;                       // half-size of the shadowed region, metres
const cam = sun.shadow.camera;
cam.left = -d; cam.right = d;
cam.top = d;   cam.bottom = -d;
cam.near = 0.5; cam.far = 8;
cam.updateProjectionMatrix();        // required after changing the frustum

The most useful debugging tool is the camera helper:

import { CameraHelper } from 'three';

const helper = new CameraHelper( sun.shadow.camera );
scene.add( helper );
// after changing the frustum:
sun.shadow.camera.updateProjectionMatrix();
helper.update();

The picture of the frustum shows at once whether a caster is outside it (no shadow at all), whether far clips the receiver, and how much of the box is empty.

Bias, acne and peter panning

Three panels: bias too small gives striped self-shadowing on lit surfaces, a balanced bias gives a tight contact shadow, bias too large detaches the shadow from the object
Figure 3. The three bias regimes

Tune in this order and stop as soon as the artifact is gone:

  1. Fit the shadow camera and mapSize to the scene (above).

  2. Raise normalBias in small steps (0.01 to 0.05 for a scene in metres).

  3. If acne remains on flat surfaces, add a small negative bias (for example -0.0005).

  4. If shadows float away from objects, the offsets are too large; lower them.

A related trick is material.shadowSide: rendering back faces into the map (THREE.BackSide) moves the depth comparison away from the lit surface and removes acne on closed meshes, at the price of leaks on thin geometry. Notice also that after r183 the WebGPURenderer shadows were improved, so bias values that were added to hide acne there may now need to be reduced or removed.

The Bookshelf desk lamp

The complete example loads the shelf, adds a warm spot lamp that casts shadows, a weak hemisphere fill and a floor, and wires the renderer. It assumes the Vite project from the getting-started page, with bookshelf.glb placed in the public folder so that it is served at /bookshelf.glb.

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Bookshelf lights and shadows</title>
    <style>
      html, body { margin: 0; height: 100%; background: #111; }
      canvas { display: block; width: 100%; height: 100%; }
    </style>
  </head>
  <body>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>
src/main.js
import {
  ACESFilmicToneMapping, Box3, CameraHelper, Color, HemisphereLight, Mesh,
  MeshStandardMaterial, PCFShadowMap, PerspectiveCamera, PlaneGeometry,
  Scene, SpotLight, SpotLightHelper, Vector3, WebGLRenderer,
} from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

const renderer = new WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( Math.min( window.devicePixelRatio, 2 ) );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.toneMapping = ACESFilmicToneMapping;

// 1. Shadows must be enabled on the renderer first.
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = PCFShadowMap;          // soft by default since r182
document.body.appendChild( renderer.domElement );

const scene = new Scene();
scene.background = new Color( 0x15171c );

const camera = new PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.05, 50 );
camera.position.set( 1.6, 1.3, 2.4 );

const controls = new OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 0.6, 0 );
controls.update();

// 2. A weak sky/ground fill, so the shadows are not pitch black.
scene.add( new HemisphereLight( 0x9fb4d8, 0x2a2118, 0.35 ) );

// 3. The desk lamp: a SpotLight, intensity in candela, decay = 2 by default.
const lamp = new SpotLight( 0xffd9a8, 80, 0, Math.PI / 5, 0.5 );
lamp.position.set( 0.9, 1.8, 1.2 );
lamp.castShadow = true;
lamp.shadow.mapSize.set( 2048, 2048 );
lamp.shadow.camera.near = 0.5;
lamp.shadow.camera.far = 6;
lamp.shadow.bias = -0.0004;
lamp.shadow.normalBias = 0.02;
lamp.shadow.radius = 3;
scene.add( lamp );
scene.add( lamp.target );                        // lets the target's matrix update

// 4. A floor that only receives shadows.
const floor = new Mesh(
  new PlaneGeometry( 6, 6 ),
  new MeshStandardMaterial( { color: 0x3a3f4a, roughness: 0.9 } ),
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add( floor );

// 5. The shelf: set the shadow flags on every mesh of the loaded model.
const loader = new GLTFLoader();
const gltf = await loader.loadAsync( '/bookshelf.glb' );
gltf.scene.traverse( ( o ) => {
  if ( o.isMesh ) {
    o.castShadow = true;
    o.receiveShadow = true;
  }
} );
scene.add( gltf.scene );

// Aim the lamp at the middle of the model, whatever its size.
const box = new Box3().setFromObject( gltf.scene );
const centre = box.getCenter( new Vector3() );
lamp.target.position.copy( centre );

// Debug helpers: toggle with the "h" key.
const helpers = [ new SpotLightHelper( lamp ), new CameraHelper( lamp.shadow.camera ) ];
helpers.forEach( ( h ) => { h.visible = false; scene.add( h ); } );
window.addEventListener( 'keydown', ( e ) => {
  if ( e.key === 'h' ) helpers.forEach( ( h ) => { h.visible = ! h.visible; } );
} );

window.addEventListener( 'resize', () => {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize( window.innerWidth, window.innerHeight );
} );

renderer.setAnimationLoop( () => {
  helpers.forEach( ( h ) => h.visible && h.update() );
  renderer.render( scene, camera );
} );

The example uses top-level await, which Vite supports for modern build targets; wrap it in an async function if your target does not. Because the lamp, the shadow map and the flags all exist before the first frame, the first render already shows shadows and the shaders compile once. If the shelf appears black, check the units first: a lamp of 80 candela about two metres away delivers roughly 20 lux, so a model exported in centimetres (100 times larger than expected) needs a much higher intensity or a scale of 0.01.

Static scenes: render the shadow once

A shelf that does not move needs its shadow map only once. Disable automatic updates and request a refresh when something changes:

lamp.shadow.autoUpdate = false;
lamp.shadow.needsUpdate = true;      // renders the map on the next frame, then resets

// later, when a book moves:
function onBookMoved() {
  lamp.shadow.needsUpdate = true;
}

This removes one full scene render per light per frame. For the mini game later in the track, where books fall continuously, keep autoUpdate = true.

Point lights and cube shadows

A shadow-casting PointLight renders the scene six times into a cube-map layout, once per face, so it costs six depth passes. One lamp of this kind can cost more than a whole directional and spot rig, and each extra shadow-casting point light multiplies the cost. A common compromise is to light the room with a spot or a directional light that casts shadows and add point lights without shadows for colour. distance is useful here to stop the shadow camera from rendering far geometry: it also sets the far plane of the point light’s shadow.

import { PointLight } from 'three';

const bulb = new PointLight( 0xffe2b8, 40, 6 );  // 40 cd, cut off at 6 m, decay stays 2
bulb.position.set( 0, 2, 0 );
bulb.castShadow = true;
bulb.shadow.mapSize.set( 1024, 1024 );           // per face
bulb.shadow.bias = -0.002;
scene.add( bulb );

Area lights

RectAreaLight gives the soft, window-like highlight on glossy surfaces that point lights cannot, without shadows. It requires the uniforms library to be initialised once and works only with the physical material family:

import { RectAreaLight } from 'three';
import { RectAreaLightUniformsLib } from 'three/addons/lights/RectAreaLightUniformsLib.js';

RectAreaLightUniformsLib.init();                 // once, before the first render

const window1 = new RectAreaLight( 0xcfe6ff, 6, 1.2, 0.8 );   // colour, nits, width, height
window1.position.set( -1.5, 1.4, 0.5 );
window1.lookAt( 0, 0.8, 0 );
scene.add( window1 );

Pitfalls

Symptom Usual cause

No shadows at all

One of the four flags is missing (renderer, light, caster, receiver), or the caster is outside the shadow camera frustum. Show the CameraHelper.

Shadows only on part of the scene

The orthographic box of a directional light is too small, or far ends before the receiver.

Stripes on every lit surface

Acne: raise normalBias, then add a small negative bias.

Shadow detached from the object

Bias too large (peter panning) or shadowSide on thin geometry.

Blocky shadow edges

mapSize too small for the area covered. Shrink the camera box before raising the resolution.

Shadow disappears when the light moves

The light is a child of an object whose matrix is not updated, or the target is not in the scene.

Hitch when adding a light

Changing the number of lights recompiles materials. Create the lights at start-up.

Model black after loading

Intensity units and scale mismatch, or the model has only a MeshStandardMaterial and the scene has no lights or environment.

Performance notes

  • Every shadow-casting directional or spot light adds one extra render of the shadow casters; a point light adds six. Limit shadow-casting lights to one or two.

  • Memory per map is about \( \text{ mapSize }^2 \times 4 \) bytes for a 32-bit depth target; a 4096 map is roughly 64 MB. Shrink the map before the camera box is fitted and you pay for resolution you do not use.

  • Mark small decorative meshes castShadow = false, and distant or hidden ones receiveShadow = false; both reduce work without being visible.

  • Use autoUpdate = false for static lighting, and prefer baked lighting (a lightmap texture) for scenery that never moves.

  • The fragment cost of lights grows with the number of lights, shadowed or not; many cheap lights are better replaced by an environment map.

  • Dispose of the shadow map when removing a light: light.dispose() releases shadow.map, as described in Performance and Disposal.

Recent changes

Release Change

r147

decay of point and spot lights defaults to 2 (physically correct falloff).

r152

ColorManagement enabled and sRGB output by default; see Textures and Color Management.

r155

The legacy lighting mode is removed: light intensities are in physical units.

r163

WebGLRenderer no longer supports WebGL 1.

r182

PCFSoftShadowMap is deprecated with WebGLRenderer; PCFShadowMap is soft.

r183

WebGPURenderer shadows are improved; bias values added to hide acne may need reducing.

r186

PCFSoftShadowMap is removed with WebGPURenderer.

Where the books are outdated

The books are Learning Three.js, 2nd edition (LTJ, three.js r69) and the Three.js Cookbook (TCB, r69); WebGL: Up and Running (PAR, 2012) predates both. The concepts they teach (light types, shadow maps, bias) are still right; the code and the numbers are not.

Book code or statement Today

renderer.shadowMapEnabled = true (LTJ ch. 3-4, TCB ch. 4-5)

renderer.shadowMap.enabled = true (since r72).

light.shadowMapWidth and shadowMapHeight, shadowCameraNear, shadowCameraFar, shadowDarkness

light.shadow.mapSize, light.shadow.camera.near and far (since r74). shadowDarkness no longer exists: use the intensity of the light and ambient fill.

light.shadowCameraVisible = true

new CameraHelper( light.shadow.camera ).

light.onlyShadow = true

Removed; a ShadowMaterial on a plane renders only the shadow.

AreaLight, LensFlare (LTJ ch. 3)

RectAreaLight (with RectAreaLightUniformsLib) and the Lensflare addon (r90).

Intensities around 1 for every light, decay of 1

Candela, lux and nits with decay = 2; scale and numbers must be chosen again (r147 and r155).

renderer.gammaInput and gammaOutput

ColorManagement and outputColorSpace = SRGBColorSpace, defaults since r152.

Global <script> tags and examples/js helpers

ES modules from three/addons/ (the examples/js folder was removed in r148).

Only BasicShadowMap and PCFSoftShadowMap (r69)

PCFShadowMap (default, soft), BasicShadowMap and VSMShadowMap; PCFSoftShadowMap is deprecated.

See also

Lighting in Shaders writes the Lambert and Blinn-Phong model by hand, and the raw WebGL shadow pass through a framebuffer is in Framebuffers and Render to Texture. How much shadows and lights cost per frame is analysed in Performance and Debugging.