Hi,
I created shadows at realtime with ondemand shadows feature Control shadow resolution and quality | High Definition RP | 16.0.6 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?
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.
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?
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.
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.
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.
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.