Search Unity

Point light performance tips

Discussion in 'High Definition Render Pipeline' started by athert, Jan 24, 2021.

  1. athert

    athert

    Joined:
    Dec 31, 2012
    Posts:
    36
    Hello.
    I know this topic was discussed multiple times and i dont want this thread to be same as another but i was not able to found any real tips (with somehow detailed explanation).
    How are we supposed to work with realtime lights in openworld scenes?
    In my example - i have really big world (about 4k x 4k) with multiple different scenes. I have villages, small cities etc. with running daycycle. Because of that, i cannot bake any lights and i need to use realtime lights only.
    And here is my biggest issue. If im creating interior for my building, i want it to look as good as possible (in medieval style) and in my first iteration, i had 20 point lights to look it good (candle on nightstand, hallway etc.). Of course that was horrible idea because this building is visible multiple times in village so make it *8 and you have number of point lights around player. Thats not valid approach. I then tried to limit point lights and shadows, i played with fade distance etc. I managed to make it somehow playable with few point lights but it still takes me 8ms to calculate all point lights in scene. Also, because of fade distance is really small, when player is approaching this building, he can see from distance light bleeding to terrain/objects around and only when he is really close, it will fix itself with shadows.
    I was then trying to find any solution (baking shadows into prefabs, decal shadows, shadow culling, other solution for fake shadows...) but i was not able to find any. How are other people doing interior/exterior lighting with such limitations? I was thinking that maybe i can just fake lights/shadows and when player enter interior (or he will be in certain radius), i will switch to realtime lights but there was no explanation for this approach.
    I tried to make shadows onDemand and request shadows only when player is nearby but if i skip few frames on specific light, this shadow will get broken (later i found that shadow atlas will just throw his shadow away. I was not able to somehow "hold" his shadow in atlas without requesting shadow again).
    I read somewhere that in hdrp11 are new techniques that can create shadows for static objects and then hold them in atlas but im stuck on 7.5.2 (working on 2019 LTS).
    Also, there was hundreds of games with similar problem as me and they success with this problems so there must be "something" that we can use. Maybe someone of you know what to do?
     
    13E12K likes this.
  2. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    What do you mean by "decal shadows"? I always wondered if its possible to fake somewhat believable shadows with decals, but hasn't found any useful info about it.

    Also, where can I read about these shadow improvements in HDRP 11?
     
  3. athert

    athert

    Joined:
    Dec 31, 2012
    Posts:
    36
    For decal shadows, i was thinking like somehow creating shadow texture (literally catch shadows with camera) and then place it as texture to decal that will cover for example whole room. And if there will be player nearby, i will just disable this fake shadow and enable realtime shadow or something like that :D

    That shadow improvement i was talking about can be found here https://twitter.com/the_f_key/status/1349686774801567745
     
  4. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    Hey, there are several things you can use (you mentioned several) to improve performance:
    • light fade distance
    • shadow fade distance
    • light cookies
    • light layers (not helping perf necessarily, but useful for preventing leaking from missing shadows)
    • contact shadows
    • scripted activation of light depending on whatever game logic you use (time of day, streaming/area activation, player location, mission logic, etc.).
    • Potentially using lightmaps/shadow masks, but for open world this might be trickier

    Also, staying away from point light shadows and instead relying on spot lights (but supported by shadowless point lights or point lights with cookies) is a good start. For instance, you just need a Spotlight pointing at the gameplay area for dynamic shadows, and handle the light throw with a dimmer point light, especially for wall lights. Basically, don't waste shadow map pixels on areas that don't need shadows like walls/floors/ceiling), as long as light leaking can be prevented.

    Ray Traced shadows are also a good alternative that don't rely on any shadow maps at all, but given you're on hdrp 7, it might not be optimal/possible for your project and your target platform (plus you probably need a fallback to shadowmap for players without Ray Tracing accelerated hardware).
     
    hkalterkait, Ruchir and valarnur like this.
  5. athert

    athert

    Joined:
    Dec 31, 2012
    Posts:
    36
    Hello, thank for quick answer!
    I was thinking about point light + spotlight as you mentioned but then there is noticable bleeding from point light to all objects around (trough wall to other rooms etc.)
    upload_2021-1-24_19-34-28.png

    In this scenario, point light without shadow will be seen on other side of wall and also spotlight (or multiple spotlights) will not be able to create this types of shadows as from point light (obviously :D).
    But you mentioned light cookies. I was thinking that light cookies are just for decoration, are they for performance too?
    Or another question may be better, can i somehow without shadows (even through cookies) prevent bleeding through wall?
    Even with carefully shadow distance management, im not able to create good looking light/shadows that will be somehow normal looking in interior, exterior and for example 100m from building so maybe if there will be option to manage bleeding, i will be able to have as much lights as i want and then if player will enter room (or will be close to room), i will be able to switch these lights to lights with shadows.
    (I also found https://blogs.unity3d.com/jp/2015/02/06/extending-unity-5-rendering-pipeline-command-buffers/ so maybe this is way to go but it was for old unity, not for HDRP. Im not sure if this approach is still valid for this render pipeline)
     
  6. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    You can use light layers to avoid leaking onto other objects. (or scripting potentially)
     
  7. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    230
    You may also have luck trying Bakery, which has some features for baking lightmaps into prefabs. If your houses are repeated, then that could help.
     
    Bovine likes this.