Particle System Implementation

To start this out:
I know all the math and stuff needed to create a particle system. It isn’t very complicated and it isn’t part of the question, so I’m just verifying that.

I plan to add a simple particle system to my (3D) engine that supports texturing, transformation, and additive blending, however I am not quite sure on how exactly to implement it graphics wise.
I have a mesh class that simply holds a vbo and an ibo which get drawn to the screen. The mesh class also holds an array of Vertex (one of my classes. Contains the position, texCoord, normal, and tangent) and integers.

So should I use this class with a shader in order to draw everything somehow, or should I render them some other way, completely different from my mesh class?

I think the question should be whether to use point sprites or not:

  1. Bill-board approach:

Sort array of vertices by distance from the camera (for correct blending), generate bill-board quads from your array of vertices, buffer the data into a dynamic VBO, render each sprite as a quad or two triangles. Your mesh would consist of VBOs for texture coordinates (and colours if required) as well as the quad vertices (or one inter-leaved VBO).

pros:

  • re-uses your existing mesh code.

cons:

  • over-head of having to orientate the quads to the camera.
  • need to provide texture coordinates but these are usually the same for every sprite hence redundant data.
  1. Point-sprites:

As #1 but use point sprites rather than billboard quads.

pros:

  • re-uses your existing mesh code.
  • no need to calculate billboard orientation or texture coordinates.
  • usually faster rendering.
  • supported by most (all) modern graphics cards (including OpenGL-ES).

cons:

  • point sprites have some limitations (e.g. large sprites are culled if the centre point is outside the view frustum) but these are usually not relevant or can be worked around.

Either approach can be enhanced by using a vertex/fragment shader:

  • more flexible rendering
  • faster than fixed-function pipeline

Note sure why you would need an IBO for a particle system though, or is it just an optional part of your mesh class?

  • stride

The ibo is used so there aren’t as many vertices needed overall but it would be trivial to make it optional.
Thanks for the reply, I’ll do a bit more research on it now.
Also, when you say I can improve it using glsl you mean just rendering it with glsl correct? Because everything is rendered with shaders by default.

If you’re okay with delving a bit deeper into graphics, you could look into using geometry shaders. That way you can get the best of both worlds.

I’ve researched them before and they seem intriguing. What I got from it was that they give the ability to change the primitive rendering type OpenGL uses as well as edit certain other attributes of… and yeah that’s where my knowledge ends.

Google, here I come. If you have any good resources feel free to post them here too.

The information is out there, but what you can do with them is a bit harder to find. Basically you can draw your particles as “points” which have the attributes that you need: for example position, size, rotation and color. Then you can use a geometry shader to output 4 new vertices to form a quad, allowing you to do proper billboarding without transforming on the CPU (transform by view matrix first, expand to screen aligned quad, transform by projection matrix). You can also apply stuff like rotation and generate texture coordinates for each corner. Without geometry shaders you’d be forced to render the particles as quads with 4 vertices each, but a lot of this information is just data that’s shared by all 4 vertices. For example there’s no need to supply 4 positions when one position and a size is enough.

That’s mind blowing. Wow that really is cool, thanks for elaborating!
When you say transform by view matrix, then expand to screen aligned quad, the screen aligned part refers to bill boarding part right?