Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light2D has performance issues on Android #9944

Closed
Noisefever opened this issue Jul 28, 2017 · 8 comments
Closed

Light2D has performance issues on Android #9944

Noisefever opened this issue Jul 28, 2017 · 8 comments

Comments

@Noisefever
Copy link

Operating system or device - Godot version:
Android, Samsung S7 - Godot 2.1.3

Issue description:

Light2D is very slow and laggy. On the desktop it runs smooth but on Android it slows down unusable. Without shadow and without shader. But as it should be in this state only a texture with add blendmode, it should be have no such impact on the framerate.

Steps to reproduce:
Marble.zip

I have attached a simple example project. Just tab (or click) the marbles to switch their lights on and off. On Android you will experience a major slowdown. The marbles can be moved with arrow keys (PC) and the accelerometer (Android).

Link to minimal example project:

@RandomShaper
Copy link
Member

I'm also hit by this. But I'm not sure a real fix is possible.

I'd say this affects any platform on which overdraw, state changes, etc. are expensive. Each CanvasItem is rendered 1 + N times, being N the number of lights that intersect it. And before that, every light has to be checked for intersection against every item. This checks is restricted to what is visible in the viewport, and I don't know it it's a bottleneck, but it has to happen.

I tried to optimize the renderer with several approaches:

  • VBOs and some bookkeeping to reduce state changes: didn't pay, the performance on mobile even worsened a bit;
  • using the depth buffer to try to reduce drawn pixels and also reduce state changes, it's work-in-progress, but probably won't work either;
  • I implemented the AT_LIGHT_PASS shader builtin to at least get code from the vertex and fragment shaders removed at runtime, for those computations not needed in lighting, but with no big difference.

Instead, the way to go would be to embrace some good practices:

  • keep the light count to the minimum;
  • make them as small as possible;
  • try to avoid intersection between lights;
  • etc.

If someone has a more promising approach, I'd be glad to hear it!

@reduz
Copy link
Member

reduz commented Jul 28, 2017 via email

@reduz
Copy link
Member

reduz commented Jul 28, 2017 via email

@Noisefever
Copy link
Author

Just to remind: if I make "fake lights" using sprites with the blend mode "add" using the same texture, there is no slowdown! And that's the thing I don't get: this should be basically the same, or am I wrong?

@reduz
Copy link
Member

reduz commented Jul 28, 2017 via email

@Noisefever
Copy link
Author

Noisefever commented Jul 28, 2017

Okay, I see. Tried to remember how I do this in my animation software. There I have a black layer, mix the lights in using "add", group the layers together and "subtract" the whole group. I thought Godot does that the same way. Seems I have to rebuild that by hand (and hope it makes a difference).

@ghost
Copy link

ghost commented Sep 7, 2018

i did what @Noisefever is doing, basically fake lights. if you have more than
light2

5 of these kind of textures on a screen, with a light2d it will start to drop fps on a gtx 950

however, reduz is right the fake lights don't look the same.. maybe i should try a different texture (even smaller) and test that

i really want to incorporate torch lighting and stuff, but hell, if you get 3 or more torches in a room and if your character has a light2d.. fps is already getting smashed lol

@Calinou
Copy link
Member

Calinou commented Nov 6, 2020

GLES2 Light2D rendering performance has been improved since 3.2.2 thanks to the introduction of 2D batching and light scissoring. GLES3 Light2D rendering performance also has been improved in 3.2.4beta1 onwards thanks to #42119, closing.

Also, 4.0 will feature significantly improved 2D lighting performance in its Vulkan renderer. thanks to a single-pass approach.

@Calinou Calinou closed this as completed Nov 6, 2020
@Calinou Calinou added this to the 3.2 milestone Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants