Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question There is any way to cache light at realtime?

Discussion in 'High Definition Render Pipeline' started by NewMagic-Studio, Jul 6, 2023.

  1. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    432
    Hi,
    I created shadows at realtime with ondemand shadows feature https://docs.unity3d.com/Packages/c...h-definition@16.0/manual/Shadows-in-HDRP.html but i wonder if there is also any way to cache light. I want to open a door, and light from corridor enter the room, i create an ondemand shadow with RequestShadowMapRendering but still i must leave the light enabled, which is still expensive. I would like to know if there is a way so that light just rendered lights and shadows once and those remain cached and in that way i could disable the light once is cached, there is any way to do this?
     
  2. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    629
    What you are asking is basically a way to dynamically bake lightmaps. This is not possible.

    You could however baked multiple lightmaps, and swap them in realtime. This is not a built-in feature from Unity and you will have to script it yourself.
     
  3. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    432
    So i would need to bake lightmaps, save them in a different folder and make another bake with different lighting. And then how can i swap them?
     
  4. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    94
    Like this


    But if you want to properly light interiors and outdoors and have this interactive, might as well use realtime GI solution from asset store.

    Also, check in profiler if your realtime light is actually expensive. It's usually not in deferred, it's the shadows that are expensive.
     
    mgeorgedeveloper likes this.
  5. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    242
    Agreed - it is unlikely that the shadow-less lights you are using is expensive in deferred.

    If you have many lights visible with shadows, it can also become a problem from a memory point of view (see the punctual lights atlas stuff).

    For performance, you can do mixed cached shadows to bake them but still have them real-time for moving objects. But you should also consider switching to point lights where possible. For example if you have a downward pointing street lamp, probably no need for it to be omni, especially with shadows enabled this will eat resources.
     
  6. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    432
    I don't want to use realtime GI, i just want to update it once and then remove light. It is expensive cause my frame drops when i use some lights without shadows. It is expensive for me cause cause frames drop from 90 in VR HDRP to 45 with vsync. I use deferred.
     
  7. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    629
    You can not "bake" everything with light and just forget about it.
    All materials (or at least, physically based ones) have a specular component, that depends on the source light direction and the point of view. Unity can bake a directionality information in lightmaps, but it will only store the "normal direction of the sum of all lights", so if you have more than one light, it will already be wrong.

    If you really want a "bake and forget" workflow, you will need to look into lightmap switching, but like I've just said, it will still be an approximation.

    With more recent version of HDRP, you have access to Adaptative Probe Volumes, which can basically be summarized as "volumetric lightmaps", and if baked dense enough, can fully replace regular lightmaps (think of a very dense lightsprobe grid).
    APV has the benefit of being able to blend multiple baked scenarios without the need for advanced scripting, which might be nice for you use.

    Lastly, the drop from 90 to 45 fps because of a single light makes me suspect that you are very close from the 90fps gap already, and maybe you should profile and see if some more optimization could be used elsewhere.
     
    Last edited: Jul 12, 2023