BabylonJS lights

BabylonJS is an open-source, robust JavaScript framework for creating and rendering 3D graphics and immersive experiences directly in web browsers.

Note: Learn more about BabylonJS.

Lights

The BabylonJS lights determine how objects in the scene are illuminated and their interactions with light sources. BabylonJS offers the following types of lights:

  1. Hemispheric light

  2. Directional light

  3. Point light

  4. Spot light

The HemisphericLight syntax

This light simulates ambient light by illuminating objects from all directions. They are commonly used to create a soft, even lighting effect.

Syntax

var light = new BABYLON.HemisphericLight(label, vector, scene);
  • label is the name of the light. It is a string.

  • vector is a BABYLON.Vector3 that defines the light's direction.

  • scene is the BabylonJS scene where the light will be added.

Example code

The DirectionalLight syntax

This light simulates sunlight or a strong light source coming from a specific direction. They create parallel light rays that illuminate the scene uniformly.

Syntax

It has a similar syntax to DirectionalLight:

var light = new BABYLON.DirectionalLight(label, vector, scene);
  • label is the name of the light. It is a string.

  • vector is a BABYLON.Vector3 that defines the light's direction.

  • scene is the BabylonJS scene where the light will be added.

Example code

The PointLight syntax

This light simulates a light source radiating light in all directions from a single point in space. They are used to model light bulbs or other light sources that are emit light in all directions.

Syntax

var light = new BABYLON.DirectionalLight(label, vector, scene);
  • label is the name of the light. It is a string.

  • vector is a BABYLON.Vector3 that defines the light's direction.

  • scene is the BabylonJS scene where the light will be added.

Example code

The SpotLight syntax

This light simulates a focused beam of light that illuminates a cone-shaped area. They are often used for flashlights or spotlights.

Syntax

var light = new BABYLON.SpotLight(label, vector1, vector2, H, J, scene);
  • label is the name of the light. It is a string.

  • vector1 specifies the position of the light source.

  • vector2 defines the direction of the light's axis.

  • H is the angle of the spotlight's cone (in radians).

  • J is the exponent controlling the spotlight's intensity distribution.

  • scene is the scene where the light will be added.

Example code

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved