{"record":{"id":"629453dd5eccde87","repo":"BabylonJS/Babylon.js","slug":"lightingvolumemesh-name-light-must-be-a-direct","errorCode":null,"errorMessage":"LightingVolumeMesh ${name}: light must be a directional light","messagePattern":"LightingVolumeMesh (.+?): light must be a directional light","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Lights/lightingVolume.pure.ts","lineNumber":153,"sourceCode":"        }\r\n        if (this._cs2) {\r\n            this._cs2.fastMode = enabled;\r\n            this._cs2.triggerContextRebuild = enabled;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Creates a new LightingVolume.\r\n     * @param name The name of the lighting volume.\r\n     * @param scene The scene the lighting volume belongs to.\r\n     * @param shadowGenerator The shadow generator used to create the lighting volume. This is optional in the constructor, but must be set before calling updateMesh.\r\n     * @param tesselation The tesselation level of the lighting volume (default: 64).\r\n     */\r\n    constructor(name: string, scene: Scene, shadowGenerator?: ShadowGenerator, tesselation = 64) {\r\n        const light = shadowGenerator ? shadowGenerator.getLight() : undefined;\r\n\r\n        if (light && !(light instanceof DirectionalLight)) {\r\n            throw new Error(`LightingVolumeMesh ${name}: light must be a directional light`);\r\n        }\r\n\r\n        this._name = name;\r\n        this._shadowGenerator = shadowGenerator;\r\n        this._light = light as DirectionalLight;\r\n        this._indices = [];\r\n\r\n        this._engine = scene.getEngine();\r\n        this._scene = scene;\r\n\r\n        this._mesh = new Mesh(name, this._scene);\r\n        scene.meshes.splice(scene.meshes.indexOf(this._mesh), 1);\r\n\r\n        if (this._engine.isWebGPU) {\r\n            this._uBuffer = new UniformBuffer(this._engine);\r\n\r\n            this._uBuffer.addUniform(\"invViewProjMatrix\", 16);\r\n            this._uBuffer.addUniform(\"invViewMatrix\", 16);\r","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Lights/lightingVolume.pure.ts#L135-L171","documentation":"LightingVolumeMesh is a helper mesh built around a ShadowGenerator, and its internal volumetric lighting math only works with a directional light. In the constructor, if a ShadowGenerator is passed whose light is not an instance of DirectionalLight, the constructor throws immediately before building any geometry.","triggerScenarios":"new LightingVolumeMesh(name, scene, shadowGenerator) where shadowGenerator.getLight() returns a light that is not a DirectionalLight (e.g. a SpotLight or PointLight was assigned to the generator).","commonSituations":"Attaching a LightingVolumeMesh to an existing ShadowGenerator that was created for a spot or point light; refactoring scene lighting from spot to directional without updating the volume; copying sample code while keeping a different light type.","solutions":["Ensure the shadow generator's light is a DirectionalLight before constructing the mesh, or create a new ShadowGenerator bound to a DirectionalLight.","Pass no shadowGenerator argument if you do not need shadow coupling, then set up lighting separately.","Replace the scene's SpotLight/PointLight with a DirectionalLight if directional shadows are acceptable."],"exampleFix":"// before\nconst spot = new BABYLON.SpotLight(\"spot\", pos, dir, 1.2, 10, scene);\nconst sg = new BABYLON.ShadowGenerator(1024, spot);\nconst vol = new BABYLON.LightingVolumeMesh(\"vol\", scene, sg); // throws\n\n// after\nconst dir = new BABYLON.DirectionalLight(\"dir\", new BABYLON.Vector3(-1, -2, -1), scene);\nconst sg = new BABYLON.ShadowGenerator(1024, dir);\nconst vol = new BABYLON.LightingVolumeMesh(\"vol\", scene, sg);","handlingStrategy":"validation","validationCode":"const light = shadowGenerator?.getLight();\nif (light && !(light instanceof BABYLON.DirectionalLight)) {\n  throw new Error(\"LightingVolumeMesh requires a directional light\");\n}","typeGuard":"function isDirectionalLight(light: BABYLON.Light | undefined): light is BABYLON.DirectionalLight {\n  return !!light && (light as BABYLON.DirectionalLight).getDirection !== undefined && light instanceof BABYLON.DirectionalLight;\n}","tryCatchPattern":"try {\n  const vol = new BABYLON.LightingVolumeMesh(name, scene, sg);\n} catch (e) {\n  if ((e as Error).message.includes(\"directional light\")) {\n    console.warn(\"Falling back: shadow generator light is not directional\", e);\n  }\n}","preventionTips":["Always bind ShadowGenerator to a DirectionalLight when lighting volumes are involved.","Add an instanceof DirectionalLight assertion in scene setup code.","Keep light creation and generator creation adjacent so types are visible at the call site."],"tags":["lighting","validation","constructor"],"backgroundTag":"invalid-argument-type","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}