Search Unity

Question Why does directional light "bleed through" objects in HDRP, but point light doesn't?

Discussion in 'High Definition Render Pipeline' started by Tabcddd, Aug 6, 2022.

  1. Tabcddd

    Tabcddd

    Joined:
    Jul 3, 2015
    Posts:
    3
    Hi all,

    I'm running into an issue in HDRP where directional light is lighting up places that should be fully occluded (and therefore completely dark). The simplest way to reproduce this issue is to create a new project with the "3D HDRP" template, then fully enclose the camera inside a "box" made of 6 cube objects for the walls. I'd expect the inside of the box to look completely dark, but I can still see all of the edges and surfaces as if they were fairly well lit.

    The point light however does not bleed through objects. If I turn off the sun (directional light) and put a point light inside my box, I can see the inside walls as expected. However, as soon as the point-light moves out of my box the inside of the box becomes fully dark, also as I'd expect.

    I've just switched over to HDRP so I may be missing something obvious, why is the inside of my box still lit up by a directional light but not by a point light that's outside of the box? Isn't directional light supposed to simulate a "very far away point light" ? How would I get the inside of the box to also be pitch black with a directional light?

    Thanks,
     
  2. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    It's not directional light, it's environment light. When an object doesn't have baked lighting, and no directional lighting, it falls back to sky lighting which is everywhere (unless you bake lighting, and then use a reflection probe).

    You can set directional light to mixed, environment lighting to static, bake lighting, put a reflection probe that covers the interior area, and after baking the lighting, bake the reflection probe. It'll be dark.
     
  3. Tabcddd

    Tabcddd

    Joined:
    Jul 3, 2015
    Posts:
    3
    Thank you for the response!

    Although my example used basic cubes, the use-case I'm going for more specifically involves only dynamically generated meshes. Unfortunately, as far as I know there's no APIs to dynamically bake lighting for these yet.

    More specifically, I'm digging tunnels which go below the surface, and I'm getting the following results:

    At the surface, everything is fine, the directional light illuminates the top as expected:


    In a tunnel where I can see the surface, it's sort of looking off already, it's a bit brighter around me than it should be:


    Much deeper in a winding tunnel (ie: absolutely no illumination from the sun should be provided), I get the following result which is completely wrong:


    Instead, I'd want to get the following result (which I can get by turning off the directional light representing the sun (or dropping its intensity to 0), and keeping a point light where the camera is):


    I'm not entirely sure I understood the "When an object doesn't have baked lighting, and no directional lighting, it falls back to sky lighting which is everywhere" part you mentioned. The last screenshot corresponds to the result I'm looking for, and as far as I understand this was in a situation where I didn't have baked lighting and removed my directional lighting.

    I can "lerp" between the last two screenshots by changing the intensity of my sun directional light while deep underground, so it does seem to be that the directional light itself is bleeding into areas that should be fully occluded. I thought it could be because my occlusion was not perfect, but encasing the tunnel in a box of cube objects also doesn't give me the "pitch dark" tunnel I'd want (ie: the last screenshot) unless I remove the directional light.

    Thanks,
     
  4. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    When you disable directional lighting, it disables environmental lighting. Environmental lighting comes from your "visual enviroment" post process, which decides your sky type (physical sky, HDRI, etc). Lower sun intensties give lower sky lighting.



    You can directly manage sky lighting intensity, without effecting directional light intensity, by setting your visual enviroment to "static", and then creating a new post process volume, assigning the sky type you want, then go to lighting tab > visual enviroment > And drag your new post process volume to the "sky" type (or something like that).

    That way changing the new post process volume sky will only effect it's intensity, without changing the sky visuals.
    If you set the "visual environment" to dynamic, and add a post process for the type of sky you're using (HDRI, physical sky) and from there you can control it's exposure/brightness.
    But it will also change sky visuals which often is not desired. By setting it to static as mentioned above, and doing the whole post process volume/environment tab thing, you can control the brightness without effecting visuals.


    Also, there's a "indirect lighting controller" post process override, there's some settings there that can effect sky lighting.


    Doing things procedurally does complicate things a bit, one idea is to use SSR and see if it helps with the reflective/silver sky lighting.

    If it doesn't work, one idea is to use a reflection probe that tracks the main camera, and set the probe to Realtime (you have to use "time slicing" which splits the cost over a few frames, otherwise it's very expensive. Time slicing is only available in 2021, or maybe 2022, one of them.

    The picture you linked is really tough to do without baked lighting, honestly not sure if it's possible.
    But you can go a long way by lowering sky lighting to the point where it looks fairly dark, and so your caves will look quite dark and not as bright.

    - Basically any shadowed areas from your directional light, will be lit by sky light only since you have no baked global illumination, and so without sky lighting, the shadowed areas would be completely dark. (although the sky light applies everywhere/to everything, but it's more noticeable in shadowed areas since it's not as bright as the directional light)
    edit: uploading a video
     
    Last edited: Aug 6, 2022
  5. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Video explaining this visually, should help a lot:


    I didn't do the light baking/reflection probe part though. .
    reflection probe should help give color to the objects, rather then this silver/reflective type of look.
    If you baked lighting though, the reflection probe will help occlude sky lighting correctly. Maybe SSR will help in that case. But since your project is procedural, you'll probably have to rely on the things you've seen on the video.

    It's a balance between sky lighting and exposure. Box volumes would be helpful too but maybe it's not possible for your project since it's procedural.

    I show some exposure stuff in the video and how it effects lighting for interiors and In general
     
    ftejada likes this.
  6. Tabcddd

    Tabcddd

    Joined:
    Jul 3, 2015
    Posts:
    3
    Thank you very much for the very detailed response and for putting in the effort to provide a video! This makes a lot more sense now.

    Tweaking the physically based sky's exposure compensation down to -10 and the global volume's exposure "limit min" to 7 gives me the results I'm looking for underground (this is a picture with a point light at the camera's location, removing the point light makes the interior pitch black):


    However this does mean that the exposure fails completely when near the surface.
    This is a wall at surface level, which looks ok when mostly looking at lit parts:


    This is the same wall after moving the camera back about a meter, where we now have excessive glare:


    And this is the surface next to a tunnel, where we also see excessive glare:


    Using a reflection probe does help obtain much more realistic results, but the performances really drop as expected. I understand why the proper results cannot be determined without actually calculating the reflections, and also why doing so is very costly, so it seems like for now I'll need to find a workaround.

    I'll try to see if I can "cheat" to determine in real-time what the current exposure compensation and min-exposure values should be (ie: how underground the player is, how occluded they are from the sun), in a way that is less "truthful" than using a reflection probe but much faster. Either that, or I handwave it as the player having perfect darkvision, or hope that Unity provides light-baking for dynamic meshes in the future.

    Thanks again for all the help!