We’re visual people. Let’s see some pictures of the artifacts.
Like I mentioned before, there are limitations and constraints that shadow volumes imposes, and there are failure cases in that particular shadow volume technique that you need to get a solid handle on. If your artifact isn’t a coding bug you’ve introduced, my guess is that one of those constraints is being violated or failure case is being exercised.
First, you mentioned your objects often have cracks. That’s a big no-no. With shadow volumes, you have to be able to ensure that every pixel (or every sample, when rendering with MSAA) will be updated by every front facing and back-facing shadow volume face that should affect it – no exceptions! To do that, you need to ensure that your extruded shadow volume silhouettes are perfect. And to ensure that you typically need a welded mesh. That is, a mesh where for each location there is exactly one vertex in the mesh representing it, and there are no cracks/T-junctions (all vertices on edges split that edge)! The silhouette alg on the NeHe page presumes this, though doesn’t state it. See “What happens is that you go through every face, and if it is visible, …”
Further the Z-pass technique on that page has some failure cases. First, you can’t let any shadow volume intersect the near plane inside the frustum. If you do, shadow artifacts results. Think through it and you’ll see why. The near plane clips away shadow volume pixels the eye can see, messing up the in-shadow/out-of-shadow count in the stencil buffer. You can generate near caps to try and avoid this, or you can use Z-fail stencil shadows in this case. This flips your near-clipping problem into a far clipping problem, and there are better options for dealing with that problem. While you can generate far caps, you also have the option of using “depth clamping” to have the GPU generate them automagically, or you can use an infinite far clip projection matrix which eliminates the possibility of far plane clipping.
Some silhouette determination techniques only work for convex casters. Look through how NeHe’s doing that carefully and make sure it works for concave casters. Reading this may be useful:
And thinking of how shadow volumes work (extrusions of the silhouette), I don’t see why these artifacts should be there.
When you determine your silhouette edges, draw the scene from the light’s perspective and draw the silhouette edges in red. That may give you some insight. Failing that, draw your shadow volume tris in red wireframe, and rotate around the object to see if it looks good. I suspect you’ll see cracks or missing faces.
Also, try punting your existing casters and use some very simple convex surfaces to verify that your alg works in the base case: cube, etc. Then try a really simple shape with a concavity.