Skip to content

Scene.addLight

Summary

Scene.addLight appends a light instance to the scene lighting list when not already present. Non-ambient lights beyond Scene.MAX_LIGHTS trigger a warning and may be ignored by lighting extraction paths. Use this method for ambient, directional, and point lights.

Syntax

Scene.addLight(light: Light): Scene
const result = scene.addLight(light);

Parameters

Name Type Required Description
light Light Yes Ambient, directional, or point light instance to register with the scene.

Returns

Scene - The same scene instance after light registration.

Type Details

LightType

type LightType = "ambient" | "directional" | "point";

Light

type Light = {
    readonly type: LightType;
    color: [number, number, number];
    intensity: number;
    enabled: boolean;
};

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);

const scene = wgpu.createScene();
scene.addLight(wgpu.createLight.ambient({ intensity: 0.15 }));
scene.addLight(wgpu.createLight.directional({ direction: [0.2, -1, 0.3], intensity: 1.1 }));

See Also