love2d / love

LÖVE is an awesome 2D game framework for Lua.
https://love2d.org
Other
4.83k stars 388 forks source link

Particle System performance #242

Closed slime73 closed 11 years ago

slime73 commented 13 years ago

Original report by Alex Szpakowski (Bitbucket: slime73, GitHub: slime73).


The performance of particle systems in LÖVE is not on par with what I would expect - even having a few simple particle systems for weapon hit effects greatly impacts the framerate of my games.

I don't know much about OpenGL or how LÖVE uses it, but I'm fairly sure there is plenty of room for improvement in the particle system code (VBO's?)

slime73 commented 13 years ago

Original comment by Anders Ruud (Bitbucket: rude, GitHub: rude).


Basically true.

If I remember correctly, ParticleSystem uses many immediate mode calls for each particle. It would be much better to use a vertex array.

slime73 commented 12 years ago

Original comment by Alex Szpakowski (Bitbucket: slime73, GitHub: slime73).


It might be worth it to use point sprites (one vertex per sprite rather than the normal 4 or 6) combined with vertex shaders, and have a vertex array fallback for computers that don't support that method.

See http://www.shmup-dev.com/forum/index.php?topic=1870.0

slime73 commented 12 years ago

Original comment by Alex Szpakowski (Bitbucket: slime73, GitHub: slime73).


[[https://bitbucket.org/rude/love/changeset/0103d2f89e35|0103d2f89e35]] (from #353) increased performance of particle systems a lot, because they no longer re-bind their sprite unnecessarily for every particle being drawn.

slime73 commented 11 years ago

Original comment by Alex Szpakowski (Bitbucket: slime73, GitHub: slime73).


I tested out a change which improves performance a fair amount with little code modification: using the changes and test .love attached below, frametime went from 16ms down to 12ms on my Intel HD 3000, and from 9ms down to 5ms on my AMD 6750m.

slime73 commented 11 years ago

Original comment by Alex Szpakowski (Bitbucket: slime73, GitHub: slime73).


slime73 commented 11 years ago

Original comment by Alex Szpakowski (Bitbucket: slime73, GitHub: slime73).


I improved performance even more by using a single vertex array to draw all particles in a particle system. I now get 8.6ms with my HD 3000, and 3.25ms with my AMD 6750m.

Some stats when using just 500 particles instead of 5000:

Intel HD 3000

AMD Radeon HD 6750m

slime73 commented 11 years ago

Original comment by Minh Ngo (Bitbucket: mngo, GitHub: mngo).


+1 to this. Couldn't hurt to be faster right? Particles are sweet!

slime73 commented 11 years ago

Original comment by Alex Szpakowski (Bitbucket: slime73, GitHub: slime73).


Commit 77889bd applied my performance-improving patch.

Particle systems are tricky on framerate even in meticulously optimized AAA games. During my testing I found that rendering a scaled down particle system to a half-screen sized canvas, and then rendering the canvas scaled up to the screen improved performance a ton on large particle systems.

I went from 8.6ms per frame (using the latest performance improvements) down to 2.2ms with my 5000-particle test when using my Intel HD 3000, just by doing the aforementioned canvas optimization.