Particle System

Hello! I’m making a simple particle system for my asteroid-belt. It consists of only GL_POINTS with a randomized location, color, and alpha value.

I have a class called Particle which consists of the mentioned variables. Then I have a class called ParticleSystem which includes a vector of Particle.

If I have very small values for the number of particles it works fine. But I want to have a lot more for a better look. When I have about 7000 particles it begins to lag. But for it to look good I want to have at least 30000.

So, my question is, how can this be optimized? I bet a complicated particle system consists of more than 7000 particles, or?

A lot depends on how you draw the particles. Are you using glBegin and glEnd? Because those will kill your framerate with that many calls. Its best to use a VBO, but that means you will have to combine all your vertices into a single array (or keep them ordered regularly).

For upwards of 10,000 instances you could use ‘instancing’ techniques. The only real advantage this gives is less API calling - and that is only a benefit if you believe this is the application bottle neck.
There are two really useful methods for instancing: TextureBuffer objects and ARB_instanced_arrays which method you choose depends upon your GL version + supported extentions and preference.
With TBO you pack your ‘instance’ data into a texture and read that back in the vertex shader to fill out vertex position and color/alpha.
With instanced arrays, you set up another set of vertex attributes containing the per-instance data (position, colour)
Both will work, but I suspect it comes down to whether you intend to update the ‘instance’ data in real time or not.

With this number of points you could easily just put them all into a single static VBO, with attributes representing initial position, velocity, direction, etc, then each frame draw the VBO in a single draw call, passing the current time as a uniform and calculating the final position to draw at in your vertex shader.

You may find however that it’s fillrate that’s killing you rather than vertex submission, in which case no trick to optimize vertex submission is going to help.

One thing is for certain - going OO at such a fine level of detail as a single point is not really necessary at all.