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

**URL:** <https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023>\
**Category:** Questions\
**Tags:** lighting\
**Created:** [February 28, 2022, 9:53pm UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023 "2022-02-28T21:53:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![anubhavgupta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anubhavgupta/32/22547_2.png) [@anubhavgupta](https://forum.babylonjs.com/u/anubhavgupta)\
**Post date:** [February 28, 2022, 9:53pm UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/1 "2022-02-28T21:53:00Z")

</div>

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).

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/3/73785dcd74be0b30b086f923940c49bda5bf8eee.png)

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 ?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 28, 2022, 9:59pm UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/2 "2022-02-28T21:59:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anubhavgupta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anubhavgupta/32/22547_2.png) [@anubhavgupta](https://forum.babylonjs.com/u/anubhavgupta)\
**Post date:** [March 1, 2022, 6:33am UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/3 "2022-03-01T06:33:35Z")

</div>

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](https://playground.babylonjs.com/#T4MAV7#9)

---

<div class="post-metadata">

**Author:** ![ZoeLeee](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zoeleee/32/20340_2.png) [@ZoeLeee](https://forum.babylonjs.com/u/ZoeLeee)\
**Post date:** [March 1, 2022, 9:12am UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/4 "2022-03-01T09:12:42Z")

</div>

Is it possible to adjust the bias value of ShadowGenerator?

---

<div class="post-metadata">

**Author:** ![anubhavgupta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anubhavgupta/32/22547_2.png) [@anubhavgupta](https://forum.babylonjs.com/u/anubhavgupta)\
**Post date:** [March 1, 2022, 9:42am UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/6 "2022-03-01T09:42:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anubhavgupta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anubhavgupta/32/22547_2.png) [@anubhavgupta](https://forum.babylonjs.com/u/anubhavgupta)\
**Post date:** [March 1, 2022, 9:43am UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/7 "2022-03-01T09:43:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![musk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/musk/32/17156_2.png) [@musk](https://forum.babylonjs.com/u/musk)\
**Post date:** [March 1, 2022, 9:45am UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/8 "2022-03-01T09:45:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 1, 2022, 8:28pm UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/9 "2022-03-01T20:28:42Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/a/4a87966c431a6941072400fb0a44e0920a68ca10.png)  
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.

---

<div class="post-metadata">

**Author:** ![anubhavgupta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anubhavgupta/32/22547_2.png) [@anubhavgupta](https://forum.babylonjs.com/u/anubhavgupta)\
**Post date:** [March 2, 2022, 2:38am UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/10 "2022-03-02T02:38:28Z")

</div>

ok, let me try that.

---

<div class="post-metadata">

**Author:** ![anubhavgupta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anubhavgupta/32/22547_2.png) [@anubhavgupta](https://forum.babylonjs.com/u/anubhavgupta)\
**Post date:** [March 2, 2022, 7:48pm UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/11 "2022-03-02T19:48:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anubhavgupta](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/anubhavgupta/32/22547_2.png) [@anubhavgupta](https://forum.babylonjs.com/u/anubhavgupta)\
**Post date:** [March 2, 2022, 7:48pm UTC](https://forum.babylonjs.com/t/how-to-prevent-lights-from-leaking-between-the-walls-planes/28023/12 "2022-03-02T19:48:45Z")

</div>

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