Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Destructable Environment Lighting Approach

Discussion in 'High Definition Render Pipeline' started by mikeohc, Apr 4, 2023.

  1. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    I have multiple areas that require a completely dark room to open up and be engulfed/partly engulfed by light. Below is what I have so far. It's a bunch of adjusting values at runtime based on object's transform. As you see, it's the entire room bounded by the local volume.

    How would I control areas where light doesn't engulf the entire room? E.g. a corridor wall collapses.
    Like in this video at 0:44.


    I know with Unity's current lighting system it might not be possible. But is there a hackish way to achieve it?

    -No lightmap baking
    -No precompute GI
    -No SSGI/RTGI

    dynalighting.gif


    Also open to anyone who might have another way to achieve what I already set up. I'm using local volumes and adjusting values of local volume at runtime.
     
  2. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Could you explain a bit further? I don't create games, but I frequently create completely dark rooms using realtime lighting with HDRP. No magic - just turn off auto-exposure and make sure ground tint is off. But this is with HDRP, so not sure if also true for URP etc.
     
  3. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    The difficulty comes from having a dynamic space being able to adapt to walls collapsing, and light breaking through.

    Yes, completely dark rooms are straight-forward. I am facing problems when an area needs to partly open and let light in, while other areas of the same space staying dark.

    Take a dark corridor (ignoring that there needs to be indirect light around exit).
    corridor_case00.JPG

    When the roof collapses or moves, light leaks in. Faking indirect light using area light. So far so good.
    corridor_case02.JPG

    At this point, more roof collapses or gets moved. While the area gets lit by fake indirect lights, areas inbetween should now receive enough open space to light the dark areas. So we need to rely on changing the local volume.
    corridor_case03.JPG
    corridor_case04.JPG

    However, this will create a problem when the player goes in further into the corridor. Because further in, that area does not have enough openings to fill in the darkness in-between.
    corridor_case05.JPG

    I hope this makes sense in what I'm trying to achieve. Since the space is dynamic, this is just a quick example of one lighting scenario. In another scenario, it's the reverse where the player is in the open and wall collapses inwards eliminating all light from the player.

    The goal is to create lighting conditions for a space that can turn fully dark or fully lit depending on certain conditions. In a way it's like precompute RT lightmaps with SSGI, but no actual baking since no walls are static.
     
  4. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Ahhh. I would like a solution to that as well! Sometimes I think I want a "negative light" - subtract light from an area instead of adding it, so you can force an area to be dark. I used black fog in an area to achieve it.

    I know a few people have mentioned changing light settings with local volumes etc, but I have not heard "and it was great". Weird edge conditions come up (like you turn and look in a different direction, transition zones are not great, etc). So messing with light settings based on location "feels" like the wrong answer to me - something will go wrong. I prefer dark walls obscured by fog or similar instead.

    Oh, the one approach that I heard that seemed most reliable (but painful to use) is light layers. Create a number of layers and then control which layers the lights affect (and change it at runtime). If you put an object in a different light layer (with HDRP anyway), only lights in the same layer as the object will affect it. Painful because you have to manage what objects and light sources are in the different layers.

    I would love to hear if there is a better solution too!
     
  5. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    You can use shadow layers. Decouple any light source from the original light layer. Rename a light layer to "Shadow Casters" and assign it to the shadow layer of the light, then any object that resides in that layer will cast shadows only without receiving light (unless it also resides in other light layers).

    Yes, while it works in some cases, the one I showed above doesn't. Problem with altering indirect multiplier is that it'll affect all the layers it's assigned to. So a tunnel will appear bright throughout if multiplier isn't at 0.

    Light layer works to some degree, but because of the way layers work, it's hard to execute dynamic environment. There's no blending like LPPV or APV so you'll have harsh lighting difference when one part of the tunnel is on a different layer.
     
  6. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    595

    Interesting concept, I guess one of the simplest ways you could achieve this is by always underexposing the exposure by 1 stop of light along with using the indirect lighting controller to control global probes.

    This would work on a local volume level, perhaps with triggers or a local volume blend with others ( if the scene is dynamic but predictable)

    if the collapsing and uncollapsing is predictable ( or at least within a particular range) you could trigger/animate with timeline the weight blending of the volumes/indirect controller, this could also be useful if the folding unfolding is also set up this was as you could fine-tune the process in both lighting and the "animation" of it.

    in terms of when that "fades" back in or out, you might be able to get a slower eye adaptation on your exposure to control the passage issue you're having, or at least give you more time to do so.

    You could use the rendering debuggers for the indirect/direct lighting modes, to see exactly how this is balancing.
     
    mikeohc likes this.
  7. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    I found part of my answer with this video of The Finals. RTGI is what they use to achieve this. Not sure if you need to bake realtime lightmaps in order to get dark areas. At least for SSGI, that you do. And I can't use raytracing.
    indirlight02.JPG indirlight01.JPG

    Here's an idea taken from this post regarding realtime changes in baked light probe data. I tried it out but it seems to have no effect on the baked light probe. I can't get the probes to add ambient light.
    SphericalHarmonicsL2.AddAmbientLight


    Any way to adjust light probe data at runtime for HDRP? I think if the idea above works, we can adjust probe ambient based on player distance from exposed light position.

    probechange00.JPG
    When player moves away from exposed light, we return probes to default data.
    probechange01.JPG

    One problem I foresee happening is blending but maybe LPPV for every wall near where light breaks through?

    I want to get the changing light probe ambient light working to see the results. If anyone can get
    SphericalHarmonicsL2.AddAmbientLight
    to work in HDRP, please do tell, thanks.
     
  8. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    Problem with adjusting local volume is if you stand in a lit area with indirect multiplier turned on, the rest of the tunnel will become bright. This method is good for smaller rooms. Refer to my post about going further into the corridor with indirect multiplier turned on.
     
  9. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    Well here's the result. I tried LPPV, but the blending isn't great. I guess this might work in a higher detail environment with more light probes in between. This is prob the closest to getting fake indirect light while keeping other areas dark.
    probeambientRT.gif
     
  10. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    144
    Have you checked the 2 realtime GI solutions on asset store? Since you are on HDRP anyway, this must be not mobile, so why not just use exactly what was designed for this?
     
    mikeohc likes this.
  11. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    I can't believe I haven't tried that first. I already have H-trace and tested it in another project before. Well there goes all the research. H-Trace does exactly what I needed. Thanks!