Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
Absolutely how essential is it that they be properly sorted? Have you actually seen any (important) artifacts using vanilla blending? –  ChrisE Mar 7 '11 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. –  Stepan Zastupov Mar 7 '11 at 15:48
6  
Have you tried disabled depth-writes (leaving depth tests on) when rendering the particles? That should make the incorrect ordering less obvious. –  Adam Mar 14 '11 at 22:37
1  
After some experiments I found that disabling depth write is the best solution in most cases. –  Stepan Zastupov Mar 21 '11 at 15:31

4 Answers 4

up vote 5 down vote accepted

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.
  • Just additive bits

    • 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 =)

share|improve this answer

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.

share|improve this answer

first, glEnable(GL_BLEND

then glDepthMask(GL_FALSE)

then glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)

then draw particles

then glDepthMask(GL_TRUE)

then glDisable(GL_BLEND)

assuming that your sprite texture has a transparent background

share|improve this answer

You might want to read this article. I know it's related to DX11, but you may find some answers or useful info in there. There is also a few links to other discussion/articles about OIT.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.