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.
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?
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)
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).
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.
Here’s few more anecdotes that could help in optimization investigations:
-
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.
-
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)
-
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)
I’ve made this, and get an fps boost from 30 to 50…