Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Light passing through walls

Discussion in 'General Graphics' started by fairtree, Jun 23, 2016.

  1. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    Hi,
    I have a light source with shadows in a maze, in this scene it is the only one light source :



    But if I look on the other side of the left wall, which has the same wall in the opposite direction I have lights passing through up and down, and a little on the wall in front of the camera :



    We could think it is because my wall is too small, but I tried to resize it a lot bigger and it does not change anything, besides I made my wall a little bit bigger than its normal size to normally avoid this kind of problem :



    I tried different shaders, light settings, shadow settings and I can not find a solution.

    Any ideas?

    Thanks :)
     
  2. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    You played with the shadow bias settings on the light?
     
  3. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    Hi mbowen89,

    First thanks for your answer, yeah I played with and it was the only thing that gave a result, but even at 0 there is still this effect.
     
  4. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Maybe it's doing per-vertex lighting instead of pixel. Show the second pic with shaded wireframe.

    What kind of light is it?
     
  5. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    Here is the shaded wireframe :
    With


    and without light



    And the light :



    By the way, Thanks for your help :)
     
  6. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Try a spotlight instead of a pointlight. Maybe the shadowcasting works better on those. Does it still bleed through?
     
  7. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    Hi Martin,

    Yeah it does still bleed.
     
  8. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Are the meshes enabled as shadowcasters?
     
  9. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    Yeah, both the roofs and the walls are set like that :

    Cast Shadows : On
    Receive shadows : X
     
  10. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    The edges of your floor tile that gets lit, how close is that to the face of the wall.

    Is your wall that's supposed to be blocking it, a flat quad, or does it have some depth.
     
  11. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    I respected 1 for height and width but to normally avoid this kind of problem I made my walls size 1.001.

    So they get in the roof a little bit, but nothing noticable.

    If a put a size of 2, 2, 2 on my walls the result is exactly the same.

    My walls are simples quad mesh with a standard shader.
     
  12. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    If you move the wall closer to the light a bit, does it start blocking the light on the floor better?

    If you have Skype, I'd be more than happy to look at it with you, PM me if you want. I think I have an idea what it's doing.
     
  13. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    You are right, it starts to do better but until there is no light anymore the wall is too far, my corridor does not look good.

    I PM you with my skype, thank you so much!!
     
  14. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Odd problem -
    Please update the thread when you find the solution, so others who run into the same problem can learn.
     
    awsapps likes this.
  15. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Do your walls have colliders? I noticed that colliders prevented the light to go through objects.
     
  16. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Colliders should have nothing to do with light at all. The only thing a collider does with a light is hide the flare component.

    It was the bias. He is just using a 2D quad mesh for his wall, and the floor edge is right up to it. You can't make the shadow bias small enough to not have it leak just a bit. The real solution would be to create walls with actual depth, so it gives the shadow bias some room to work.

    For his situation and scene, what worked best we thought, was to simply set a FLOOR2 layer on the other side of the wall and disable that layer for that light. That light should not affect that hallway at all anyways, so it works perfectly. Wherever he has this situation throughout his scene, he can go back and forth between two floor layers. Like I said, the best solution would be to have some actual depth to his walls, but his scene was already completed.
     
    DrSamwise, pcg, daveyj723 and 2 others like this.
  17. fairtree

    fairtree

    Joined:
    Jun 11, 2012
    Posts:
    84
    Finally done with that, and when I come to answer it mbowen did it before me ;-)

    First I have to say that mbowen called me on friday for 1 hour on his personnal time to explain me all he said and propose me, not one, but two solutions to try to solve my problem.

    As I said to him I can not thank him enough and the community can be proud to have members like him.

    I was able to work on it today and the layer was a perfect solution, but even too much, because few lights were passing everywhere and the difference between walls with layers and without was too huge.

    So I kept his first solution, move my walls to make them block the light more than before, and I also reduced the light intensity.

    Now for the little glitches that remain I must be the only one to see them.

    I hope I will be able to be as generous as him and help people as he does :)
     
    DrSamwise, pcg, daveyj723 and 2 others like this.
  18. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Hi,

    Im wondering if someone can help me also with a similar situation as this post.

    I am also having the same issues in all the rooms in my house, if i turn on any point light in any room it leaks into another room either next to it or below or above it.

    How can i stop the light from lighting the other rooms and only remain inside the room it is meant to? The walls in the house are relatively thick and not paper thin, the point light is set to be Real-Time. Am i missing something else?

    Unfortunately, playing around with the geometry of the walls, ceilings, floors is not an option. Im new to unity so I'm hoping that its just something that I've missed that someone can just help me with?!

    Thanks
     
  19. magnetic_fallacy

    magnetic_fallacy

    Joined:
    Aug 17, 2016
    Posts:
    2
    I recently had a similar issue. Here are a few solutions that worked for me:

    1. Create a Unity primitive (cube, plane, etc) sized similarly to your wall, remove its collider and in the Mesh Renderer properties set it to "Shadows Only". Place it just behind your wall so that it blocks the light from leaking out.

    2. Set the point light's Baking property to Mixed or Baked, then bake your lighting data using the Lighting tab. (Note that this will take a long time depending on the size of your scene and the number of lights.)

    3. If either of these don't solve the problem effectively, reduce the Range property of your point light and move it further away from the wall so that nothing beyond the wall is in range. You can increase the Intensity to compensate for the reduced range, so it will look similar to before.

    Hope this helps.
     
    daveyj723, Vytek and theANMATOR2b like this.
  20. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    thank you i managed to solve it by simply changing the Bounce Intensity setting of my real time point lights to ZERO and enabled shadows.

    I have to admit though having bounce intensity to zero does not make the light look as good (kind of looks a bit fake as the light just suddenly ends at the end of the circle whereas with bounce light, the light fades off). But doesn't look like bounce light can be used with real time light otherwise you end up with light going through walls :(
     
  21. phantomfreak001

    phantomfreak001

    Joined:
    Jan 23, 2019
    Posts:
    1
    Turn on "cast shadows" and turn the "strength" all the way up.
     
    Ignacii likes this.
  22. abandon_games

    abandon_games

    Joined:
    Sep 1, 2017
    Posts:
    38
    An update for anyone wondering about this in Unity 2020.x, try playing around with the Mesh Renderer's Lighting > Cast Shadows property to get what you want:

    upload_2021-4-9_5-58-56.png