Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I tried to build a particle system with VertexArray  (Read 353 times)

0 Members and 1 Guest are viewing this topic.

JasonLeon

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
I tried to build a particle system with VertexArray
« on: March 10, 2025, 04:05:58 pm »
The particle class is inherited from Sprite.
It's terribly laggy when there's over 10,000 particles moving at the same time.
It's very slow when changing those vertexes' position in function Update().

Is there any solution? Thanks for your time.

JasonLeon

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: I tried to build a particle system with VertexArray
« Reply #1 on: March 10, 2025, 04:14:13 pm »
Or I should just use Sprite lists and draw them particle by particle?

Hapax

  • Hero Member
  • *****
  • Posts: 3415
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: I tried to build a particle system with VertexArray
« Reply #2 on: March 10, 2025, 06:39:04 pm »
The best option is pretty much always to draw them all together as a single vertex array. However, it's (a little bit) more complicated than just drawing lots of sprites.

Another option is to use some form of sprite batching. You can use a pre-made one or make your own.
I have two types already created:

https://github.com/SFML/SFML/wiki/Source%3A-Simple-Sprite-Batcher
takes a vector of pointers to already-created sprites and batches them into a single vertex array. This can be done every frame if required and should see an increase of speed to around 200% (or more!).
Here's a video example (warning: fast movement - flickering effects - may be unsuitable to watch):


https://github.com/Hapaxia/SelbaWard/wiki/Sprite-Batch
is a different approach. It itself contains the sprites and you update them via its interface (or copy a sf::Sprite). This way it can make internal optimisations so should result in better/faster results. This is a part of Selba Ward so feel free to have a look around for other things there you'd like to use too ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything