Skip to Content
🎉 @playcanvas/react 0.3.0! Now with React 19 support. Read more →

Light

Usage

import { Light } from '@playcanvas/react/components' const DirectionalLight = (props) => { return <Entity> <Light type="directional" {...props} /> </Entity> }

Props

The following props are based on PlayCanvas version 2.3.3. This documentation is automatically generated from the TypeScript types of the installed PlayCanvas package.

NameTypeDefault
type"directional" | "omni" | "spot"

The type of the light.

"directional"
lightLight
colorCssColor

Sets the color of the light. The alpha component of the color is ignored. Defaults to white ([1, 1, 1]). Gets the color of the light.

intensitynumber

Sets the brightness of the light. Defaults to 1. Gets the brightness of the light.

luminancenumber

Sets the physically-based luminance. Only used if scene.physicalUnits is true. Defaults to 0. Gets the physically-based luminance.

shapenumber

Sets the light source shape. Can be:

  • LIGHTSHAPE_PUNCTUAL: Infinitesimally small point.
  • LIGHTSHAPE_RECT: Rectangle shape.
  • LIGHTSHAPE_DISK: Disk shape.
  • LIGHTSHAPE_SPHERE: Sphere shape.

Defaults to pc.LIGHTSHAPE_PUNCTUAL. Gets the light source shape.

affectSpecularityboolean

Sets whether material specularity will be affected by this light. Ignored for lights other than LIGHTTYPE_DIRECTIONAL. Defaults to true. Gets whether material specularity will be affected by this light.

castShadowsboolean

Sets whether the light will cast shadows. Defaults to false. Gets whether the light will cast shadows.

shadowDistancenumber

Sets the distance from the viewpoint beyond which shadows are no longer rendered. Affects directional lights only. Defaults to 40. Gets the distance from the viewpoint beyond which shadows are no longer rendered.

shadowIntensitynumber

Sets the intensity of the shadow darkening. 0 having no effect and 1 meaning shadows are entirely black. Defaults to 1. Gets the intensity of the shadow darkening.

shadowResolutionnumber

Sets the size of the texture used for the shadow map. Valid sizes are 64, 128, 256, 512, 1024, 2048. Defaults to 1024. Gets the size of the texture used for the shadow map.

shadowBiasnumber

Set the depth bias for tuning the appearance of the shadow mapping generated by this light. Valid range is 0 to 1. Defaults to 0.05. Get the depth bias for tuning the appearance of the shadow mapping generated by this light.

numCascadesnumber

Sets the number of shadow cascades. Can be 1, 2, 3 or 4. Defaults to 1, representing no cascades. Gets the number of shadow cascades.

bakeNumSamplesnumber

Sets the number of samples used to bake this light into the lightmap. Defaults to 1. Maximum value is 255. Gets the number of samples used to bake this light into the lightmap.

bakeAreanumber

Sets the penumbra angle in degrees, allowing for a soft shadow boundary. Defaults to 0. Requires bake to be set to true and the light type is LIGHTTYPE_DIRECTIONAL. Gets the penumbra angle in degrees.

cascadeDistributionnumber

Sets the distribution of subdivision of the camera frustum for individual shadow cascades. Only used if LightComponent#numCascades is larger than 1. Can be a value in range of 0 and 1. Value of 0 represents a linear distribution, value of 1 represents a logarithmic distribution. Defaults to 0.5. Larger value increases the resolution of the shadows in the near distance. Gets the distribution of subdivision of the camera frustum for individual shadow cascades.

normalOffsetBiasnumber

Sets the normal offset depth bias. Valid range is 0 to 1. Defaults to 0. Gets the normal offset depth bias.

rangenumber

Sets the range of the light. Affects omni and spot lights only. Defaults to 10. Gets the range of the light.

innerConeAnglenumber

Sets the angle at which the spotlight cone starts to fade off. The angle is specified in degrees. Affects spot lights only. Defaults to 40. Gets the angle at which the spotlight cone starts to fade off.

outerConeAnglenumber

Sets the angle at which the spotlight cone has faded to nothing. The angle is specified in degrees. Affects spot lights only. Defaults to 45. Gets the angle at which the spotlight cone has faded to nothing.

falloffModenumber

Sets the fall off mode for the light. This controls the rate at which a light attenuates from its position. Can be:

  • LIGHTFALLOFF_LINEAR: Linear.
  • LIGHTFALLOFF_INVERSESQUARED: Inverse squared.

Affects omni and spot lights only. Defaults to LIGHTFALLOFF_LINEAR. Gets the fall off mode for the light.

shadowTypenumber

Sets the type of shadows being rendered by this light. Can be:

  • SHADOW_PCF1_32F
  • SHADOW_PCF3_32F
  • SHADOW_PCF5_32F
  • SHADOW_PCF1_16F
  • SHADOW_PCF3_16F
  • SHADOW_PCF5_16F
  • SHADOW_VSM_16F
  • SHADOW_VSM_32F
  • SHADOW_PCSS_32F Gets the type of shadows being rendered by this light.
vsmBlurSizenumber

Sets the number of samples used for blurring a variance shadow map. Only uneven numbers work, even are incremented. Minimum value is 1, maximum is 25. Defaults to 11. Gets the number of samples used for blurring a variance shadow map.

vsmBlurModenumber

Sets the blurring mode for variance shadow maps. Can be:

  • BLUR_BOX: Box filter.
  • BLUR_GAUSSIAN: Gaussian filter. May look smoother than box, but requires more samples. Gets the blurring mode for variance shadow maps.
vsmBiasnumber

Sets the VSM bias value. Gets the VSM bias value.

cookieAssetnumber

Sets the texture asset to be used as the cookie for this light. Only spot and omni lights can have cookies. Defaults to null. Gets the texture asset to be used as the cookie for this light.

cookieIntensitynumber

Sets the cookie texture intensity. Defaults to 1. Gets the cookie texture intensity.

cookieFalloffboolean

Sets whether normal spotlight falloff is active when a cookie texture is set. When set to false, a spotlight will work like a pure texture projector (only fading with distance). Default is false. Gets whether normal spotlight falloff is active when a cookie texture is set.

cookieChannelstring

Sets the color channels of the cookie texture to use. Can be “r”, “g”, “b”, “a”, “rgb”. Gets the color channels of the cookie texture to use.

cookieAnglenumber

Sets the angle for spotlight cookie rotation (in degrees). Gets the angle for spotlight cookie rotation (in degrees).

cookieScale[number, number]

Sets the spotlight cookie scale. Gets the spotlight cookie scale.

cookieOffset[number, number]

Sets the spotlight cookie position offset. Gets the spotlight cookie position offset.

shadowUpdateModenumber

Sets the shadow update model. This tells the renderer how often shadows must be updated for this light. Can be:

  • SHADOWUPDATE_NONE: Don’t render shadows.
  • SHADOWUPDATE_THISFRAME: Render shadows only once (then automatically switches to SHADOWUPDATE_NONE.
  • SHADOWUPDATE_REALTIME: Render shadows every frame (default). Gets the shadow update model.
masknumber

Sets the mask to determine which MeshInstances are lit by this light. Defaults to 1. Gets the mask to determine which MeshInstances are lit by this light.

affectDynamicboolean

Sets whether the light will affect non-lightmapped objects. Gets whether the light will affect non-lightmapped objects.

affectLightmappedboolean

Sets whether the light will affect lightmapped objects. Gets whether the light will affect lightmapped objects.

bakeboolean

Sets whether the light will be rendered into lightmaps. Gets whether the light will be rendered into lightmaps.

bakeDirboolean

Sets whether the light’s direction will contribute to directional lightmaps. The light must be enabled and bake set to true. Be aware, that directional lightmap is an approximation and can only hold single direction per pixel. Intersecting multiple lights with bakeDir=true may lead to incorrect look of specular/bump-mapping in the area of intersection. The error is not always visible though, and highly scene-dependent. Gets whether the light’s direction will contribute to directional lightmaps.

isStaticboolean

Sets whether the light ever moves. This is an optimization hint. Gets whether the light ever moves.

layersnumber[]

Sets the array of layer IDs (Layer#id ) to which this light should belong. Don’t push/pop/splice or modify this array. If you want to change it, set a new one instead. Gets the array of layer IDs (Layer#id ) to which this light should belong.

shadowUpdateOverridesnumber[]

Sets an array of SHADOWUPDATE_ settings per shadow cascade. Set to undefined if not used. Gets an array of SHADOWUPDATE_ settings per shadow cascade.

penumbraSizenumber

Sets the size of penumbra for contact hardening shadows. For area lights, acts as a multiplier with the dimensions of the area light. For punctual and directional lights it’s the area size of the light. Defaults to 1. Gets the size of penumbra for contact hardening shadows.

systemComponentSystem

The ComponentSystem used to create this Component.

entityEntity

The Entity that this Component is attached to.

enabledboolean

Sets the enabled state of the component. Gets the enabled state of the component.

Last updated on