# Order independent transparency in particle system

I'm writing a particle system and would like to find a trick to achieve proper alpha blending without sorting particles because:

• Each particle is a point sprite in a single mesh and I can't use scene graph ability to sort transparent nodes. The system node should be properly sorted, though.
• Particle position is computed on shader from initial velocity, acceleration and time. In order to sort the system I would have to perform all this computations on CPU, which is something I want to avoid.
• Sorting hundreds of particles against camera position and uploading it on GPU each frame seams to be quiet heavy operation.

Alpha testing seems to be fast enough on GLES 2.0 and works fine for non-transparent but "masked" textures. Still, it's not enough for semi-transparent particles.

How would you handle this?

• Absolutely how essential is it that they be properly sorted? Have you actually seen any (important) artifacts using vanilla blending? Mar 7, 2011 at 15:27
• A particle can blend with background instead of another particle and then "rectangle" essence of point-sprite is very noticeable. Alpha testing helps here but artifacts are still noticeable when alpha value quiet low but not enough to discard the fragment. Mar 7, 2011 at 15:48
• Have you tried disabled depth-writes (leaving depth tests on) when rendering the particles? That should make the incorrect ordering less obvious.
Mar 14, 2011 at 22:37
• After some experiments I found that disabling depth write is the best solution in most cases. Mar 21, 2011 at 15:31

Here's what I would do.

Step 1: Don't sort. Just do it. See if it's a problem. Most likely isn't.

Step 2: Limit particles into such that do not really need sorting, such as:

• Just solids (with possibly alpha-to-coverage edges)

• let zbuffer take care of the sorting.

• a+b = b+a, so order doesn't matter

Step 3: if more is needed, split particle rendering into bits that have to be in front and the rest, and perform rendering in several passes (could fix complex smoke, for instance)

Step 4: if more is still needed, or if you need a general solution, one thing that comes to mind would be to use MRTs to get a very rough N bucket sorting done; render the particles into N output surfaces and compose them in a separate pass.

Anything further would require more information about your specific use case. But I'm pretty sure you don't really need order independency after all. Just use enough particles in random enough and it'll be ok =)

Just don't write to the depth buffer when rendering the particles. This will allow them to all be rendered and blended with each other. You should still perform depth testing though so that they can be properly occluded by geometry in the scene.

Using additive blending order doesn't matter:

glEnable(GL_BLEND)