playcanvas-typings
Version:
TypeScript declaration files for PlayCanvas game engine
138 lines (134 loc) • 8.33 kB
TypeScript
declare namespace pc {
/**
* @component
* @name pc.LightComponent
* @class 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.
* @description Creates a new Light Component.
* @param {pc.LightComponentSystem} system The ComponentSystem that created this Component.
* @param {pc.Entity} entity The Entity that this Component is attached to.
* @example
* // 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
* });
* @example
* // Get the pc.LightComponent on an entity
* var lightComponent = entity.light;
* @example
* // Update a property on a light component
* entity.light.range = 20;
* @property {String} type The type of light. Can be:
* <ul>
* <li>"directional": A light that is infinitely far away and lights the entire scene from one direction.</li>
* <li>"point": A light that illuminates in all directions from a point.</li>
* <li>"spot": A light that illuminates in all directions from a point and is bounded by a cone.</li>
* </ul>
* Defaults to "directional".
* @property {pc.Color} color The Color of the light. The alpha component of the color is
* ignored. Defaults to white (1, 1, 1).
* @property {Number} intensity The brightness of the light. Defaults to 1.
* @property {Boolean} castShadows If enabled the light will cast shadows. Defaults to false.
* @property {Number} shadowDistance The distance from the viewpoint beyond which shadows
* are no longer rendered. Affects directional lights only. Defaults to 40.
* @property {Number} shadowResolution The size of the texture used for the shadow map.
* Valid sizes are 64, 128, 256, 512, 1024, 2048. Defaults to 1024.
* @property {Number} shadowBias The depth bias for tuning the appearance of the shadow
* mapping generated by this light. Defaults to 0.05.
* @property {Number} normalOffsetBias Normal offset depth bias. Defaults to 0.
* @property {Number} range The range of the light. Affects point and spot lights only.
* Defaults to 10.
* @property {Number} innerConeAngle The angle at which the spotlight cone starts
* to fade off. The angle is specified in degrees. Affects spot lights only. Defaults
* to 40.
* @property {Number} outerConeAngle The angle at which the spotlight cone has faded
* to nothing. The angle is specified in degrees. Affects spot lights only. Defaults
* to 45.
* @property {Number} falloffMode Controls the rate at which a light attentuates from
* its position. Can be:
* <ul>
* <li>{@link pc.LIGHTFALLOFF_LINEAR}: Linear.</li>
* <li>{@link pc.LIGHTFALLOFF_INVERSESQUARED}: Inverse squared.</li>
* </ul>
* Affects point and spot lights only. Defaults to pc.LIGHTFALLOFF_LINEAR.
* @property {Number} mask Defines a mask to determine which {@link pc.MeshInstance}s are
* lit by this light. Defaults to 1.
* @property {Boolean} affectDynamic If enabled the light will affect non-lightmapped objects
* @property {Boolean} affectLightmapped If enabled the light will affect lightmapped objects
* @property {Boolean} bake If enabled the light will be rendered into lightmaps
* @property {Boolean} bakeDir 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.
* @property {Number} shadowUpdateMode Tells the renderer how often shadows must be updated for this light. Options:
* <ul>
* <li>{@link pc.SHADOWUPDATE_NONE}: Don't render shadows.</li>
* <li>{@link pc.SHADOWUPDATE_THISFRAME}: Render shadows only once (then automatically switches to pc.SHADOWUPDATE_NONE).</li>
* <li>{@link pc.SHADOWUPDATE_REALTIME}: Render shadows every frame (default).</li>
* </ul>
* @property {Number} shadowType Type of shadows being rendered by this light. Options:
* <ul>
* <li>{@link pc.SHADOW_PCF3}: Render depth (color-packed on WebGL 1.0), can be used for PCF 3x3 sampling.</li>
* <li>{@link pc.SHADOW_VSM8}: Render packed variance shadow map. All shadow receivers must also cast shadows for this mode to work correctly.</li>
* <li>{@link 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.</li>
* <li>{@link pc.SHADOW_VSM32}: Render 32-bit exponential variance shadow map. Requires OES_texture_float extension. Falls back to pc.SHADOW_VSM16, if not supported.</li>
* <li>{@link pc.SHADOW_PCF5}: Render depth buffer only, can be used for hardware-accelerated PCF 5x5 sampling. Requires WebGL2. Falls back to pc.SHADOW_PCF3 on WebGL 1.0.</li>
* </ul>
* @property {Number} vsmBlurMode Blurring mode for variance shadow maps:
* <ul>
* <li>{@link pc.BLUR_BOX}: Box filter.</li>
* <li>{@link pc.BLUR_GAUSSIAN}: Gaussian filter. May look smoother than box, but requires more samples.</li>
* </ul>
* @property {Number} vsmBlurSize Number of samples used for blurring a variance shadow map. Only uneven numbers work, even are incremented. Minimum value is 1, maximum is 25.
* @property {Number} cookieAsset Asset that has texture that will be assigned to cookie internally once asset resource is available.
* @property {pc.Texture} cookie Projection texture. Must be 2D for spot and cubemap for point (ignored if incorrect type is used).
* @property {Number} cookieIntensity Projection texture intensity (default is 1).
* @property {Boolean} cookieFalloff 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.
* @property {String} cookieChannel Color channels of the projection texture to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination.
* @property {Number} cookieAngle Angle for spotlight cookie rotation.
* @property {pc.Vec2} cookieScale Spotlight cookie scale.
* @property {pc.Vec2} cookieOffset Spotlight cookie position offset.
* @property {Boolean} isStatic Mark light as non-movable (optimization)
* @extends pc.Component
*/
class LightComponent extends pc.Component {
constructor(system: pc.LightComponentSystem, entity: pc.Entity)
type: string;
color: pc.Color;
intensity: number;
castShadows: boolean;
shadowDistance: number;
shadowResolution: number;
shadowBias: number;
normalOffsetBias: number;
range: number;
innerConeAngle: number;
outerConeAngle: number;
falloffMode: number;
mask: number;
affectDynamic: boolean;
affectLightmapped: boolean;
bake: boolean;
bakeDir: boolean;
shadowUpdateMode: number;
shadowType: number;
vsmBlurMode: number;
vsmBlurSize: number;
cookieAsset: number;
cookie: pc.Texture;
cookieIntensity: number;
cookieFalloff: boolean;
cookieChannel: string;
cookieAngle: number;
cookieScale: pc.Vec2;
cookieOffset: pc.Vec2;
isStatic: boolean;
}
}