CLASSES
TagsA - Z

Light

NodeLight

Description

class Light extends Node

Lights are used to produce the diffuse and specular color received by each pixel.

This color is then used by materials to determine the final color of every pixel.

Babylon.js allows you to create and register as many lights as you want but beware because the StandardMaterial can handle only 4 simultaneous lights (the first four enabled lights of the lights list)

A tutorial about lights can be found here : https://doc.babylonjs.com/tutorials/ligths

Constructor

new Light(name, scene)

Creates a Light object in the scene.

Documentation : http://doc.babylonjs.com/tutorials/lights

Parameters

Name Type Description
name string The name of the object
scene Scene The scene to append the light

Members

static LIGHTMAP_DEFAULT : number

If every light affecting the material is in this lightmapMode,

material.lightmapTexture adds or multiplies

(depends on material.useLightmapAsShadowmap)

after every other light calculations.

static LIGHTMAP_SPECULAR : number

material.lightmapTexture as only diffuse lighting from this light

adds pnly specular lighting from this light

adds dynamic shadows

static LIGHTMAP_SHADOWSONLY : number

material.lightmapTexture as only lighting

no light calculation from this light

only adds dynamic shadows from this light

static INTENSITYMODE_AUTOMATIC : number

Each light type uses the default quantity according to its type:

 point/spot lights use luminous intensity

 directional lights use illuminance

static INTENSITYMODE_LUMINOUSPOWER : number

lumen (lm)

static INTENSITYMODE_LUMINOUSINTENSITY : number

candela (lm/sr)

static INTENSITYMODE_ILLUMINANCE : number

lux (lm/m^2)

static INTENSITYMODE_LUMINANCE : number

nit (cd/m^2)

static LIGHTTYPEID_POINTLIGHT : number

Light type const id of the point light.

static LIGHTTYPEID_DIRECTIONALLIGHT : number

Light type const id of the directional light.

static LIGHTTYPEID_SPOTLIGHT : number

Light type const id of the spot light.

static LIGHTTYPEID_HEMISPHERICLIGHT : number

Light type const id of the hemispheric light.

diffuse : Color3

The color of the diffuse reflection of the light

specular : Color3

The color of the specular reflection of the light

intensity : number

Controls the global intensity of the light

range : number

intensityMode : number

Gets the photometric scale used to interpret the intensity.

This is only relevant with PBR Materials where the light intensity can be defined in a physical way.

Sets the photometric scale used to interpret the intensity.

This is only relevant with PBR Materials where the light intensity can be defined in a physical way.

radius : number

Gets the light radius used by PBR Materials to simulate soft area lights.

sets the light radius used by PBR Materials to simulate soft area lights.

renderPriority : number

shadowEnabled : boolean

Defines wether or not the shadows are enabled for this light. This can help turning off/on shadow without detaching

the current shadow generator.

includedOnlyMeshes : AbstractMesh[]

Holds the meshes affected by this light

excludedMeshes : AbstractMesh[]

Holds the meshes non affected by this light

excludeWithLayerMask : number

includeOnlyWithLayerMask : number

lightmapMode : number

Methods

getClassName() string

Returns the string "Light".

toString(fullDetails) string

Parameters

Name Type Description
optional fullDetails boolean

setEnabled(value) void

Set the enabled state of this node.

@see isEnabled

Parameters

Name Type Description
value boolean

getShadowGenerator() IShadowGenerator

Returns the Light associated shadow generator.

getAbsolutePosition() Vector3

Returns a Vector3, the absolute light position in the World.

transferToEffect(effect, lightIndex) void

Parameters

Name Type Description
effect Effect The given effect
lightIndex string

canAffectMesh(mesh) boolean

Boolean : True if the light will affect the passed mesh.

Parameters

Name Type Description
mesh AbstractMesh The given Mesh

getWorldMatrix() Matrix

Returns the light World matrix.

static compareLightsPriority(a, b) number

Sort function to order lights for rendering.

@return -1 to reduce's a's index relative to be, 0 for no change, 1 to increase a's index relative to b.

Parameters

Name Type Description
a Light First Light object to compare to second.
b Light Second Light object to compare first.

dispose() void

Disposes the light.

getTypeID() number

Returns the light type ID (integer).

getScaledIntensity() number

Returns the intensity scaled by the Photometric Scale according to the light type and intensity mode.

clone(name) Light

Returns a new Light object, named "name", from the current one.

Parameters

Name Type Description
name string The name of the object

serialize() any

Serializes the current light into a Serialization object.

Returns the serialized object.

static GetConstructorFromName(type, name, scene) () => Light

Creates a new typed light from the passed type (integer) : point light = 0, directional light = 1, spot light = 2, hemispheric light = 3.

This new light is named "name" and added to the passed scene.

Parameters

Name Type Description
type number
name string The name of the object
scene Scene The scene to append the light

static Parse(parsedLight, scene) Light

Parses the passed "parsedLight" and returns a new instanced Light from this parsing.

Parameters

Name Type Description
parsedLight any
scene Scene The scene to append the light