API Reference

Class List

pc.LightComponent

Extends: pc.Component

The Light Component enables the Entity to light the scene. There are three types of light: directional, point and spot. Directional lights are global in that they are considered to be infinitely far away and light the entire scene. Point and spot lights are local in that they have a position and a range. A spot light is a specialization of a point light where light is emitted in a cone rather than in all directions. Lights also have the ability to cast shadows to add realism to your scenes.

// Add a pc.LightComponent to an entity
var entity = new pc.Entity();
entity.addComponent('light', {
    type: "point",
    color: new pc.Color(1, 0, 0),
    range: 10
});
// Get the pc.LightComponent on an entity
var lightComponent = entity.light;
// Update a property on a light component
entity.light.range = 20;

Summary

Properties

affectDynamicIf enabled the light will affect non-lightmapped objects
affectLightmappedIf enabled the light will affect lightmapped objects
bakeIf enabled the light will be rendered into lightmaps
bakeDirIf enabled and bake=true, the light's direction will contribute to directional lightmaps.
castShadowsIf enabled the light will cast shadows.
colorThe Color of the light.
cookieProjection texture.
cookieAngleAngle for spotlight cookie rotation.
cookieAssetAsset that has texture that will be assigned to cookie internally once asset resource is available.
cookieChannelColor channels of the projection texture to use.
cookieFalloffToggle normal spotlight falloff when projection texture is used.
cookieIntensityProjection texture intensity (default is 1).
cookieOffsetSpotlight cookie position offset.
cookieScaleSpotlight cookie scale.
falloffModeControls the rate at which a light attentuates from its position.
innerConeAngleThe angle at which the spotlight cone starts to fade off.
intensityThe brightness of the light.
isStaticMark light as non-movable (optimization)
maskDefines a mask to determine which pc.MeshInstances are lit by this light.
normalOffsetBiasNormal offset depth bias.
outerConeAngleThe angle at which the spotlight cone has faded to nothing.
rangeThe range of the light.
shadowBiasThe depth bias for tuning the appearance of the shadow mapping generated by this light.
shadowDistanceThe distance from the viewpoint beyond which shadows are no longer rendered.
shadowResolutionThe size of the texture used for the shadow map.
shadowTypeType of shadows being rendered by this light.
shadowUpdateModeTells the renderer how often shadows must be updated for this light.
typeThe type of light.
vsmBlurModeBlurring mode for variance shadow maps:
  • pc.BLUR_BOX: Box filter.
vsmBlurSizeNumber of samples used for blurring a variance shadow map.

Inherited

Properties

enabledEnables or disables the component.

Details

Constructor

LightComponent(system, entity)

Creates a new Light Component.

// Add a pc.LightComponent to an entity
var entity = new pc.Entity();
entity.addComponent('light', {
    type: "point",
    color: new pc.Color(1, 0, 0),
    range: 10
});
// Get the pc.LightComponent on an entity
var lightComponent = entity.light;
// Update a property on a light component
entity.light.range = 20;

Parameters

systempc.LightComponentSystemThe ComponentSystem that created this Component.
entitypc.EntityThe Entity that this Component is attached to.

Properties

BooleanaffectDynamic

If enabled the light will affect non-lightmapped objects

BooleanaffectLightmapped

If enabled the light will affect lightmapped objects

Booleanbake

If enabled the light will be rendered into lightmaps

BooleanbakeDir

If enabled and bake=true, the light's direction will contribute to directional lightmaps. 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.

BooleancastShadows

If enabled the light will cast shadows. Defaults to false.

pc.Colorcolor

The Color of the light. The alpha component of the color is ignored. Defaults to white (1, 1, 1).

NumbercookieAngle

Angle for spotlight cookie rotation.

NumbercookieAsset

Asset that has texture that will be assigned to cookie internally once asset resource is available.

StringcookieChannel

Color channels of the projection texture to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination.

BooleancookieFalloff

Toggle normal spotlight falloff when projection texture is used. When set to false, spotlight will work like a pure texture projector (only fading with distance). Default is false.

NumbercookieIntensity

Projection texture intensity (default is 1).

pc.Vec2cookieOffset

Spotlight cookie position offset.

pc.Vec2cookieScale

Spotlight cookie scale.

NumberfalloffMode

Controls the rate at which a light attentuates from its position. Can be:

  • pc.LIGHTFALLOFF_LINEAR: Linear.
  • pc.LIGHTFALLOFF_INVERSESQUARED: Inverse squared.
Affects point and spot lights only. Defaults to pc.LIGHTFALLOFF_LINEAR.

NumberinnerConeAngle

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

Numberintensity

The brightness of the light. Defaults to 1.

BooleanisStatic

Mark light as non-movable (optimization)

Numbermask

Defines a mask to determine which pc.MeshInstances are lit by this light. Defaults to 1.

NumbernormalOffsetBias

Normal offset depth bias. Defaults to 0.

NumberouterConeAngle

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

Numberrange

The range of the light. Affects point and spot lights only. Defaults to 10.

NumbershadowBias

The depth bias for tuning the appearance of the shadow mapping generated by this light. Defaults to 0.05.

NumbershadowDistance

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

NumbershadowResolution

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

NumbershadowType

Type of shadows being rendered by this light. Options:

  • pc.SHADOW_DEPTH: Render packed depth, can be used for hard or PCF sampling.
  • pc.SHADOW_VSM8: Render packed variance shadow map. All shadow receivers must also cast shadows for this mode to work correctly.
  • pc.SHADOW_VSM16: Render 16-bit exponential variance shadow map. Requires OES_texture_half_float extension. Falls back to pc.SHADOW_VSM8, if not supported.
  • pc.SHADOW_VSM32: Render 32-bit exponential variance shadow map. Requires OES_texture_float extension. Falls back to pc.SHADOW_VSM16, if not supported.

NumbershadowUpdateMode

Tells the renderer how often shadows must be updated for this light. Options:

  • pc.SHADOWUPDATE_NONE: Don't render shadows.
  • pc.SHADOWUPDATE_THISFRAME: Render shadows only once (then automatically switches to pc.SHADOWUPDATE_NONE).
  • pc.SHADOWUPDATE_REALTIME: Render shadows every frame (default).

Stringtype

The type of light. Can be:

  • "directional": A light that is infinitely far away and lights the entire scene from one direction.
  • "point": A light that illuminates in all directions from a point.
  • "spot": A light that illuminates in all directions from a point and is bounded by a cone.
Defaults to "directional".

NumbervsmBlurMode

Blurring mode for variance shadow maps:

  • pc.BLUR_BOX: Box filter.
  • pc.BLUR_GAUSSIAN: Gaussian filter. May look smoother than box, but requires more samples.

NumbervsmBlurSize

Number of samples used for blurring a variance shadow map. Only uneven numbers work, even are incremented. Minimum value is 1, maximum is 25.

Inherited

Properties

Booleanenabled

Enables or disables the component.