When using lights with parent meshes in clustered lighting, if the parent mesh’s enabled state changes, the lights may become brighter while ignoring maxRange, or in some cases, the engine may crash.
repro: Babylon.js Playground
In this repro, while the engine crash could not be reproduced, it was observed that when the mesh is enabled after 2 seconds, the light shines brighter (possibly because it moves outside the scope of the ClusteredLightContainer?).
Thank you for maintaining this great framework!
The engine crash may occur under Snapshot rendering. I have attached the crash logs.
Thanks for the repro — I found the remaining issue and opened a PR: Fix clustered child light resync after parent enabled changes by Popov72 · Pull Request #18412 · BabylonJS/Babylon.js · GitHub
The earlier fix cleaned up the child light from mesh.lightSources when it was added to the ClusteredLightContainer, but there was another path: when the parent mesh enabled state changes, Light._syncParentEnabledState() resyncs the child light against the scene meshes. For a light owned by a ClusteredLightContainer, that could re-add the raw PointLight to mesh.lightSources even though it is not in scene.lights anymore.
That made the material see both the clustered container and the raw point light, so the plane became brighter and the raw light bypassed clustered.maxRange.
The PR marks lights internally while they are owned by a clustered container and skips the regular mesh light-source resync for those child lights until they are removed from the container. I also added a regression test for changing the enabled state of a parent mesh.
Thank you for the quick fix!