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.
The BabylonJS lights determine how objects in the scene are illuminated and their interactions with light sources. BabylonJS offers the following types of lights:
Hemispheric light
Directional light
Point light
Spot light
HemisphericLight
syntaxThis light simulates ambient light by illuminating objects from all directions. They are commonly used to create a soft, even lighting effect.
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.
DirectionalLight
syntaxThis light simulates sunlight or a strong light source coming from a specific direction. They create parallel light rays that illuminate the scene uniformly.
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.
PointLight
syntaxThis 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.
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.
SpotLight
syntaxThis light simulates a focused beam of light that illuminates a cone-shaped area. They are often used for flashlights or spotlights.
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.
Free Resources