BabylonJS/Babylon.js · error · Error

FrameGraphCascadedShadowGeneratorTask ${this.name}: the CSM

Error message

FrameGraphCascadedShadowGeneratorTask ${this.name}: the CSM shadow generator only supports directional lights.

What it means

FrameGraphCascadedShadowGeneratorTask overrides _createShadowGeneratorInstance to require a DirectionalLight, because CascadedShadowGenerator (CSM) only works with directional lights. If this.light is any other light type (PointLight, SpotLight, etc.) it throws during shadow generator creation.

Source

Thrown at packages/dev/core/src/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.ts:273

                }

                // Convert to normalized view depth
                const zNear = camera.minZ;
                const zFar = camera.maxZ;

                min = (min - zNear) / (zFar - zNear);
                max = (max - zNear) / (zFar - zNear);
            }

            if (min !== this._shadowGenerator.minDistance || max !== this._shadowGenerator.maxDistance) {
                this._shadowGenerator.setMinMaxDistance(min, max);
            }
        });
    }

    protected override _createShadowGeneratorInstance() {
        if (!(this.light instanceof DirectionalLight)) {
            throw new Error(`FrameGraphCascadedShadowGeneratorTask ${this.name}: the CSM shadow generator only supports directional lights.`);
        }
        this._shadowGenerator = new CascadedShadowGenerator(this.mapSize, this.light, this.useFloat32TextureType, this.camera, this.useRedTextureFormat);
    }

    protected override _createShadowGenerator() {
        if (super._createShadowGenerator()) {
            const shadowGenerator = this._shadowGenerator;
            if (shadowGenerator === undefined) {
                return;
            }

            shadowGenerator.numCascades = this._numCascades;
            shadowGenerator.debug = this._debug;
            shadowGenerator.stabilizeCascades = this._stabilizeCascades;
            shadowGenerator.lambda = this._lambda;
            shadowGenerator.cascadeBlendPercentage = this._cascadeBlendPercentage;
            shadowGenerator.depthClamp = this._depthClamp;
            shadowGenerator.shadowMaxZ = this._shadowMaxZ;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Use a DirectionalLight for this task: new DirectionalLight("dir", direction, scene).
  2. If you need shadows from a spot/point light, use FrameGraphShadowGeneratorTask (non-cascaded) instead.
  3. Check light.getClassName() === "DirectionalLight" or instanceof DirectionalLight before assigning the task's light input.
  4. If the light type varies at runtime, branch: pick the CSM task for directional lights and the regular shadow generator task otherwise.

Example fix

// before
task.light = frameGraph.createLightInputValue(spotLight); // SpotLight
// throws in _createShadowGeneratorInstance

// after
const dirLight = new DirectionalLight("dir", new Vector3(-1, -2, -1), scene);
task.light = frameGraph.createLightInputValue(dirLight);
Defensive patterns

Strategy: type-guard

Validate before calling

function isDirectionalForCSM(light: Light | undefined): light is DirectionalLight {
    return light instanceof DirectionalLight;
}
if (!isDirectionalForCSM(light)) throw new Error("CSM task requires a DirectionalLight");
task.light = frameGraph.createLightInputValue(light);

Type guard

function isDirectionalLight(light: Light): light is DirectionalLight {
    return light instanceof DirectionalLight;
}

Try / catch

try {
    task.record();
} catch (e) {
    if ((e as Error).message.includes("only supports directional lights")) {
        console.error("Switching to FrameGraphShadowGeneratorTask for non-directional light.");
        // fall back to non-CSM shadow generator task
    } else throw e;
}

Prevention

When it happens

Trigger: Assigning task.light = frameGraph.createLightInputValue(someSpotOrPointLight) (anything not instanceof DirectionalLight) and then recording/building, which invokes _createShadowGeneratorInstance and hits the instanceof check.

Common situations: Reusing a generic shadow-generator task setup and swapping in a non-directional light; a scene light whose runtime type differs from expected (e.g. light created conditionally); misunderstanding that CSM differs from the regular CascadedShadowGenerator's directional-light requirement.

Related errors


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