Atlaslog
Atlaslog / three.js / API reference / DirectionalLight
three.js · API reference

DirectionalLight

Quick answer

DirectionalLight simulates a distant source such as the sun by lighting every surface from one direction. The vector from position to target defines that direction, and distance does not attenuate the light. Enable castShadow and size shadow.camera to cover the objects that must cast shadows.

Last verified 2026-11-03 · three.js 0.160.0 · Cite this page
new THREE.DirectionalLight ( color , intensity ) → DirectionalLight
Key points
Example
const sun = new THREE.DirectionalLight(0xfff1d6, 2.6);
sun.position.set(-30, 45, 20);   // 高、偏西、偏南
scene.add(sun);
sun.target.position.set(0, 0, 0);
scene.add(sun.target);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
const sc = sun.shadow.camera;
sc.left = -60;
sc.right = 60;
sc.top = 60;
sc.bottom = -60;
sc.near = 1;
sc.far = 160;
sc.updateProjectionMatrix();

sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.04;

renderer.shadowMap.enabled = true;
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). DirectionalLight. https://www.jingweizhi.com/en/three/api/directional-light.html (accessed 2026-11-03).