@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
658 lines (657 loc) • 20.1 kB
TypeScript
/**
* The Light Component enables the Entity to light the scene. There are three types of light:
* directional, omni and spot. Directional lights are global in that they are considered to be
* infinitely far away and light the entire scene. Omni and spot lights are local in that they have
* a position and a range. A spot light is a specialization of an omni 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.
*
* ```javascript
* // Add a pc.LightComponent to an entity
* const entity = new pc.Entity();
* entity.addComponent('light', {
* type: "omni",
* color: new pc.Color(1, 0, 0),
* range: 10
* });
*
* // Get the pc.LightComponent on an entity
* const lightComponent = entity.light;
*
* // Update a property on a light component
* entity.light.range = 20;
* ```
*
* @category Graphics
*/
export class LightComponent extends Component {
/**
* Creates a new LightComponent instance.
*
* @param {import('./system.js').LightComponentSystem} system - The ComponentSystem that
* created this Component.
* @param {import('../../entity.js').Entity} entity - The Entity that this Component is
* attached to.
*/
constructor(system: import("./system.js").LightComponentSystem, entity: import("../../entity.js").Entity);
/**
* @type {import('../../../core/event-handle.js').EventHandle|null}
* @private
*/
private _evtLayersChanged;
/**
* @type {import('../../../core/event-handle.js').EventHandle|null}
* @private
*/
private _evtLayerAdded;
/**
* @type {import('../../../core/event-handle.js').EventHandle|null}
* @private
*/
private _evtLayerRemoved;
_cookieAsset: any;
_cookieAssetId: any;
_cookieAssetAdd: boolean;
_cookieMatrix: any;
/**
* @type {import('./data.js').LightComponentData}
* @ignore
*/
get data(): import("./data.js").LightComponentData;
/**
* @type {import('../../../scene/light.js').Light}
* @ignore
*/
set light(arg: import("../../../scene/light.js").Light);
/**
* @type {import('../../../scene/light.js').Light}
* @ignore
*/
get light(): import("../../../scene/light.js").Light;
/**
* Sets the type of the light. Can be:
*
* - "directional": A light that is infinitely far away and lights the entire scene from one
* direction.
* - "omni": An omni-directional light that illuminates in all directions from the light source.
* - "spot": An omni-directional light but is bounded by a cone.
*
* Defaults to "directional".
*
* @type {string}
*/
set type(arg: string);
/**
* Gets the type of the light.
*
* @type {string}
*/
get type(): string;
/**
* Sets the color of the light. The alpha component of the color is ignored. Defaults to white
* (`[1, 1, 1]`).
*
* @type {import('../../../core/math/color.js').Color};
*/
set color(arg: import("../../../core/math/color.js").Color);
/**
* Gets the color of the light.
*
* @type {import('../../../core/math/color.js').Color};
*/
get color(): import("../../../core/math/color.js").Color;
/**
* Sets the brightness of the light. Defaults to 1.
*
* @type {number}
*/
set intensity(arg: number);
/**
* Gets the brightness of the light.
*
* @type {number}
*/
get intensity(): number;
/**
* Sets the physically-based luminance. Only used if `scene.physicalUnits` is true. Defaults to 0.
*
* @type {number}
*/
set luminance(arg: number);
/**
* Gets the physically-based luminance.
*
* @type {number}
*/
get luminance(): number;
/**
* Sets the light source shape. Can be:
*
* - {@link LIGHTSHAPE_PUNCTUAL}: Infinitesimally small point.
* - {@link LIGHTSHAPE_RECT}: Rectangle shape.
* - {@link LIGHTSHAPE_DISK}: Disk shape.
* - {@link LIGHTSHAPE_SPHERE}: Sphere shape.
*
* Defaults to pc.LIGHTSHAPE_PUNCTUAL.
*
* @type {number}
*/
set shape(arg: number);
/**
* Gets the light source shape.
*
* @type {number}
*/
get shape(): number;
/**
* Sets whether material specularity will be affected by this light. Ignored for lights other
* than {@link LIGHTTYPE_DIRECTIONAL}. Defaults to true.
*
* @type {boolean}
*/
set affectSpecularity(arg: boolean);
/**
* Gets whether material specularity will be affected by this light.
*
* @type {boolean}
*/
get affectSpecularity(): boolean;
/**
* Sets whether the light will cast shadows. Defaults to false.
*
* @type {boolean}
*/
set castShadows(arg: boolean);
/**
* Gets whether the light will cast shadows.
*
* @type {boolean}
*/
get castShadows(): boolean;
/**
* Sets the distance from the viewpoint beyond which shadows are no longer rendered. Affects
* directional lights only. Defaults to 40.
*
* @type {number}
*/
set shadowDistance(arg: number);
/**
* Gets the distance from the viewpoint beyond which shadows are no longer rendered.
*
* @type {number}
*/
get shadowDistance(): number;
/**
* Sets the intensity of the shadow darkening. 0 having no effect and 1 meaning shadows are
* entirely black. Defaults to 1.
*
* @type {number}
*/
set shadowIntensity(arg: number);
/**
* Gets the intensity of the shadow darkening.
*
* @type {number}
*/
get shadowIntensity(): number;
/**
* Sets the size of the texture used for the shadow map. Valid sizes are 64, 128, 256, 512,
* 1024, 2048. Defaults to 1024.
*
* @type {number}
*/
set shadowResolution(arg: number);
/**
* Gets the size of the texture used for the shadow map.
*
* @type {number}
*/
get shadowResolution(): number;
/**
* 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.
*
* @type {number}
*/
set shadowBias(arg: number);
/**
* Get the depth bias for tuning the appearance of the shadow mapping generated by this light.
*
* @type {number}
*/
get shadowBias(): number;
/**
* Sets the number of shadow cascades. Can be 1, 2, 3 or 4. Defaults to 1, representing no
* cascades.
*
* @type {number}
*/
set numCascades(arg: number);
/**
* Gets the number of shadow cascades.
*
* @type {number}
*/
get numCascades(): number;
/**
* Sets the number of samples used to bake this light into the lightmap. Defaults to 1. Maximum
* value is 255.
*
* @type {number}
*/
set bakeNumSamples(arg: number);
/**
* Gets the number of samples used to bake this light into the lightmap.
*
* @type {number}
*/
get bakeNumSamples(): number;
/**
* 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 {@link LIGHTTYPE_DIRECTIONAL}.
*
* @type {number}
*/
set bakeArea(arg: number);
/**
* Gets the penumbra angle in degrees.
*
* @type {number}
*/
get bakeArea(): number;
/**
* Sets the distribution of subdivision of the camera frustum for individual shadow cascades.
* Only used if {@link 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.
*
* @type {number}
*/
set cascadeDistribution(arg: number);
/**
* Gets the distribution of subdivision of the camera frustum for individual shadow cascades.
*
* @type {number}
*/
get cascadeDistribution(): number;
/**
* Sets the normal offset depth bias. Valid range is 0 to 1. Defaults to 0.
*
* @type {number}
*/
set normalOffsetBias(arg: number);
/**
* Gets the normal offset depth bias.
*
* @type {number}
*/
get normalOffsetBias(): number;
/**
* Sets the range of the light. Affects omni and spot lights only. Defaults to 10.
*
* @type {number}
*/
set range(arg: number);
/**
* Gets the range of the light.
*
* @type {number}
*/
get range(): number;
/**
* 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.
*
* @type {number}
*/
set innerConeAngle(arg: number);
/**
* Gets the angle at which the spotlight cone starts to fade off.
*
* @type {number}
*/
get innerConeAngle(): number;
/**
* 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.
*
* @type {number}
*/
set outerConeAngle(arg: number);
/**
* Gets the angle at which the spotlight cone has faded to nothing.
*
* @type {number}
*/
get outerConeAngle(): number;
/**
* Sets the fall off mode for the light. This controls the rate at which a light attenuates
* from its position. Can be:
*
* - {@link LIGHTFALLOFF_LINEAR}: Linear.
* - {@link LIGHTFALLOFF_INVERSESQUARED}: Inverse squared.
*
* Affects omni and spot lights only. Defaults to {@link LIGHTFALLOFF_LINEAR}.
*
* @type {number}
*/
set falloffMode(arg: number);
/**
* Gets the fall off mode for the light.
*
* @type {number}
*/
get falloffMode(): number;
/**
* Sets the type of shadows being rendered by this light. Can be:
*
* - {@link SHADOW_PCF3}: Render depth (color-packed on WebGL 1.0), can be used for PCF 3x3
* sampling.
* - {@link SHADOW_VSM8}: Render packed variance shadow map. All shadow receivers must also cast
* shadows for this mode to work correctly.
* - {@link SHADOW_VSM16}: Render 16-bit exponential variance shadow map. Requires
* OES_texture_half_float extension. Falls back to {@link SHADOW_VSM8}, if not supported.
* - {@link SHADOW_VSM32}: Render 32-bit exponential variance shadow map. Requires
* OES_texture_float extension. Falls back to {@link SHADOW_VSM16}, if not supported.
* - {@link SHADOW_PCF5}: Render depth buffer only, can be used for hardware-accelerated PCF 5x5
* sampling. Requires WebGL2. Falls back to {@link SHADOW_PCF3} on WebGL 1.0.
* - {@link SHADOW_PCSS}: Render depth as color, and use the software sampled PCSS method for shadows.
*
* @type {number}
*/
set shadowType(arg: number);
/**
* Gets the type of shadows being rendered by this light.
*
* @type {number}
*/
get shadowType(): number;
/**
* 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.
*
* @type {number}
*/
set vsmBlurSize(arg: number);
/**
* Gets the number of samples used for blurring a variance shadow map.
*
* @type {number}
*/
get vsmBlurSize(): number;
/**
* Sets the blurring mode for variance shadow maps. Can be:
*
* - {@link BLUR_BOX}: Box filter.
* - {@link BLUR_GAUSSIAN}: Gaussian filter. May look smoother than box, but requires more samples.
*
* @type {number}
*/
set vsmBlurMode(arg: number);
/**
* Gets the blurring mode for variance shadow maps.
*
* @type {number}
*/
get vsmBlurMode(): number;
/**
* Sets the VSM bias value.
*
* @type {number}
*/
set vsmBias(arg: number);
/**
* Gets the VSM bias value.
*
* @type {number}
*/
get vsmBias(): number;
/**
* Sets the texture asset to be used as the cookie for this light. Only spot and omni lights can
* have cookies. Defaults to null.
*
* @type {number|null}
*/
set cookieAsset(arg: number | null);
/**
* Gets the texture asset to be used as the cookie for this light.
*
* @type {number|null}
*/
get cookieAsset(): number | null;
/**
* Sets the texture to be used as the cookie for this light. Only spot and omni lights can have
* cookies. Defaults to null.
*
* @type {import('../../../platform/graphics/texture.js').Texture|null}
*/
set cookie(arg: import("../../../platform/graphics/texture.js").Texture | null);
/**
* Gets the texture to be used as the cookie for this light.
*
* @type {import('../../../platform/graphics/texture.js').Texture|null}
*/
get cookie(): import("../../../platform/graphics/texture.js").Texture | null;
/**
* Sets the cookie texture intensity. Defaults to 1.
*
* @type {number}
*/
set cookieIntensity(arg: number);
/**
* Gets the cookie texture intensity.
*
* @type {number}
*/
get cookieIntensity(): number;
/**
* 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.
*
* @type {boolean}
*/
set cookieFalloff(arg: boolean);
/**
* Gets whether normal spotlight falloff is active when a cookie texture is set.
*
* @type {boolean}
*/
get cookieFalloff(): boolean;
/**
* Sets the color channels of the cookie texture to use. Can be "r", "g", "b", "a", "rgb".
*
* @type {string}
*/
set cookieChannel(arg: string);
/**
* Gets the color channels of the cookie texture to use.
*
* @type {string}
*/
get cookieChannel(): string;
/**
* Sets the angle for spotlight cookie rotation (in degrees).
*
* @type {number}
*/
set cookieAngle(arg: number);
/**
* Gets the angle for spotlight cookie rotation (in degrees).
*
* @type {number}
*/
get cookieAngle(): number;
/**
* Sets the spotlight cookie scale.
*
* @type {import('../../../core/math/vec2.js').Vec2|null}
*/
set cookieScale(arg: import("../../../core/math/vec2.js").Vec2 | null);
/**
* Gets the spotlight cookie scale.
*
* @type {import('../../../core/math/vec2.js').Vec2|null}
*/
get cookieScale(): import("../../../core/math/vec2.js").Vec2 | null;
/**
* Sets the spotlight cookie position offset.
*
* @type {import('../../../core/math/vec2.js').Vec2|null}
*/
set cookieOffset(arg: import("../../../core/math/vec2.js").Vec2 | null);
/**
* Gets the spotlight cookie position offset.
*
* @type {import('../../../core/math/vec2.js').Vec2|null}
*/
get cookieOffset(): import("../../../core/math/vec2.js").Vec2 | null;
/**
* Sets the shadow update model. This tells the renderer how often shadows must be updated for
* this light. Can be:
*
* - {@link SHADOWUPDATE_NONE}: Don't render shadows.
* - {@link SHADOWUPDATE_THISFRAME}: Render shadows only once (then automatically switches
* to {@link SHADOWUPDATE_NONE}.
* - {@link SHADOWUPDATE_REALTIME}: Render shadows every frame (default).
*
* @type {number}
*/
set shadowUpdateMode(arg: number);
/**
* Gets the shadow update model.
*
* @type {number}
*/
get shadowUpdateMode(): number;
/**
* Sets the mask to determine which {@link MeshInstance}s are lit by this light. Defaults to 1.
*
* @type {number}
*/
set mask(arg: number);
/**
* Gets the mask to determine which {@link MeshInstance}s are lit by this light.
*
* @type {number}
*/
get mask(): number;
/**
* Sets whether the light will affect non-lightmapped objects.
*
* @type {boolean}
*/
set affectDynamic(arg: boolean);
/**
* Gets whether the light will affect non-lightmapped objects.
*
* @type {boolean}
*/
get affectDynamic(): boolean;
/**
* Sets whether the light will affect lightmapped objects.
*
* @type {boolean}
*/
set affectLightmapped(arg: boolean);
/**
* Gets whether the light will affect lightmapped objects.
*
* @type {boolean}
*/
get affectLightmapped(): boolean;
/**
* Sets whether the light will be rendered into lightmaps.
*
* @type {boolean}
*/
set bake(arg: boolean);
/**
* Gets whether the light will be rendered into lightmaps.
*
* @type {boolean}
*/
get bake(): boolean;
/**
* 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.
*
* @type {boolean}
*/
set bakeDir(arg: boolean);
/**
* Gets whether the light's direction will contribute to directional lightmaps.
*
* @type {boolean}
*/
get bakeDir(): boolean;
/**
* Sets whether the light ever moves. This is an optimization hint.
*
* @type {boolean}
*/
set isStatic(arg: boolean);
/**
* Gets whether the light ever moves.
*
* @type {boolean}
*/
get isStatic(): boolean;
/**
* Sets the array of layer IDs ({@link 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.
*
* @type {number[]}
*/
set layers(arg: number[]);
/**
* Gets the array of layer IDs ({@link Layer#id}) to which this light should belong.
*
* @type {number[]}
*/
get layers(): number[];
/**
* Sets an array of SHADOWUPDATE_ settings per shadow cascade. Set to undefined if not used.
*
* @type {number[] | null}
*/
set shadowUpdateOverrides(values: number[] | null);
/**
* Gets an array of SHADOWUPDATE_ settings per shadow cascade.
*
* @type {number[] | null}
*/
get shadowUpdateOverrides(): number[] | null;
/**
* 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.
*
* @type {number}
*/
set penumbraSize(value: number);
/**
* Gets the size of penumbra for contact hardening shadows.
*
* @type {number}
*/
get penumbraSize(): number;
/** @ignore */
_setValue(name: any, value: any, setFunc: any, skipEqualsCheck: any): void;
addLightToLayers(): void;
removeLightFromLayers(): void;
onLayersChanged(oldComp: any, newComp: any): void;
onLayerAdded(layer: any): void;
onLayerRemoved(layer: any): void;
refreshProperties(): void;
onCookieAssetSet(): void;
onCookieAssetAdd(asset: any): void;
onCookieAssetLoad(): void;
onCookieAssetRemove(): void;
onRemove(): void;
}
import { Component } from '../component.js';