BabylonJS/Babylon.js · error · Error

FrameGraphLightingVolumeTask ${this.name}: light must be a d

Error message

FrameGraphLightingVolumeTask ${this.name}: light must be a directional light

What it means

After requiring a shadow generator, FrameGraphLightingVolumeTask validates that shadowGenerator.light is an instance of DirectionalLight. Lighting volumes are only implemented for directional lights, so any other light type (point, spot, etc.) makes the task throw during record().

Source

Thrown at packages/dev/core/src/FrameGraph/Tasks/Misc/lightingVolumeTask.ts:73

        if (isReady) {
            this.lightingVolume._setComputeShaderFastMode(true);
        }
        return isReady;
    }

    public override getClassName(): string {
        return "FrameGraphLightingVolumeTask";
    }

    public record() {
        if (this.shadowGenerator === undefined) {
            throw new Error(`FrameGraphLightingVolumeTask ${this.name}: shadowGenerator is required`);
        }

        const light = this.shadowGenerator.light;

        if (!(light instanceof DirectionalLight)) {
            throw new Error(`FrameGraphLightingVolumeTask ${this.name}: light must be a directional light`);
        }

        this.lightingVolume.shadowGenerator = this.shadowGenerator.shadowGenerator;

        const pass = this._frameGraph.addObjectListPass(this.name);

        pass.setObjectList(this.outputMeshLightingVolume);
        pass.setExecuteFunc(() => {
            this.lightingVolume.update();
        });

        const passDisabled = this._frameGraph.addObjectListPass(this.name + "_disabled", true);

        passDisabled.setObjectList(this.outputMeshLightingVolume);
        passDisabled.setExecuteFunc(() => {});
    }

    public override dispose() {

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Use a DirectionalLight with a directional shadow generator for the lighting volume.
  2. Remove or disable the lighting volume task for non-directional lights.
  3. Check light instanceof DirectionalLight in scene setup code before wiring the task.

Example fix

// before
const light = new BABYLON.SpotLight("spot", pos, dir, 1.2, 8, scene);
// after
const light = new BABYLON.DirectionalLight("dir", dir, scene);
lvTask.shadowGenerator = shadowGenTask.output;
Defensive patterns

Strategy: validation

Validate before calling

if (!(lightingVolumeTask.shadowGenerator?.light instanceof BABYLON.DirectionalLight)) {
  throw new Error("LightingVolumeTask only supports directional lights");
}

Type guard

function isDirectionalLight(light: unknown): light is BABYLON.DirectionalLight {
  return light instanceof BABYLON.DirectionalLight;
}

Try / catch

try {
  lightingVolumeTask.record();
} catch (e) {
  if (String(e).includes("directional light")) {
    console.error("Replace the scene light with a DirectionalLight or remove the lighting volume task");
  } else throw e;
}

Prevention

When it happens

Trigger: lightingVolumeTask.record() where task.shadowGenerator is set, but the underlying shadowGenerator.light is a PointLight, SpotLight, or other non-directional light.

Common situations: Attaching a lighting volume to a scene lit by spot or point light shadow generators; changing the scene's light type from directional to spot after the task was configured.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/d0dcd06403affe0a. Report an issue: GitHub.