Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

2D renderer and baking lights

Discussion in '2019.2 Beta' started by thormond, Jul 18, 2019.

  1. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    Hi, is it possible to bake a lightmap for the new 2D lights introduced with LWRP and 2D renderer? (especially for global lights). It seems like it doesn't work at all but perhaps my settings are wrong.
     
  2. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    No, it's not possible to use any of the 3D lightmapping systems with the 2D lights. We're interested in knowing your motivation behind this though. What makes you want to bake the 2D lights? Is it because they don't move in your scene and you want to avoiding calculating the lighting every frame?
     
  3. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    I'm trying to optimize the 2D Lights for mobile device which is actually pretty hard to do without causing the game to fall below the optimal 30 FPS. Calculating things such as falloff, normals, multiple light blend styles every frame is just not something a mobile GPU can effectively do (especially falloff, I could live without normals and rim lights but falloff is necessary and super expensive for some reason, for example: 3 freeform lights with non-zero falloff get me below 30 FPS while 8 freeform lights without falloff do not)
    The solution would be to bake all of the light for backgrounds and have maybe like one point light follow the player around (with as minimal falloff as possible)
     
  4. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    So I was running some tests, before it took me 3 freeform lights with some falloff to get me below 30 FPS so I was curious how many freeform lights without falloff it would take to get me below 30 FPS.

    The number I arrived at is 64.
    3 freeform lights with falloff = 64 freeform lights without falloff

    Another interesting find: Even if you set falloff intensity on a point light to 0 it will still have some falloff and keep butchering the GPU on mobile (compared to freeform on the same setting).
     
  5. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    These are really interesting finds! Thanks! We'll look into them. For this preview release of the 2D renderer we hardly did any optimizations, and we expect this kind of performance problems to happen.
     
  6. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    Here's few more anecdotes that could help in optimization investigations:

    1) I had a scene that yielded 9 FPS, when i checked off all the Light Blend Styles in 2D Renderer (aside from the default Multiply) the FPS capped at 30 FPS. Interestingly no light on that scene was using any of the unchecked blend styles.

    2) Unchecking "Use Normal Map" on light sources always improved FPS by a lot, even if the sprites affected by light do not have any normal map assigned to them in Secondary Textures (that could be a big deal if we wanted to make a highly performant light that normally affects the background elements that lack normal map and sometimes affects the player along with his normal map)

    3) Static lights and lights that move have exactly the same performance for some reason. One time i had a scene that yielded 28 FPS with lights that had a "shake" script on them (to emulate movement). When I disabled the script the FPS didn't change (so I'm assuming that light gets re-calculated every frame independent of if it's static or not)
     
    DungDajHjep likes this.
  7. Piatlopunk

    Piatlopunk

    Joined:
    Jul 26, 2019
    Posts:
    2