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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How do people walk the line between performance and lighting fidelity?

Discussion in 'General Graphics' started by daniel-eherbert, Aug 25, 2015.

  1. daniel-eherbert

    daniel-eherbert

    Joined:
    Dec 24, 2012
    Posts:
    34
    I'm working on a scene in which I'm hoping to achieve a certain visual style.

    This should give a bit of an indication of the direction I'm heading: http://gfycat.com/QuarrelsomeWindyBalloonfish

    What I'm having trouble with is finding balance between performance and visual quality.

    In the gfycat link above only realtime point lights are used - one per fluro. The fluro tubes are emissive, but GI is off. When the lights come on the framerate will drop from 60 to ~20 or lower. Turning hard/soft shadows off helps, but it still drops notably, especially considering the only lit object is the room itself and what is in the image is the entirety of the scene so far.

    I was able to get good performance with real-time GI (point lights turned off and using the fluro tube emissive materials), but the visual quality of the lighting around the room was full of artefacts and discoloration. I can boost the GI resolution to get closer to the result I'm after, but I had to raise it far too much to be practical (this scene will be distributed in a package).

    I know pixel lights can impact performance but I wouldn't have expected a ~40 fps drop from 12 lights with a single simple mesh.

    I've played games and seen scenes with great lighting fidelity and great performance...

    Have I perhaps missed something? Or is there a better approach/setup for achieving this style of on/off lighting?
     
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    The "Good" setting back in 4.5 had allowed for no more than 2 pixel lights. So it's not surprising at all that 12 lights can drop frames so heavily :( I'm sure you've played games (AAA titles) that have had dozens of realtime pixel lights. But they can pour millions of dollars into a custom Engine and have found solutions that Unity just doesn't have. They also rely heavily on faking certain parts, and also decreasing the amount of raycasts from certain lights.* (Which I haven't seen an option for in Unity)

    So you have a few options:
    1. Go for baked lighting. (You can bake prefabs and Instantiate them to make it appear dynamic) But be prepared for hundreds upon hundreds upon hundreds of issues with the Baked route.
    2. Use blob lighting. (Google this) It's a nice way to use textures instead of raycasts to fake light!
    3. Use Vertex lighting. This is an ugly one, but it allows for much more realtime lights with a better performance. Keep in mind, you'll need more polygons for this to look better. So unless your wall is subdivided this won't do much good...
    4. Use Halos/particle systems. This is even uglier, but sometimes a good halo for a distance light can fake the glow of an actual realtime light.
    5. Cull lights with a custom "LOD" script. You can deactivate lights you don't need. Or you can fake multiple lights by increasing the brightness of a single light. So in your scene for example, just have 2 lights on each side. As the individual materials turn to the "on" material, make the light on either side brighter, to simulate the effect of more lights turning on. When the player leaves the room, your script can detect that and turn off the lights from that room so they don't take up any more GPU/CPU cycles. Unity already activates the closest pixel lights based off the limit but I've noticed it does a horrible job at this. It takes into account angle over distance--when you're close to a light and looking at a far light, it will render far as pixel and the close as vertex for some reason.
    6. Don't use realtime pixel lights. I was having the same issue, and I needed more lights for interiors, but was scared to go past the limit for "Good". So one solution is to work around it in the gameplay. Instead of having a lot of lights that are always turned on, just have a torch the player carries around to light as he moves. This is by far the worst "solution" because it's not a solution at all. Honestly, if lightmaps get improved and work back like they did in Beast, I'd be more help. But unfortunately, Enlighten has sucked us all in to the abyss.
    *There's an option for shadow resolution, but nothing to interpolate texel res that I've seen...
     
    daniel-eherbert and theANMATOR2b like this.
  3. daniel-eherbert

    daniel-eherbert

    Joined:
    Dec 24, 2012
    Posts:
    34
    Thanks for the reply!

    I'll have a look in to each of those things.

    Since my post I've also had an idea about breaking my room meshes apart based on what needs more lighting detail. Eg, the wall which the fluros are on might be broken out in to its own mesh, and lightmapping for that mesh could have a much higher resolution than the rest of the room.

    I'm intrigued by Command Buffers too, but that is probably beyond the scope of what I should be doing for this demo scene. :)
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  5. daniel-eherbert

    daniel-eherbert

    Joined:
    Dec 24, 2012
    Posts:
    34
    Thanks, hippocoder.

    Deferred is definitely enabled unfortunately.
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Are you on mobile? the gif shows a scene which I would consider impossible to run slower than 60fps even on a terrible laptop. What does the profiler say?

    What other post fx are you using? Is there any more data you can provide? Do all the lights cast shadows? point light shadows are terribly expensive still.
     
  7. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    @SomeGuy22
    Awesome post. Definitely saving this wealth of information for future use.
    Thank you.
     
    SomeGuy22 and daniel-eherbert like this.
  8. daniel-eherbert

    daniel-eherbert

    Joined:
    Dec 24, 2012
    Posts:
    34
    Not on mobile. I did have a brief look at the profiler last night, mostly to check if my post effects where the cause, and from memory most of the load was coming from calculating the lighting. Can't remember specifically however. Will check after work when I get the chance.

    I'm using an updated+unreleased build of my post effects package, and there is some overhead from using some SSAO+Depth of Field+Aberration, but it is minor. Even with my post fx disabled the performance hit is significant, and is only happening when the lights are turned on.

    In the gif the lights do cast shadows. When they do not cast shadows the impact is not as bad, but there is still more impact than I would expect (~20+ fps drop)

    The geometry is built using ProBuilder... Might try using some planes/cubes to see if it performs better, but I wouldn't have thought PB's meshes would have resulted in this sort of performance behaviour.
     
  9. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    855
    Like Hippo said, there should be no reason that turning those lights on decreases FPS by that much if you're using deferred lighting, even with shadows. That's the sort of FPS drop you may expect to get if you're in forward (maybe, even then that scene looks too simple?).
     
  10. daniel-eherbert

    daniel-eherbert

    Joined:
    Dec 24, 2012
    Posts:
    34
    Just did a quick check of a couple things.

    Deferred is definitely on:

    (and in Player Settings too)

    Lights off (no post fx, with stats and FPS):


    Lights on (no post fx, with stats and FPS):



    The stats FPS is definitely not accurate, the performance drop is visible as you move and look around the scene (standard character controller for now).

    The ms+fps shown bottom left is calculated by looking at the difference of Time.deltaTime between Update() calls.
     
  11. daniel-eherbert

    daniel-eherbert

    Joined:
    Dec 24, 2012
    Posts:
    34
    I think what I'm going to do, at least until I can work out what the issue is (if there is one), is ditch shadowing from lights and design the rooms so that the the lighting doesn't look like it should cast strong shadows.

    Eg: