Search Unity

How to improve lighting performance in procedurally generated scene?

Discussion in 'Global Illumination' started by ReticentDaikaiju, Dec 20, 2018.

  1. ReticentDaikaiju

    ReticentDaikaiju

    Joined:
    Jun 6, 2015
    Posts:
    8
    I am working on a scene that includes an office building that is procedurally generated at runtime. The building contains multiple rooms, each with at least one light source, which is also created and placed at runtime. The problem is that for large buildings containing 50+ rooms with realtime light sources this starts to take a heavy toll on the frame rate. Unfortunately, as near as I can tell there is no way to use light maps since baked lighting can only be done in the editor, and the scene is generated at runtime. Are there any other options I could look at?
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Some vague tips as I have not enough info:

    1. HDRP is better at a lot of lights and shadows, but it is still a work in progress so you might not want to use it.

    2. Deferred rendering is a must. If you use forward rendering, then consider pooling and reusing lights that can't be seen. Do you see 50+ rooms all at the same time? If so then I'm surprised. And 50+ lights is not expensive in deferred so more information is needed.
     
  3. ReticentDaikaiju

    ReticentDaikaiju

    Joined:
    Jun 6, 2015
    Posts:
    8
    Thanks for the tips. 50 rooms can actually be seen at the same time when the building is viewed from the outside. Below is an image of a really simple building with 56 rooms visible, and I was actually hoping to eventually go larger. As you can see it's at about 11 FPS even with the rendering path set to deferred on the main camera, and it's not even at full resolution. I should note that even the rooms on the far side of the building appear to be contributing to the slowdown, since I don't think Unity foregoes calculating the lighting even if they aren't visible. Maybe I'm just being ignorant and there is an easy way to do this though. I did try grouping the lights into 4 subgroups (one for each side of the building) and disabling the ones on the far side. If I do this it goes up to about 25 FPS, and with all lights disabled I can get up to 60 FPS. I should also note that I'm currently running this on a Surface Pro notebook, so it doesn't have the most powerful GPU (Intel 540), but I should still think a scene like this should be doable if I'm not stupid about it.
    simple_building.png
     
    Last edited: Dec 20, 2018
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Actually the problem seems deeper - can you solve the 80ms cpu time please? This is priority. Once that's done let's look at gpu....

    It just seems like too many draw calls to be deferred... I think a scene like this could be achievable on a modern mobile phone at 60fps so this is definitely possible.

    What is performance without shadows?
     
  5. ReticentDaikaiju

    ReticentDaikaiju

    Joined:
    Jun 6, 2015
    Posts:
    8
    It seems the shadows were the problem. I disabled shadows on the room lights and the performance shot up. The light is now able to cross between rooms, which isn't the best, but I tweaked the range and intensity of the lights so it's somewhat less noticeable.

    simple_building2.png
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I think you'll be able to fake shadows using cookies quite efficiently. There are a number of possible strategies from this point.

    Have you considered something like this? lots of free example ones and they differ in capabilities:


    You can also render a cube map (reflection probe) per square area and just render that if you wanted, refreshing them. There are a lot of options.
     
  7. ReticentDaikaiju

    ReticentDaikaiju

    Joined:
    Jun 6, 2015
    Posts:
    8
    I think cookies are probably the way to go. I was planning to try procedurally generating the interiors as well, but the project is still in the very early stages, so there's plenty of room for experimentation.