How to prevent lights from leaking between the walls(Planes)?

Apologies if this is a naive question. I am a beginner, trying to create a room with no roof(i.e light coming from sun, directly). I am using a directional light with ShadowGenerator to get shadows of room walls cast on the floor and other walls.
I guess, I was able to create that but there is a slight problem to it which I am unable to figure out how can be solved.

Issue: As you can see from the image below there is a slight leak of light present(between the walls). That is what I am trying to fix(remove).

I have tried the following things; some of them have reduced the issue(and the results you can see in the image above) but the issue is not yet completely gone.

  1. Tried joining the walls as a single mesh (did I call out that I am a beginner ?)
  2. Set light.shadowMinZ = 1 and light.shadowMaxZ = 2000; this has reduced the leak(earlier the leak was much bigger)
  3. Tried setting scene.shadowEnabled = true.
  4. Tried setting light.shadowFrustumSize = 18.1 which fixed the leak, but rendered the shadows in incorrect shape.

I wanted to understand how can I fix it, in case if it is not fixable, should the recommendation is to create the room/environment in tools like blender with baked lights and then expert it to babylonjs ?

could you recreate the scene in the playground ? I am wondering if increasing the depth of the walls would help ?

Thanks @sebavan for the suggestion. I tried that though it has changed the shadows a bit but not completely resolved the issue.

here is the link to the playground: https://playground.babylonjs.com/#T4MAV7#9

Is it possible to adjust the bias value of ShadowGenerator?

1 Like

Tried changing bias but then it starts showing lines and patterns on the box in the center of the screen

changing light.shadowMinZ = -4.5 fixes the issue but changes the shape of the shadow :frowning:

It’s good when the shadowMinZ value is -14.5. Maybe the king of shadows can save us @Evgeni_Popov

The main issue is the light can not see the thickness of the walls cause it is inside it


you should move it oustide the blocks and ensure some thickness at the angles so instead of a cross shape you could surround your area with thick walls.

2 Likes

ok, let me try that.

1 Like

Thanks a ton @sebavan for the help. You suggestion has fixed the issue. So when I set the value of light position x to be greater than the wall size(-22 in my case) that fixes the issue. Again, thanks a lot for your help.

1 Like

Updated container with fix for reference: https://playground.babylonjs.com/#T4MAV7#10

1 Like