Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just some ideas for optimization of simple, 2D sprite particles.</p> <p>A good idea is to send all particles in a vertex array / VBO, and use a vertex shader to update their positions over time. This is great if you have a simple motion that can be easily described using a mathematical formula where <code>x(t)</code> and <code>y(t)</code> (that is, they depend only on time). </p> <p>Another great idea is using point sprites instead of triangles and quads. This should reduce the required bandwidth on the pipeline to a quarter. </p> <hr> <p>In my space sim I have implemented the most trivial approach: particles sent as textured quads using <code>glBegin()</code>/<code>glEnd()</code>. They are dumped into the current "sector" as individual objects and are completely independent from the time of dumping onwards. This is the most primitive, stupid, and idiotic thing to do and is responsible for great reduction in performance, especially since what I do is iterate through objects via STL vector's iterator and send each and every one of them sequentially.</p> <p>You need to consider how many particles you want, and what do you want them to do. * Do you want them to react to surroundings and collide? Then you need updating handled on CPU and data sent over and over again. * Do they just fly around in the most stupid manner possible? Then you may be able to get away with sending all particles as VBO and TBO, and update them in shader.</p> <p>Have fun!</p> <hr> <p>Updated to relate to the comment #1 from asker :-)</p> <p>What I would do is use the <a href="http://en.wikipedia.org/wiki/KISS_principle" rel="nofollow noreferrer">KISS principle</a>. This means: a class called <code>ParticleEmitter</code> containing a vertex array, an array of velocities, and a STL <code>vector</code> with instances of simple colliders such as plane, sphere, triangle. Additionally, have a "global"* STL <code>vector</code> with colliders. Then update the velocities according to colliders. </p> <p>Similar can be done with affectors (gravity, wind and such): another STL vector in <code>ParticleEmitter</code> with affectors and another "global" STL <code>vector</code> with affectors. </p> <p>Affectors and colliders would be classes that would implement <code>affectParticle(particle_t*)</code>. where <code>struct particle_t { float x,y,z; float vx,vy,vz; }</code>. I would keep it a POD structure, and run updating in <code>ParticleEmitter::update()</code>.</p> <p>However if you are running this on iPhone, could it be overcomplication? Perhaps you can get away with what you already implemented? I have no idea how my design might affect benchmark results, but it sounds reasonable enough to me if you keep the particle, collider and affector count down, because it sounds like it might scale with approximately <code>n*c+n*a</code>. </p> <p>These are just my ad-hoc thoughts, and how I'd personally implement it. Your design, or other people's design, would probably be better :-)</p> <p><code>*</code> "Global" under quotes, because it would probably make sense to make use of any space partitioning you have in use.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload