H3DU.Lights
H3DU.Lights()
A collection of light sources. It stores the scene's ambient color as well as data on one or more light sources. When constructed, the list of light sources will be empty.
NOTE: The default shader program assumes that all colors specified in this object are in companded sRGB.
Members
- MAX_LIGHTS
Maximum number of lights supported by the default shader program. - sceneAmbient
Ambient color for the scene.
Methods
- getCount
Gets the number of lights defined in this object. - getLight
Gets information about the light source at the given index. - setAmbient
Sets the color of the scene's ambient light. - setBasic
Resets this object to a basic configuration for light sources: one light source with its default values, and the default value forsceneAmbient
. - setDirectionalLight
Sets a directional light. - setParams
Sets parameters for the light source at the given index. - setPointLight
Sets a point light.
H3DU.Lights.MAX_LIGHTS (constant)
Maximum number of lights supported by the default shader program.
Default Value: 3
H3DU.Lights#sceneAmbient
Ambient color for the scene. This is the color of the light that shines on every part of every object equally and in every direction. In the absence of other lighting effects, all objects will be given this color.
Ambient light is a simplified simulation of the real-world effect of light bouncing back and forth between many different objects in an area. One example of this phenomenon is sunlight reaching an indoor room without directly hitting it, such that the sunlight bounces off the walls and so illuminates most of the room pretty much uniformly. Ambient lights simulate this phenomenon.
NOTE: In the default shader program, this property is only used on objects that use H3DU.Material, not H3DU.PbrMaterial.
Default Value: "[0.2,0.2,0.2]"
H3DU.Lights#getCount()
Gets the number of lights defined in this object.
Return Value
Return value. (Type: number)
H3DU.Lights#getLight(index)
Gets information about the light source at the given index.
Parameters
index
(Type: number)
Zero-based index of the light to set. The first light has index 0, the second has index 1, and so on. If the light doesn't exist at that index, it will be created.
Return Value
The corresponding light source object. (Type: H3DU.LightSource)
H3DU.Lights#setAmbient(r, g, b, [a])
Sets the color of the scene's ambient light.
Parameters
r
(Type: Array.<number> | number | string)
Array of three or four color components; or the red color component (0-1); or a string specifying an HTML or CSS color.g
(Type: number)
Green color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.b
(Type: number)
Blue color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.a
(Type: number) (optional)
Alpha color component (0-1). Currently not used.
Return Value
This object. (Type: H3DU.Lights)
H3DU.Lights#setBasic()
Resets this object to a basic configuration for
light sources: one light source with its default
values, and the default value for sceneAmbient
.
Return Value
This object. (Type: H3DU.Lights)
H3DU.Lights#setDirectionalLight(index, direction, [diffuse], [specular])
Sets a directional light.
Parameters
index
(Type: number)
Zero-based index of the light to set. The first light has index 0, the second has index 1, and so on. If the light doesn't exist at that index, it will be created.direction
(Type: Array.<number>)
A 3-element array giving the X, Y, and Z world space components, respectively, of the a vector; the light will shine the brightest on surfaces that face the light in this vector's direction from the origin (0, 0, 0).diffuse
(Type: Array.<number>) (optional)
A color vector or string giving the diffuse color of the light. If null, undefined, or omitted, the diffuse color will remain unchanged. The default is (1, 1, 1, 1) for light index 0 and (0, 0, 0, 0) otherwise.specular
(Type: Array.<number>) (optional)
A color vector or string giving the color of specular highlights caused by the light. If null, undefined, or omitted, the specular highlight color will remain unchanged. The default is (1, 1, 1) for light index 0 and (0, 0, 0) otherwise.
Return Value
This object. (Type: H3DU.Lights)
H3DU.Lights#setParams(index, params)
Sets parameters for the light source at the given index.
Parameters
index
(Type: number)
Zero-based index of the light to set. The first light has index 0, the second has index 1, and so on. If the light doesn't exist at that index, it will be created.params
(Type: Object)
An object as described in H3DU.LightSource.setParams.
Return Value
This object. (Type: H3DU.Lights)
H3DU.Lights#setPointLight(index, position, [diffuse], [specular])
Sets a point light.
Parameters
index
(Type: number)
Zero-based index of the light to set. The first light has index 0, the second has index 1, and so on. If the light doesn't exist at that index, it will be created.position
(Type: Array.<number>)
A 3-element array giving the X, Y, and Z world space coordinates, respectively, of the light's position.diffuse
(Type: Array.<number>) (optional)
Diffuse color, as described in H3DU.Lights.setDirectionalLight.specular
(Type: Array.<number>) (optional)
Specular color, as described in H3DU.Lights.setDirectionalLight.
Return Value
This object. (Type: H3DU.Lights)