Creates a new LightComponent instance.
The ComponentSystem that created this Component.
The Entity that this Component is attached to.
The Entity that this Component is attached to.
The ComponentSystem used to create this Component.
If enabled the light will affect non-lightmapped objects.
If enabled the light will affect lightmapped objects.
If enabled, material specularity will be affected by this light. Ignored for lights other than LIGHTTYPE_DIRECTIONAL. Defaults to true.
If enabled the light will be rendered into lightmaps.
If bake is true and the light type is LIGHTTYPE_DIRECTIONAL, this specifies the penumbra angle in degrees, allowing a soft shadow boundary. Defaults to 0.
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.
If bake is true, this specifies the number of samples used to bake this light into the lightmap. Defaults to 1. Maximum value is 255.
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.
If enabled the light will cast shadows. Defaults to false.
Projection texture. Must be 2D for spot and cubemap for omni light (ignored if incorrect type is used).
Angle for spotlight cookie rotation.
Asset that has texture that will be assigned to cookie internally once asset resource is available.
Color channels of the projection texture to use. Can be "r", "g", "b", "a", "rgb".
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.
Projection texture intensity (default is 1).
Spotlight cookie position offset.
Spotlight cookie scale.
Controls the rate at which a light attenuates from its position. Can be:
Affects omni and spot lights only. Defaults to LIGHTFALLOFF_LINEAR.
The angle at which the spotlight cone starts to fade off. The angle is specified in degrees. Affects spot lights only. Defaults to 40.
The brightness of the light. Defaults to 1.
Mark light as non-movable (optimization).
An 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.
The physically based luminance. Only used if scene.physicalUnits is true. Defaults to 0.
Defines a mask to determine which MeshInstances are lit by this light. Defaults to 1.
Normal offset depth bias. Valid range is 0 to 1. Defaults to 0.
Number of shadow cascades. Can be 1, 2, 3 or 4. Defaults to 1, representing no cascades.
The angle at which the spotlight cone has faded to nothing. The angle is specified in degrees. Affects spot lights only. Defaults to 45.
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.0.
The range of the light. Affects omni and spot lights only. Defaults to 10.
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.
The distance from the viewpoint beyond which shadows are no longer rendered. Affects directional lights only. Defaults to 40.
The intensity of the shadow darkening, 1 being shadows are entirely black. Defaults to 1.
The size of the texture used for the shadow map. Valid sizes are 64, 128, 256, 512, 1024, 2048. Defaults to 1024.
Type of shadows being rendered by this light. Options:
Tells the renderer how often shadows must be updated for this light. Can be:
Returns an array of SHADOWUPDATE_ settings per shadow cascade, or undefined if not used.
The light source shape. Can be:
Defaults to pc.LIGHTSHAPE_PUNCTUAL.
The type of light. Can be:
TODO:
Blurring mode for variance shadow maps. Can be:
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.
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message');
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
obj.on('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
const evt = obj.on('test', function (a, b) {
console.log(a + b);
});
// some time later
evt.off();
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
obj.once('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled
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.