shadow volume problems

I’m trying to implement stencil shadow volumes based completely on GPU as described in few papers lately.

However, I get severe artifacts and am not quite sure what is causing them. I’m first trying to get z-pass method to work, but I encounter some errors in the shadow (not speaking about when being inside the volume). I believe that the errors must be caused by errnous shadow volume data, so let me explain how I do it and I would be grateful if you can point some thing that is wrong:

First of all, the polygons that form my scene are not usually triangles. I eventually will convert them into triangle meshes but when I generate a vertex array for the degenerate-quad edges, I only consider the edges of each polygon (eg. a quad and a pentagon shares an edge to be used, but not the triangle edges that forms the pentagon or the quad).

So, I create a vertex array by taking four vertices for each edge in the model. Two of the vertices will have the normal of the right polygon sharing the edge and the other two will have the normals of the left polygon. I also check that I’m not having multiple quads for the same edge.

When I render the shadow volumes, I first bind a vertex program that will extrude the zero-volume silhouette quad accordingly to the dot product between the vertex normals and light vector.

I would also be grateful if you could post some information about how do you do this, if you find it hard to follow my crappy explanation =D.

I’m sorry if this is not completely opengl related…