Light2D and Particles2D causes incredibly FPS drop

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Roboboi

I have more than one (10-20) torches in the scenes of my game. These torches have Particles2D as a fire animation. The problem is, when I add Light2D to these torches, the game becomes incredibly laggy and FPS drops to 2. How can I fix this?

Edit: I tried to hide particles that not in screen, iy worked actually but fps is still at ~11
Edit 2: I disabled Light2D when they’re not in screen. This incrased FPS to ~20

:bust_in_silhouette: Reply From: Bubu

Well, this is simply because Light2D nodes are expensive in terms of computing power.
Try turning off unnecessary shadows or maybe shadows altogether. If the framerate is still low, use a Sprite node with an additive material.

Based on my experience, Particles2D don’t reduce performance unless you use textures above 256px and a count that exceeds 500 on my ancient tablet.

** If the framerate is still low, use a Sprite node with an additive material.**

Can you explain or suggest a tutorial about this?

Roboboi | 2021-04-06 11:11

Add a Sprite node, assign a texture, scroll down in the Inspector until you find Material under CanvasItem, add a new CanvasItemMaterial and finally change the Blend Mode to Add.

Tell me if you face any problems or if it doesn’t work.

Bubu | 2021-04-06 12:02

The current implementation of 2D Lights is not efficient and can greatly reduce the framerate especially on older hardware.

When I was developing a 2D game, I was constantly testing it on a very old tablet (Android 4.4 KitKat) that barely supported GLES 2.0.

At some point I decided to add some lights to cast shadows.

The game ran easily with 7 lights on my computer. However, my tablet was struggling to render the game.

I kept decreasing the number of lights until I settled down to only one light!

So my guess is that the current algorithm to render 2D shadows is really intensive and should be optimized.

Bubu | 2021-04-06 16:32

Sorry i dont get it. Should i add the sprite node to Particles or the particles to sprite node?

Roboboi | 2021-04-07 07:42

The Sprite node can be a cheap substitution to lights, not particles.

Bubu | 2021-04-07 08:01

:bust_in_silhouette: Reply From: Mrpaolosarino

i agree , Light 2d itself is a FPS eater. If you want to create the same effect without light 2d, use WorldEnvironment. You can delete every Light 2d in your scene and just add a autoload of WorldEnvironment and you are done