Batching multiple ParticleSystems for drawing

Issue #1183 new
mkdx
created an issue

I think people will find useful if ParticleSystem instances could be bound to a SpriteBatch. By "ParticleSystem bound to SpriteBatch" i mean that the ParticleSystem that is bound to a SpriteBatch will use a range of sprite ids for itself (say if PS buffer size is 30, then it will use ids 1-30 if its a first system that is bound to that spritebatch). It will update those sprites as its particles and to render that said particle emitter, you will have to render either the particle system or the spritebatch it is bound to. Now here comes the part why exactly people might find it useful. It's going to be possible to bind multiple particle systems to one spritebatch (100 systems with buffer size 10 to one spritebatch that has buffer size of 1000, for example). Update calls still have to be done separately for each particle system, but to draw them all, user will just have to draw the spritebatch with one draw call. SpriteBatch and ParticleSystem will have to use same texture (otherwise emitter's texture will be overriden by the one that is used in spritebatch)

Comments (4)

  1. Alex Szpakowski

    I agree with the idea of batching together multiple particle systems that use the same sprites to improve performance, but I think this is a really hacky approach that will be more confusing than it's worth (and probably won't even work as people expect).

    Ideas for cleaner solutions are welcome :)

  2. mkdx reporter

    Can't say i'm experienced enough to describe exact ways to implement this feature, however i can imagine the least hacky way to do it. After particle system is bound to a spritebatch, it just handles spritebatch's range of ids as its own particles and that's it. The only thing that begs for question is how exactly spritebatch is going to know what range of sprite ids is "marked" as used by particle system. And buffer size for particle system is probably going to be static and unchangeable for start to avoid hacky id reallocation mechanisms. It's probably going to be okay that way mostly because "batched particle system" is going to be used, for example, for an array of fire torches on a level, and they all will have same buffer size etc.

    bind.png

    Not sure how can i explain it better.

    I know modifying existing code to implement this feature may break something later, maybe there should be some more methods to flush reservation so that spritebatch can be used as normal spritebatch (but a batch that has reserved ids should just return ids past reservation for normal sb:add() operations).

  3. Log in to comment