Anvil

Lighting a Scene

Lighting a scene is easy. Just switch “lighting” to true in your scene’s options:

const myScene = new Scene({
	lighting: true,
	lightOptions: {
		ambient: 0.2 // must be non-zero
		fog: 1.2
	}
});

Here, we initialize an empty scene with no active lights.

We set the ambient lighting to 0.2, which is the default, and dimly lights each object in the scene. Fog controls how the light spreads in a scene. A fog of 1 means that the brightness of the light will decrease linearly from the origin.

To add a light into the scene, use the Light constructor.

var myLight = new Light(position, diffuse, strength, color)

Once we have configured our light, we can add it to the scene.

myScene.addLight(myLight);

The light class also has multiple features that you can use to make your experience easier.

These include pin:

light.pin(gameObject);

This pins the light’s position to any game object, and it updates every frame.

For a full list of methods, see the documentation