{"record":{"id":"0643bdaca2daeff3","repo":"BabylonJS/Babylon.js","slug":"framegraphcascadedshadowgeneratortask-this-name","errorCode":null,"errorMessage":"FrameGraphCascadedShadowGeneratorTask ${this.name}: the CSM shadow generator only supports directional lights.","messagePattern":"FrameGraphCascadedShadowGeneratorTask (.+?): the CSM shadow generator only supports directional lights\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.ts","lineNumber":273,"sourceCode":"                }\r\n\r\n                // Convert to normalized view depth\r\n                const zNear = camera.minZ;\r\n                const zFar = camera.maxZ;\r\n\r\n                min = (min - zNear) / (zFar - zNear);\r\n                max = (max - zNear) / (zFar - zNear);\r\n            }\r\n\r\n            if (min !== this._shadowGenerator.minDistance || max !== this._shadowGenerator.maxDistance) {\r\n                this._shadowGenerator.setMinMaxDistance(min, max);\r\n            }\r\n        });\r\n    }\r\n\r\n    protected override _createShadowGeneratorInstance() {\r\n        if (!(this.light instanceof DirectionalLight)) {\r\n            throw new Error(`FrameGraphCascadedShadowGeneratorTask ${this.name}: the CSM shadow generator only supports directional lights.`);\r\n        }\r\n        this._shadowGenerator = new CascadedShadowGenerator(this.mapSize, this.light, this.useFloat32TextureType, this.camera, this.useRedTextureFormat);\r\n    }\r\n\r\n    protected override _createShadowGenerator() {\r\n        if (super._createShadowGenerator()) {\r\n            const shadowGenerator = this._shadowGenerator;\r\n            if (shadowGenerator === undefined) {\r\n                return;\r\n            }\r\n\r\n            shadowGenerator.numCascades = this._numCascades;\r\n            shadowGenerator.debug = this._debug;\r\n            shadowGenerator.stabilizeCascades = this._stabilizeCascades;\r\n            shadowGenerator.lambda = this._lambda;\r\n            shadowGenerator.cascadeBlendPercentage = this._cascadeBlendPercentage;\r\n            shadowGenerator.depthClamp = this._depthClamp;\r\n            shadowGenerator.shadowMaxZ = this._shadowMaxZ;\r","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.ts#L255-L291","documentation":"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.","triggerScenarios":"Assigning task.light = frameGraph.createLightInputValue(someSpotOrPointLight) (anything not instanceof DirectionalLight) and then recording/building, which invokes _createShadowGeneratorInstance and hits the instanceof check.","commonSituations":"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.","solutions":["Use a DirectionalLight for this task: new DirectionalLight(\"dir\", direction, scene).","If you need shadows from a spot/point light, use FrameGraphShadowGeneratorTask (non-cascaded) instead.","Check light.getClassName() === \"DirectionalLight\" or instanceof DirectionalLight before assigning the task's light input.","If the light type varies at runtime, branch: pick the CSM task for directional lights and the regular shadow generator task otherwise."],"exampleFix":"// before\ntask.light = frameGraph.createLightInputValue(spotLight); // SpotLight\n// throws in _createShadowGeneratorInstance\n\n// after\nconst dirLight = new DirectionalLight(\"dir\", new Vector3(-1, -2, -1), scene);\ntask.light = frameGraph.createLightInputValue(dirLight);","handlingStrategy":"type-guard","validationCode":"function isDirectionalForCSM(light: Light | undefined): light is DirectionalLight {\n    return light instanceof DirectionalLight;\n}\nif (!isDirectionalForCSM(light)) throw new Error(\"CSM task requires a DirectionalLight\");\ntask.light = frameGraph.createLightInputValue(light);","typeGuard":"function isDirectionalLight(light: Light): light is DirectionalLight {\n    return light instanceof DirectionalLight;\n}","tryCatchPattern":"try {\n    task.record();\n} catch (e) {\n    if ((e as Error).message.includes(\"only supports directional lights\")) {\n        console.error(\"Switching to FrameGraphShadowGeneratorTask for non-directional light.\");\n        // fall back to non-CSM shadow generator task\n    } else throw e;\n}","preventionTips":["Always create the light for CSM tasks with new DirectionalLight(...).","Check light.getClassName() before binding to a CSM task's light input.","Use FrameGraphShadowGeneratorTask for point/spot lights.","Add a unit test asserting the light type for CSM configurations."],"tags":["babylonjs","frame-graph","csm","shadows","light-type"],"backgroundTag":"unsupported-light-type","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}