Capítulo 145 de 859

Chapter 145: SpotLight

Core Idea

This light gets emitted from a single point in one direction, along a cone that increases in size the further from the light it gets.

This light can cast shadows - see the SpotLightShadow for details.

Key Concepts

  • angle : number: Maximum angle of light dispersion from its direction whose upper bound is Math.PI/2.
  • decay : number: The amount the light dims along the distance of the light. In context of physically-correct rendering the default value should not be chang…
  • distance : number: Maximum range of the light. 0 means no limit.
  • isSpotLight : boolean (readonly): This flag can be used for type testing.
  • map : Texture: A texture used to modulate the color of the light. The spot light color is mixed with the RGB value of this texture, with a ratio correspon…
  • penumbra : number: Percent of the spotlight cone that is attenuated due to penumbra. Value range is [0,1].
  • power : number: The light's power. Power is the luminous power of the light measured in lumens (lm). Changing the power will also change the light's intens…
  • shadow : SpotLightShadow: This property holds the light's shadow configuration.
  • target : Object3D: The spot light points from its position to the target's position.

Code Examples

// white spotlight shining from the side, modulated by a texture
const spotLight = new THREE.SpotLight( 0xffffff );
spotLight.position.set( 100, 1000, 100 );
spotLight.map = new THREE.TextureLoader().load( url );
spotLight.castShadow = true;
spotLight.shadow.mapSize.width = 1024;
spotLight.shadow.mapSize.height = 1024;
spotLight.shadow.camera.near = 500;
spotLight.shadow.camera.far = 4000;
spotLight.shadow.camera.fov = 30;s
  • What it demonstrates: Typical usage of SpotLight.

Reference Tables

Constructor

Signature
`new SpotLight( color : number

Properties

PropertyDescription
.angle : numberMaximum angle of light dispersion from its direction whose upper bound is Math.PI/2.
.decay : numberThe amount the light dims along the distance of the light. In context of physically-correct rendering the default value should not be changed.
.distance : numberMaximum range of the light. 0 means no limit.
.isSpotLight : boolean (readonly)This flag can be used for type testing.
.map : TextureA texture used to modulate the color of the light. The spot light color is mixed with the RGB value of this texture, with a ratio corresponding to its alpha value. The cookie-like masking effect is r…
.penumbra : numberPercent of the spotlight cone that is attenuated due to penumbra. Value range is [0,1].
.power : numberThe light's power. Power is the luminous power of the light measured in lumens (lm). Changing the power will also change the light's intensity.
.shadow : SpotLightShadowThis property holds the light's shadow configuration.
.target : Object3DThe spot light points from its position to the target's position.

Key Takeaways

  1. SpotLight extends: EventDispatcher → Object3D → Light
  2. Most relevant properties: angle, decay, distance, isSpotLight.

Connects To