Sign in to follow this  
b3rs3rk

Shadow volumes optimizations

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
*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.

Share this post


Link to post
Share on other sites
@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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this