Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Do I need Depth Sorting?

  1. #1
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    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?
    I may not be good looking but I sure am dumb.

  2. #2
    Intern Newbie
    Join Date
    Nov 2002
    Posts
    34

    Re: Do I need Depth Sorting?

    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

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Do I need Depth Sorting?

    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.
    I may not be good looking but I sure am dumb.

  4. #4
    Intern Newbie
    Join Date
    Nov 2002
    Posts
    34

    Re: Do I need 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:

    Code :
    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

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Florence, Ky USA
    Posts
    21

    Re: Do I need Depth Sorting?

    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

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Florence, Ky USA
    Posts
    21

    Re: Do I need Depth Sorting?

    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).]

  7. #7
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: Do I need Depth Sorting?

    Originally posted by Kent767:
    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).]
    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

  8. #8
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Do I need Depth Sorting?

    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...
    I may not be good looking but I sure am dumb.

  9. #9
    Intern Newbie
    Join Date
    Nov 2002
    Posts
    34

    Re: Do I need Depth Sorting?

    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.

    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...

    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

  10. #10
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Florence, Ky USA
    Posts
    21

    Re: Do I need Depth Sorting?

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •