SPS and data streaming

Hi all!

I have a scene with one SPS, whose particles are added/removed depending on a stream of data coming in from the server.
The SPS is constantly at ~7000 particles (so, not that much).

The update (add/remove) frequency is of course variable (and depends on what the authoritative server decides), but the following scenario happens:

. server sends (for example) 2000 “add particles” directive
. and within a very short period of time, sends another (for example) 1500 “remove particles” directive.

Adding seems to be very fast; on initial load, ~7000 particles are added/generated in about 50-70ms.

However, when data needs to be removed/added (hence using a delta sent over by the server), the update is incredibly slow (browser freeze for several seconds).
I suspect it is because I do individual removals: sps.removeParticles(particle_index, particle_index+1) instead of sending larger slices to the removal function.

So questions:
. Is there a way to send a list of indices to removeParticles that is not a slice, but a series of individual indices. Assuming that’s the case would it change anything?
. Would I be better off simply re-generating the whole SPS mesh, starting from scratch when a delta is received?

Thanks!

The SPS is not really designed to be updated (added or deleted) frequently with so many particles.

In your case, as you are always around 7000 particles, when:

  • removing particles: set their position outside the screen so that they are not visible. Keep the indices of the particles removed
  • adding particles: use the list of indices and update the properties of the particles with the properties of the particles being added.

This way, you will never update the vertex buffer and it should be really fast.

4 Likes

Thank you Evgeni,

I did something along those lines:

. initialise the SPS with a “reserve/buffer/pool” of particles (a few thousand of them), all set at isVisible=false;
. a few data structures/maps keep track of which particle indices are used, and by which server-side entity
. when removes are read from the stream, I simply set the relevant particle[index] at isVisible=false;
. when adds are read from the stream, I simply set the relevant particles at isVisible=true along with position, scaling etc.

As you suggested, this seems not to touch the vertex buffer. And is quite fast :slight_smile: – i.e. chunks ~1000 particles get added/removed without a noticeable lag.

Bonus: I could increase the pool of “initialisation particles” in case something goes wrong and the adds() overflow the amount.

Thanks! :slight_smile:

3 Likes

I confirm :smiley:

1 Like