Search Unity

Question Spot lights with large outer angles leak light through walls

Discussion in 'High Definition Render Pipeline' started by se, Jul 23, 2021.

  1. se

    se

    Joined:
    May 20, 2013
    Posts:
    46
    I'm using Unity 2021.1.15f1.

    I noticed some light leaking trough walls and figured out that spot lights with a large outer angle seem to be the culprit. Without ray tracing enabled the shadows also look very wonky.

    The screenshots include the only active light in the scene. Is there something I can do about this other than lowering the outer angle unitl it's gone? Should this work properly since I can set these outer angles in the editor? Did I misconfigure something?

    Thanks for any help.
     

    Attached Files:

  2. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Is this real time or baked ?
     
  3. se

    se

    Joined:
    May 20, 2013
    Posts:
    46
    It's realtime.
     
  4. Zareion

    Zareion

    Joined:
    Aug 11, 2017
    Posts:
    3
    I've having the same issues honestly, all of the walls in my scene are set to cast shadows and the lighting is set to real time. I'm stuggling to find answers for this as well.
     
  5. se

    se

    Joined:
    May 20, 2013
    Posts:
    46
    Area lights seem to happily go through walls as well. I'm now limited to point lights. :confused:

     
  6. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    Hey, could you share a tiny repro project with me? (via dm)
     
    se likes this.
  7. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    Hey, thank you for sharing this scene.

    So, there are several issues to look into.

    upload_2021-8-13_12-45-39.png

    First of all, using extremely wide cone angles with shadows has always been a tricky problem to solve in real-time 3d. The amount of resolution you have is very limited: 512 in your case, which is tiny for such a large light covering a whole hemisphere. By increasing the cone angle massively, you then lose precision (= aliasing in the shadow map).

    Another problem is that in these scenarios, you need to start tuning the shadow biases. For most scenarios, the default settings are fine, but if you mix "low resolution" + "very wide cone angle" + "too high biases", you will end up with the issues you see.

    Btw, this is why some engines don't even bother fixing this and don't let cone angles higher than ~170 degrees, because it's not a trivial problem to solve. Hopefully, in HDRP you can fix this very easily. ;)

    You have 2 options (make sure you click on the "More options" cog button in the Shadow header of the inspector to see these settings or read the documentation).

    Fix #1
    - You can keep the current 179-degree cone angle for the spot if absolutely necessary
    - You can keep a shadow resolution of 512
    - Take advantage of the custom shadow spot angle, so that the shadow map can be focused more than the actual angle of the light, and therefore you can eliminate most issues.

    Of course, this works only in particular situations, but in yours, for ceiling lamps, it works as intended. And once you also use a light cookie to simulate the self-shadowing of the lamp, you can end up with very narrow shadow cone angles and get very high precision, while minimizing the resolution.

    upload_2021-8-13_12-47-23.png

    Fix #2
    - Reduce the cone angle of the spotlight to a more reasonable 175 degrees
    - Increase the resolution of the shadow map to 1024, this will radically help with the lack of precision and reduce aliasing
    - If needed, tune the normal and slope bias, i.e. reduce them in this situation, to make sure shadows aren't "sank" too deep into the geometry (this created shadow banding in the scene you sent me)
    - Optionally (not required in your scene), you may increase the Near Plane to slightly increase precision

    upload_2021-8-13_12-48-14.png


    Hopefully, you should be good to go. You can also mix and match both solutions based on the situation.
     
    Last edited: Aug 13, 2021
    seoyeon222222 likes this.
  8. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    For the Area light, just increase the shadow cone and tune the bias, it's the exact same concept as explained above for the spotlight.

    upload_2021-8-13_13-2-29.png
     
    se likes this.
  9. se

    se

    Joined:
    May 20, 2013
    Posts:
    46
    Thanks for the in-depth reply! I actually started with reducing the spot angle to 170 and than 160 but I kept noticing light leaks and wall/floor highlights from lights in other rooms so I switched to point lights. I completely missed these advanced options. I can get spot lights to behave fairly well now, but the area light seems to be a bit of whack-a-mole and never has the unlit room properly dark in my attempts. I was mostly worried that I had some general setting wrong. I guess I'll just have to tweak it case by case. Thanks again!
     
    pierred_unity likes this.