Do I need Depth Sorting?

Hello.
I want to write a particle system that features particles with different alpha-values.
My question is, do I need Depth Sorting for this one? If so, which possibilities do I have? A good tutrial maybe?
Thanks for the help!

PS: I wanted to download a particle demo from nvidia’s developer section but could not open the *.zip .
This happens quite often (and only) with zips from their site. Does anyone know the problem?

If I understand your problem correctly, the only thing you should do is to draw translucent objects (i.e. your particle system) before any opaque objects are drawn to ensure transparency is handled correctly.
Also disable changes to the depth buffer via glDepthMask(GL_FALSE) and everything should be fine

Nick

Yes, but do I do with the particles?
I made a little test:
2 quads, the quad nearer to the camera is transparent.
I if draw the further away quad first everyting is fine. Else it looks strange.
I seems that I have to do depth-sorting.

With my particle system I don’t need to. I just extracted the important bits of the draw loop to show how I do it:

glDisable(GL_LIGHTING);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_BLEND);

//Set Depth Buffer to read only
//so we draw transparency correctly
glDepthMask(GL_FALSE);

glBindTexture(GL_TEXTURE_2D, ParticleTexture);

for(numparticles)
{
glPushMatrix();
{
glTranslatef(p.m_vOrigin.x, p.m_vOrigin.y, p.m_vOrigin.z);
glRotate(CameraRotation);

  glColor3fv(p.Color);
  glBegin(GL_QUADS);
  {
  	glTexCoord2d(0,1);
  	glVertex2f(-pSize, pSize);
  	
  	glTexCoord2d(0,0);
  	glVertex2f(-pSize, -pSize);
  	
  	glTexCoord2d(1,0);
  	glVertex2f(pSize, -pSize);
  	
  	glTexCoord2d(1,1);
  	glVertex2f(pSize, pSize);
  }
  glEnd();

}
glPopMatrix();
}

Hope this helps…
Nick

you still have to sort the particles by distance from the viewing point… otherwise if you look at it from another angle, it wont blend properly…
But yeah you still draw the particles after the other objects
Kent

i lied…
wow thats neat… that saves a bunch on framerates… disabling the depthmask

woohoo
sorry im a lamer

hmm… then why does anybody do depth sorting???

[This message has been edited by Kent767 (edited 12-02-2002).]

Originally posted by Kent767:
[b]i lied…
wow thats neat… that saves a bunch on framerates… disabling the depthmask

woohoo
sorry im a lamer

hmm… then why does anybody do depth sorting???

[This message has been edited by Kent767 (edited 12-02-2002).][/b]

I don’t think you should… a particle system quickly has tonns of polygons (a few thousand) and can seriously eat resources (as far as I’ve experienced).
Also, a particle system is usually looked at from a larger distance. So a user probably won’t see each particle seperate, but will see the system as a whole… depth testing on a particle system is rather useless in my opinion. But don’t quote me on that, as I’ve only started with openGL a few weeks ago and am not experience enough to be taken 100% seriously

Hello.
Thank you for all of your replys.
Nick, your solution does work, it delivers a different result as
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DepthMask to true and depthsorting deliver.
Still, if you say it is (really) good for the performance to skip depthsorting I go your solution, it’s easy too.
Thanks for the help guys!

P.S:
Don’t get me wrong on this, Nick, by why don’t you use those vertex arrays everybody seems to fancy so much?
I myself have never tried them yet but all keep yelling at me to do it…

Originally posted by B_old:
Hello.
Thank you for all of your replys.
Nick, your solution does work, it delivers a different result as
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Sure - depends on what blend result you wish - I’m still experimenting a bit.

[b]DepthMask to true and depthsorting deliver.
Still, if you say it is (really) good for the performance to skip depthsorting I go your solution, it’s easy too.
Thanks for the help guys!

P.S:
Don’t get me wrong on this, Nick, by why don’t you use those vertex arrays everybody seems to fancy so much?
I myself have never tried them yet but all keep yelling at me to do it…

[/b]

I’m just about to start with them - I haven’t experimented with them so far. But I guess it should (hopefully) boost my model rendering especially… With particles I found the biggest performance problem is massiv overblending - when multiple particles are blended over another - poly performance hasn’t been the big issue with my particles yet. Also, my particles change sizes individually and I think thus they’re not really suitable for arrays anyway…

Structural wrote:

Also, a particle system is usually looked at from a larger distance. So a user probably won’t see each particle seperate, but will see the system as a whole… depth testing on a particle system is rather useless in my opinion.

I totally agree. Even if seen from a close distance, most particles are small and moving fast anyway so that any glitches don’t really catch the eye. I never noticed any remarkably strange effects with my system…

Nick

yeah i understand why there is no need to do depth sorting on particle systems… what boggles me is that people do them for anything… why not just store transparent polygons seperately, and render them last w/ depthmask disabled?
Kent

Just for fun I tried feeding (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) into my particle system. Apart from looking ugly, it also had the particles overlapping in the wrong way, relating Z-precedence. I think by pure chance using (GL_SRC_ALPHA, GL_ONE) I circumvented these problems. (The looks with (SRC_A, ONE) are cool anyway) I guess using a constant value for the destination, you get independent of source alpha values and thus can avoid tedious depth sorting…
But it seems that for some applications depth sorting is necessary…

[This message has been edited by Nick Nougat (edited 12-03-2002).]

Originally posted by Kent767:
yeah i understand why there is no need to do depth sorting on particle systems… what boggles me is that people do them for anything… why not just store transparent polygons seperately, and render them last w/ depthmask disabled?

depth sorting is used to get correct alpha blending results.

imagine the following scenario: you have two quads pointing directly at the screen, with one in front of the other. the quad in front is red, and the one in back is green. the blending function is (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA), and the alpha value of both quads is .99 (almost completely opaque), say.

clearly, what you should see is .99 red, and .01 green (assuming there’s nothing else in your scene), since the red quad is in front of the green one. but if you don’t do depth sorting, and you render the red quad and then the green one, you’ll instead get .99 green and .01 red. this is the opposite of what it should be.

the hack that nick’s using, which just disables depth writes and uses a (GL_SRC_ALPHA,GL_ONE) blending function, but doesn’t do depth sorting and thus doesn’t draw back to front, can yield good results, although it doesn’t produce natual looking transparency effects (this depends on the specifics of the scene of course).

the best fool proof method for correct transparency is still depth sorting, but there is at least one other method that could be implemented with modern graphics hardware: depth peeling. it requires a seperate rendering pass for each layer of transparency though, so it’s pretty slow. nvidia has a depth peeling paper and demo available: http://developer.nvidia.com/view.asp?IO=Interactive_Order_Transparency

[This message has been edited by SThomas (edited 12-06-2002).]

The particle system in my project uses vertex arrays and has worked very well so far.

( http://www.personal.psu.edu/djp211/rnm_web )

But the code is not avaliable is it?
Do you know any good vertex array-tutorial?

Well, bright particles like fire particles work very well with my hack, although I see that this approach won’t work for everything…
Since we’re on it: could anyone give me some hints where to find good material on depth sorting?

Yeah, I would be interested in that too.
Cant’t help though.