Skip to main content
gamedev.net
🔒 Locked

Depth-sorting

Started by Forrest2006 Jul 2, 2007 at 4:25 AM 2 replies 1.1k views
Original Post
Forrest2006
Forrest2006
I am generating a tree using L-systems, so I have the vertex positions for trunk and branches in a list and leaf positions in another list. For leaves I am placing billboard QUADS with transparent textures, so I am sorting them in 'back-to-front' order before drawing them. There are like 300 leaf billboards for a single tree. All is good until I don't apply any rotations, the frame rate is like 50 for a single tree when it's rotated!! I am doing something like this:

 //draws trunk and branches here..opaque geometry 
 drawTree(); 

 //updating the leaf positions according to the current modelview matrix 
 for(i=0;i<leaflist.size();i++)
 {
    sortedleaflist = leaflist;
    temp = sortedleaflist;
    temp.x = ModelViewMatrix*temp.x;
    temp.y = ModelViewMatrix*temp.y;
    temp.z = ModelViewMatrix*temp.z;
    sortedleaflist = temp;
 }
 
 //sorting the list
 std::sort(sortedleaflist.begin(),sortedleaflist.end(),myPredicateForSorting);

 EnableBlending();
 for(i=0;i<sortedleaflist.size();i++)
 {
    temp = sortedleaflist;
    //For billboarding
    LoadIdentity();  
    DrawQuadBillBoard(temp.x,temp.y,temp.z);
 }
 DisableBlending();
 

Please tell me what is wrong here, how can I improve the performance?
Forrest2006
Forrest2006
By LoadIdentity() , I am using an identity modelview matrix to eliminate all rotations ( for billboarding ) and Drawing textured QUADS on x,y,z which I calculated by multiplying with the Modelviewmatrix containing rotations.

Basically I am eliminating rotations for Quads so that they always face the camera, on origin facing -z direction in my case.
Rasmadrak
Rasmadrak
the trick is to only apply the rotation (or anti-camera-rotation) once per frame.
this is my drawing code:

    if (renderParticles.empty()) return;    //Get camera matrix, then render each group if it is visible.    glDisable(GL_CULL_FACE);    glDisable(GL_LIGHTING);    glAlphaFunc(GL_GREATER,0.99);    glEnable(GL_DEPTH_TEST);    vec vertex1,vertex2,vertex3,vertex4;    float modelview[16];    glGetFloatv(GL_MODELVIEW_MATRIX , modelview);        vec leftcamvector(modelview[0],modelview[4],modelview[8]);    vec upcamvector(modelview[1],modelview[5],modelview[9]);          //Draw render lists:         glDepthMask(false);                                      for (std::list<Particle*>::iterator o = renderParticles.begin(); o != renderParticles.end(); o++)             {                      vertex1 = ((*o)->globalpos-camera->globalpos) + leftcamvector*(*o)->size + upcamvector*(*o)->size;                    vertex2 = ((*o)->globalpos-camera->globalpos) - leftcamvector*(*o)->size + upcamvector*(*o)->size;                    vertex3 = ((*o)->globalpos-camera->globalpos) - leftcamvector*(*o)->size - upcamvector*(*o)->size;                    vertex4 = ((*o)->globalpos-camera->globalpos) + leftcamvector*(*o)->size - upcamvector*(*o)->size;                        //Render ONE quad, facing camera.                    glTexCoord2f((*o)->uvx2,(*o)->uvy2);                    glVertex3f(vertex1.x,vertex1.y,vertex1.z);                    glTexCoord2f((*o)->uvx,(*o)->uvy2);                    glVertex3f(vertex2.x,vertex2.y,vertex2.z);                    glTexCoord2f((*o)->uvx,(*o)->uvy);                    glVertex3f(vertex3.x,vertex3.y,vertex3.z);                    glTexCoord2f((*o)->uvx2,(*o)->uvy);                    glVertex3f(vertex4.x,vertex4.y,vertex4.z);             }                glEnd();    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);    glDepthMask(true);    glEnable(GL_CULL_FACE);    glEnable(GL_LIGHTING);    glDisable(GL_ALPHA_TEST);
"Game Maker For Life, probably never professional thou." =)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.