Search Unity

Realtime lights are killing my game's performance. Realistic alternatives?

Discussion in 'Global Illumination' started by dgoyette, Jan 8, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I'm having to face a tough reality: My current approach to lighting is killing performance, and making my game nearly unplayable on lower end hardware. So I'm revisiting my lighting solution, and I'm looking for suggestions on approaches I might take.

    My current approach is probably almost as bad as it gets for performance: I'm using HDRP, Realtime GI, all lights are Realtime (not mixed), and all lights are shadow casters. The aesthetic of my game is realistic sci-fi, so I wanted the lighting to be accurate. Here's an example of a fairly simple room in my game, which has two lights (spotlights) on the ceiling, illuminating the room:

    upload_2020-1-7_19-0-23.png
    Most rooms get more complex than this, and it gets more difficult in rooms with hallways and passages, as I need more light to keep things visible. The worse rooms end up with 10-12 of these lights in them. On a good GPU it's not an issue, but on lower end hardware this lighting is taking the game from 45-60 FPS down to 12-15 FPS. Something has to change. I realize HDRP is not intended for 10-year-old hardware, but right now I'm just doing the lighting badly, and I know the performance can be better. Here are some ideas I have, but I'd love to know what other people are doing.


    A single, directional shadow casters

    A common approach I've seen is to bake all lighting except for a single directional light. The directional light only casts shadows on dynamic objects, and is generally oriented straight down. This isn't very realistic, but as long as there aren't a lot of other shadow casters in the scene, the lack of realistic lighting isn't so noticeable. I'm not actually sure how to get this in Unity. In a scene with Baked lighting, if I add a directional light and set it to Realtime, it still illuminates static geometry. So maybe there's a trick to just getting shadows without illuminated anything else.


    Enabled/Disable lights based on proximity

    Here I'd go with a baked light approach, but then choose one (or maybe two) shadow casting lights to be active at any given time. Other lights would have their realtime shadows disabled unless they're closest to the camera.


    I'm not sure what else to try. It's not just the shadows, it's the presence of realtime lights in the scene. Each one adds a pretty serious performance hit. But many of my scenes have a lot of moving objects, and I worry that a big element of realism will be lost if I remove this. I've considered approaches where I can support multiple lighting approaches depending on graphics settings. But I'm not sure if I can dynamically switch like that. For example, maybe on "High" settings, I would just use Realtime GI, and on low settings I've use Baked lightmaps and a single shadow caster. That would mean having both kinds of light maps and light data, and having to bake both. But maybe that's the best approach?

    Any guidance would be welcome.
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    What is the hardware out of curiosity?
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Using a GTX 1070, everything's fine. In my test scene, it's easily 200 FPS with a dozen realtime shadow casters. However, I can easily switch over to the built-in Intel HD 630 integrated graphics, and with the same settings, it's down to 15 FPS. Turning off the lights brings it up to 25 FPS. So, nothing great, but if I set everything else to Low settings, then then I end up with 35-40 FPS with the lights on, and around 60 FPS with the lights off. So, on bad hardware, the lighting seems to be about half of the performance cost. This is with a decent CPU in both cases (i7-7820HK).

    I'm not expecting miracles with bad hardware, just not such a massive drop.
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There's a lot of optimisation potential in HDRP. What have you tried settings wise?
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Mostly I've turned off features I know I'm not using. I'm still on 2019.1, and I'll be moving to 2019.3 once it's released/stable. I don't know whether there are any performance differences between HDRP 5.x and 7.x.

    Here's my config. I haven't much changed the things below this in the config, but I've turned off a few features here:

    upload_2020-1-7_19-53-55.png
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Profiling-wise, the biggest cost is always rendering shadows, so that's what I've been focused on trying to improve so far.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    What are your shadow options in the Volume?
     
  8. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I'm not sure which is associated with the volume. Here's the settings from the HDRP config:

    upload_2020-1-7_20-18-44.png

    Here's the settings I have on the volume associated with the camera:

    upload_2020-1-7_20-19-42.png

    And the camera itself:

    upload_2020-1-7_20-20-2.png
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You want to immediately drop shadow resolution then add a global volume to control the amount of cascades, shadow distance etc - sounds to me you have a lot to dig into - you really haven't scratched the surface here optimisation wise. Good luck and read the docs fully for it.
     
    dgoyette likes this.
  10. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Thanks for the direction. I'll start looking at that to see the performance impact.
     
  11. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I've spent more time testing things out and trying to isolate the major culprits that are really killing performance. I did look into adding Shadowing to my global volume. That one was new to me, and that has definitely helped. I'll be keeping that setting in the game, and allowing the max shadow distance to be adjusted by players in the Graphics Options.

    I realized in my testing that I didn't have a real baseline against which to compare my changes to. That is, what is the best-case scenario I can expect in my game on a given GPU? So I made a simple test scene: Just a room, two dynamic blocks, and a single realtime spotlight:

    upload_2020-1-8_12-38-20.png

    On the Intel HD 630, this scene renders at about 60-65 FPS with my current HDRP settings. If I turn off literally every HDRP option other than Opaque and Shadows, the scene runs at 85 FPS. So, my HDRP profile is reducing FPS by 20 in this case, which doesn't seem surprising or too alarming, though it is a little unfortunate just how much extra work the GPU does merely because various features are enabled, but not currently being used.

    Anyway, if instead of a realtime light I make the light Baked, then the framerate in this scene goes from about 65 FPS to 95 FPS, with all my normal HDRP settings in place. That's a pretty big jump just for a single realtime light. So my conclusion is that realtime lights, more than anything, really hurt low-end performance. My current plan is to segment my lighting approach, because Low and High end, leaving it as an option to the user. All lights will be Mixed lights, and I'll bake relatively low-quality lightmaps. When a player sets the graphics settings to low, I'll turn off all of the Mixed lights, and turn on the lightmaps. When they're playing at Higher graphics settings, I'll turn the lights back on, and turn the lightmaps off. That feels a little messy, but my reasoning is, low-end systems just can't handle the realtime lights. I'm okay with losing dynamic shadows on low settings if it means more people can play the game, as long as I don't make things look worse for people playing in better hardware. So this feels like a reasonable trade off.
     
    jmcusack and PutridEx like this.
  12. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    One thing I'm finding odd is that there doesn't seem to be much of a performance impact of switching from Spot lights to Point lights. My understanding was that point lights are the equivalent of six spotlights, and when I've profiled the game I see that each point light results in 6 Draw Shadows passes, while spot lights result in only one. So I've been avoiding point lights as much as possible out of performance concern. But maybe that was naive/misinformed.
     
  13. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Shadow casting point lights should have more impact on performence than shadow casting spotlights.

    Generally, many realtime shadows are a huge problem. At some point, you have to accept the fact that you cannot go over a certain amount of shadow casters. Shadow resulution and shadow cascades already mention. Another option you have is to disable shadows casting for not so important objects and reducing shadow casting lights per room. Perhaps also try out Light Layers. Of course activating Light Layers has some costs, too. You may also try out the light and shadow fading settings each inividual light source has. For example, if you have a closed room with one door, you could set that distance to really low at a point where the player is not noticing it so much.
     
    Last edited: Jan 18, 2020
  14. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Thanks. I've spent a fair bit of time this week pursuing performance improvements around lighting. The result is somewhere around a 50-75% improvement in framerates compared to what I was achieving on low-end hardware. The main sources of improved performance have been:
    • Allowing a low screen resolution setting, going as low as 1024 x 576. More than any other single factor, resolution has the biggest impact on performance. Previously, the lowest I was allowing was 1280 x 720, but just adding another notch down yields reasonable visuals and improved framerates.
    • Shadow Distance - This seems to really help. I'm not letting players adjust a slider to control what shadow distance they want so they can dial in the performance.
    • Turning off features using overrides on the camera. I now allow players to turn off HDRP features (like distortion, volumetrics, AO, etc). Turning those systems off on each camera has a pretty big impact on performance.
    • Separate "critical" from "cosmetic" realtime lights, and letting players turn off cosmetic lighting. Those are lights that just look nice, but aren't needed to see. This allows low-end hardware to optionally turn off a bunch of unnecessary lights while allowing high-end users to see the intended visuals.
    Before, on bad hardware, a complex scene was yielding 35-40 FPS. That same scene, with these adjustments, now runs at 55-60 FPS. That makes a big difference, and it honestly doesn't even look terrible.

    I'm currently using light layers, but it's on my list to see if I should make them an optional thing, assuming that optionally disabling light layers yields noticeable performance gains.
     
    jmcusack, FernandoMK and mbussidk like this.
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There is more you can squeeze. HDRP is a proper console engine that will do any AAA title on prev-gen hardware from 2013+ at 30fps. The goal of the engine design was to give a consistent performance for the bandwidth, so think along the lines of "how much bandwidth am I using here..?" that's generally the key to working with HDRP performance.
     
  16. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    399
  17. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I'm sure I'll take another performance dive in the not-too-distant future. One of the challenges has just been evaluating the practical impact a given feature has on performance. Going on FPS counts before and after is the best I could manage. It would be great if the "bandwidth" concept you're referring to was quantifiable, where I could see, in practical terms, how much more bandwidth a given feature requires. This difficulty isn't unique to HDRP, but it always feels like performance optimization is just a lot of "turn something off, hopefully notice if it mattered", which isn't a great way to detect minor differences in performance.

    I'm of two minds. The practical side of me knows that my target audience has reasonable hardware. Steam hardware reports show that only something like 10% of their customers don't have a dedicated GPU. So, practically everyone who would play my game probably could play my game. I'm a bit improperly influenced by the number of non-gamer friends/colleagues/acquaintances who want to try playing it, but only have integrated graphics. That really isn't my target audience, but it's a useful audience for testing purposes, because they're interested and available. None of my recent changes really make any noticeable difference on a 1070: Maybe a scene was rendering at 170 FPS and now it's rendering at 225 FPS. That doesn't really matter. But if a few simple changes mean I can expand my alpha/beta testing audience, that ends up being pretty useful to me. Luckily, I've been able to achieve that with these fairly small changes. So I'm happy about that. And it probably has lasting benefit, in that even people with mid-range hardware can turn off some cosmetic things to get a bit better performance, if that's more important to them.
     
    jamespaterson likes this.
  18. Kibate

    Kibate

    Joined:
    Jun 3, 2013
    Posts:
    2
    Hi. I know this is an old thread, and i usually don't comment on these kind of topics(i'm more of a lurker), but i just had to throw in my own experience in regards to hardware.
    OP mentioned that he looked up on Steam that only 10% use low hardware computers. Since I am one of those that only have a laptop, i have a few thoughts about that.
    You see, that number can be quite misleading when it comes to Steam. I probably don't end up in most statistics of Steam, because i have been discouraged from using Steam(and other platforms) BECAUSE there are less and less games that my laptop could run. Even with games that look like my PC should be able to handle, yet they have simply not been optimized for people like me. (and since i try to become a game developer myself, and have been into video games for 25 years, i know what i am talking about when i say "This game should be playable on a Laptop")
    Meaning, that 10% could actually be much higher if these people actually could play more games on Steam.

    Heck, i have been discouraged from using the Steam app itself because it is horribly optimized. So many modern games and apps have been horribly coded just because "If the average PC can run it, that means it's fine". I started to learn that, even if i ever get a good PC to develop my games and intend on having the average PC be my target demographic, i will still try to make the games playable on lower end hardware, as it will force me to write my code properly.

    (funnily enough, i happen to notice that OP actually finished his game this month, good for you. It looks interesting, i will try the Demo. Let's hope i can play it ;)
     
    jmcusack and CThayer like this.
  19. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Yeah you really don't comment I can see by the fact that this is your first post since 2013 :eek:
     
  20. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Far from finished, but yeah, in Early Access now, so coming along. There are a lot of settings to fine-tune performance in the game. Related to this thread, I ended up with options around whether to enable/disable shadows, what the shadow distance should be, and another setting for just disabling shadows on special "accent" lights, which are non-essential lights that can be safely turned off without ruining the game. Feel free to send me a feedback form in-game in the demo, if you end up playing it, to let me know how it performs for you. If you're really on old hardware, this is still an HDRP project, so you'll at least need a compatible GPU.
     
  21. Kibate

    Kibate

    Joined:
    Jun 3, 2013
    Posts:
    2
    I guess i haven't haha. I did a few comments on Unity Answers, but i guess i never did on Unity Forum. It's just that there never was any need to, you know? That is, until now.

    I was always confused about "Early Access". I figured it meant "You can get the game earlier than others, but it's already pretty much finished and only needs a few bug fixes". But I guess i was wrong.
    I finally played the Demo and gave you a mostly proper feedback from the ingame feedback option as you suggested. But to sum up for others: I was able to play it just fine(obviously on lower settings). Thus as far as the threads topic is concerned, he managed to make it work based on my experience with the game.
     
    dgoyette and Ruchir like this.