Hi everyone,
Please have a look at this playground: https://playground.babylonjs.com/#WLDCUC#253
Dude and Elf are missing shadows. But when I move the setup function of the clustered lights down, the shadows render. Why is that?
Best wishes
Joe
Hi everyone,
Please have a look at this playground: https://playground.babylonjs.com/#WLDCUC#253
Dude and Elf are missing shadows. But when I move the setup function of the clustered lights down, the shadows render. Why is that?
Best wishes
Joe
By default, materials are only illuminated by a maximum of 4 lights. When you call addExtraLights before lightSetup, 5 lights are created in the scene.
When staticLight.includedOnlyMeshes is updated with the dude/elf meshes, as part of the operation, all meshes in the scene are looped through and their internal _lightSources are synchronized with this light. Since the background plane is not yet in staticLight.includedOnlyMeshes, the light is removed from backgroundPlane._lightSources. When backgroundPlane is later added to staticLight.includedOnlyMeshes, it becomes the 5th light in backgroundPlane._lightSources (because the light is added at the end of the array), which means it does not contribute to lighting the mesh.
The solution is either to exclude backgroundPlane from one or more of the other 4 lights, or to update material.maxSimultaneousLights to 5 for this mesh. This is what I did in this PG (line 54):
Just to clarify: in my initial post, I thought ClusteredLightContainer was responsible. This was misleading. You can replace it with a PointLight for instance and get the same behaviour https://playground.babylonjs.com/#WLDCUC#265