Skip to main content
gamedev.net
🔒 Locked

Shadow volumes optimizations

Started by b3rs3rk Aug 29, 2005 at 8:41 PM 2 replies 800+ views
Original Post
b3rs3rk
b3rs3rk
i've finally finished my shadow volumes demo (i've been working on it for toooo loooong..), now i have my scene and my models perfectly shadowed, using both depth pass and depth fail when needed :) Now i'm trying to get things speed up: in a nutshell, after i've found an object's silouhette, i draw it in immediate mode:

for(every mesh){
  for(current mesh->numOfEdges){

     .....silouhette finding algo....

     v1 = mesh->pvert[ i1 ].v;
     v2 = mesh->pvert[ i2 ].v; 
     v3 = ExtendVertex(&v1,lightpos,INFINITY);
     v4 = ExtendVertex(&v2,lightpos,INFINITY);

     glBegin(GL_QUADS);
       glVertex3f( v1.x, v1.y, v1.z );
       glVertex3f( v2.x, v2.y, v2.z );
       glVertex3f( v4.x, v4.y, v4.z );
       glVertex3f( v3.x, v3.y, v3.z );	
     glEnd();
  }
}

this works good, but there is a way to get things better? I've tryied using vertex buffers, but this way the fps drops down:

vector<tVertex> ShadowVertices;

for(every mesh){
  for(current mesh->numOfEdges){

     .....silouhette finding algo....

     v1 = mesh->pvert[ i1 ].v;
     v2 = mesh->pvert[ i2 ].v; 
     v3 = ExtendVertex(&v1,lightpos,INFINITY);
     v4 = ExtendVertex(&v2,lightpos,INFINITY);

     ShadowVertices.push_back(v1);
     ShadowVertices.push_back(v2);
     ShadowVertices.push_back(v4);
     ShadowVertices.push_back(v3);
  }
}

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer  (3, GL_FLOAT, sizeof(tVertex), &ShadowVertices[0]);	
glDrawArrays(GL_QUADS, 0, ShadowVertices.size());
glDisableClientState(GL_VERTEX_ARRAY);

some advices?
Toji
Toji
I have to say that I'm surprised that the newer version of the code is slower. With so many calls to glBegin/glEnd, I would have thought that the older code would be slower for certain. Oh well...

One simple (but probably not critical) thing I can think of is to not use Quads, but instead triangles. It's only a tiny bit more work on your part, but it saves OpenGL from doing some calculation behind your back.

Another thing: Are you using std::vector for the vertex list, or a class of your own? May be a memory management thing.

Finally, the old standby fix: Are you running the latest drivers? It could honestly just be a bug in the driver version you have. (What card is it, by the way?)

Sorry if that doesn't help, but it is a bit baffling.
// The user formerly known as Tojiro67445, formerly known as Toji [smile]
Name_Unknown
Name_Unknown
*scratch that*

Don't use the vector, it has too many copies and if it is on the stack you are allocating and deallocating every frame.

If you wanna use an array, set up a scratch array buffer and use that instead.
"It's such a useful tool for living in the city!"
b3rs3rk
b3rs3rk
@Toji: if i use triangles the fps doesn't change too much... yes,i'm using std::vector and the latest driver (nvidia 77.77 on a fx5700 256).

@Name_Unknown: a scratch array buffer? i would, but it isn't slower? the vector i'm using is a member of the class of the shadowed model, so i don't recreate it every frame, i simply call the clear() method. If i use an array i should allocate memory and dealloc every time...

Topic Locked

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

Sign in to reply to this topic.