API

Lights

Lights and Shadows

Lights are, of course, necessary to see meshes and affect their brightness and color. Although lights illuminate meshes, they only produce shadows when shadow generation is enabled for the mesh. The default number of allowed lights is four, but this can be increased.

There are five types of lights that can be used, each with a range of lighting properties.

  • The Point Light - think light bulb.
  • The Directional Light - think planet lit by a distant sun.
  • The Spot Light - think of a focused beam of light.
  • The Hemispheric Light - think of the ambient light.
  • The Rectangular Area Light - think LED panel.

Color properties for all lights include emissive, diffuse and specular.

Overlapping lights will interact as you would expect, with the overlap of red, green, and blue producing white light. Every light can be switched on or off, and when it is on, its intensity can be set with a value from 0 to 1.

For shadows a shadowGenerator object is needed. There is also an extension, shadows only, that allows shadows on a transparent mesh.

To understand how meshes react to light, you need to know about the normals of a mesh, since they form part of the calculations that determine color and illumination.

Coming next

Shadows
Learn how to leverage shadows in Babylon.js
Shadows
Introduction To Lights
Learn the basics of lights in Babylon.js
Introduction To Lights
Cascaded Shadow Maps
Learn how to utilize Cascaded Shadow Maps in Babylon.js
Cascaded Shadow Maps
Volumetric Light Scattering Post Process
Learn how to utilize a Babylon.js post process to simulate light scattering.
Volumetric Light Scattering Post Process
Global Illumination with Reflective Shadow Maps
Learn how to utilize Babylon.js to render scenes with global illumination
Global Illumination with Reflective Shadow Maps
Mathematics of the depth metric when generating shadow maps and rendering with shadows
Some in-depth knowledge on how Babylon.js is computing the depth metric used in shadow map generation and shadows rendering when in normal / reverse depth buffer mode and when using either the -1..1 or 0..1 NDC Z range
Mathematics of the depth metric when generating shadow maps and rendering with shadows
Clustered Lighting
Learn about Babylon's clustered lighting implementation
Clustered Lighting