Particle Depth Sort

Started by
5 comments, last by jhwc1138 21 years, 7 months ago
Ok... I have working, although minimal, particle system.. I turn off depth testing so I can get the blending right but now I see the particle through everything, which I know is becuase I turned off depth testing... So my question is would depth sorting the particles make all the blending modes work right? Is there a way to make it so I don''t see the borders of the particle textures and also avoid a depth test? If there is no way, what is the best algo for depth sorting? Thanks!
Advertisement
Draw everything solid in the scene with z-buffer on, then disable the z-buffer for writing, but leave on the z-test and finally draw your particles. This should be enough for simple engines... correct if this description was wrong!


Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
Thanks, what is the openGL syntax for this...

"then disable the z-buffer for writing, but leave on the z-test"
Well.. does any one know how to do that in opengl?
glDepthMask(GL_FALSE)
if your alpha is either 0% or 100%,
disable the z-buffer for writing works
else
turn off depth testing or disable the z-buffer for writing wont make blending right, but acceptable
better draw them back to front

[edited by - iwaskia on September 18, 2002 6:45:54 PM]
Something important to mention: blend mode. If you are using GL_ONE-GL_ONE blending, you can simply turn off depth writing before drawing your particles. If you are using GL_SRC_ALPHA-GL_ONE_MINUS_SRC_ALPHA, you need to sort them back to front before drawing.

EDIT - FYI, ONE-ONE blending is best used for "energy" effects like fire, SRC_ALPHA-ONE_MINUS_SRC_ALPHA is best used for dust and smoke effects. So don't just use one-one because it is faster. Use it when appropriate.

[edited by - Neosmyle on September 18, 2002 7:10:49 PM]

This topic is closed to new replies.

Advertisement