Spotlights

A Spotlight is a cone-shaped beam of light emitted from a point in one direction, similar to the light produced by a flashlight or stage lighting. Compared to other lights, spotlights have an additional SpotAngle property, which is used to adjust the light range of the spotlight.

spotlight

In the editor, one can clearly see the position, color and light range of the light as well as its spot angle, as shown in the following image. With the Transform Gizmos in the upper left corner of the editor, it is possible to adjust the position and direction of the spotlight.

spotlight

See Adding Lights for how to add spotlights to a scene.

For the Spotlight component interface, please refer to SpotLight API.

Note: Starting with v3.5, Spotlight Shadows are separated from the Scene Settings panel and are no longer affected by the Global Shadows parameter.

Spotlight Properties

image

PropertyDescription
ColorSets the color of the light.
UseColorTemperatureWhether to enable the color temperature.
ColorTemperatureAdjusts the color temperature.
SizeSets the light size.
RangeSets the range of light effect.
SpotAngleAdjusts the spot angle to control the light range.
TermSets the light intensity unit type, including LUMINOUS_POWER and LUMINANCE.
LuminousPowerLuminous flux in lumens (lm).
Effective when Term is set to LUMINOUS_POWER.
LuminanceBrightness in Candela per square meter (cd/m2).
Effective when Term is set to LUMINANCE.
StaticSettingsStatic lighting settings, please refer to the Lightmapping documentation.

Spotlight Shadow Properties

image

PropertyExplanation
ShadowEnabledWhether to enable the shadow effect.
ShadowPcfSet the anti-aliasing level of the shadow edge, currently including HARD, SOFT, SOFT_2X. Please refer to the section PCF Soft Shadow below for details.
ShadowBiasSet the shadow offset value to prevent z-fitting.
ShadowNormalBiasSet the normal offset value.

PCF Soft Shadow

Percentage Closer Filtering (PCF) is a simple, common technique used to achieve shadow edge desampling, by smoothing shadow edges to eliminate jaggedness in shadow mapping. The principle is to sample around the current pixel (also called a fragment), then calculate the ratio of the sample closer to the lights compared to the fragment, use this ratio to scale the scattered light and specular light, and then color the fragment to blur the shadow edges.

Cocos Creator currently supports hard sampler (HARD mode), 4x sampler (SOFT mode), 9x sampler (SOFT_2X mode). The larger the magnification, the larger the sampling area and the more softer the shadow edges.