Stop SpotLights passing through shadow generating meshes


Is there a way for a SpotLight to not pass through meshes that are in the render list of that light? I have a character with a flashlight, when i face a wall that generates shadows for that flashlight, the light still passes through to objects behind that wall.

Screenshot here - Imgur: The magic of the Internet

Also is there a way to limit how far the light shines?

Thanks in advance!

This is call shadow occlusion and unfortunately this is not supported (and pretty tought to do :))
You can still limit light.radius or manually change which light impacts which mesh with light.includedOnlyMeshes: Light - Babylon.js Documentation

This was actually very easy to fix by adding Mesh.receiveShadows on the walls and the box behind :slight_smile:

Also the property for the light distance I was looking for is light.range, very cool

haha sorry I misunderstood your ask :smiley: and so glad you found a solution