Lighting

Spotlight

Spotlight is like the light emitted from a flashlight in real life, emitting conically from a point in a specific direction.

image-20240319174652884

The spotlight has several main characteristics: color (color), intensity (intensity), effective distance (distance), scatter angle (angle), penumbra attenuation angle (penumbra). The scatter angle indicates the angle within which there is light relative to the direction of the light source, and the penumbra attenuation angle indicates that within the effective angle range, the light intensity gradually attenuates to 0 as the angle increases.

AttributeFunction
Angle (Scatter Angle)Indicates the angle within which there is light relative to the direction of the light source
IntensityControls the intensity of the spotlight, the higher the value, the brighter
ColorControls the color of the spotlight
DistanceEffective distance, light intensity attenuates with distance
Penumbra (Attenuation Angle)Indicates that within the effective angle range, the light intensity gradually attenuates to 0 as the angle increases
Culling MaskControls the objects that need to be illuminated by the light, default is Everything. Needs to be used in conjunction with the Entity's Layer

Script Usage

const lightEntity = rootEntity.createChild("light");
 
const spotLight = lightEntity.addComponent(SpotLight);
// 散射角度
spotLight.angle = Math.PI / 6;
// 半影衰减角度,为 0 时没有衰减
spotLight.penumbra = Math.PI / 12;
// 颜色
spotLight.color.set(0.3, 0.3, 1, 1);
// 位置
lightEntity.transform.setPosition(-10, 10, 10);
// 朝向
lightEntity.transform.setRotation(-45, -45, 0);

Was this page helpful?

On this page