Lights

Lights and Shadows

Lights are of course necessary to see the meshes and affect brightness and colour. Although lights show meshes they only produce shadows when shadow generation is set on the mesh. The default number of lights allowed is four but this can be increased.

There are four types of lights that can be used 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.

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 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 begin to understand how meshes react to light you need to know about the normals of a mesh since they form part of the calculations in determining the color and illumination.

Coming next

Introduction To Lights
Learn the basics of lights in Babylon.js
Introduction To Lights
Shadows
Learn how to leverage shadows in Babylon.js
Shadows
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
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