[SOLVED] Shadow Volume problem

Hi all,
I have a problem calculating my shadows using shadow volumes and the stencil buffer. I have two triangles (triangle a and b). They have the same position except one of them is further away (triangle b), so triangle a is in front of triangle b. Now when the light is in front of them, the shadow of triangle a will cast correctly on triangle b. But when i move my light source behind triangle b, there is no shadow on triangle a. I am drawing my volumes like this:

I think, thats the common way of doing it. I also think, i know the problem. If the light is behind the triangles, the directions of the shadow volumes are changed, because the shadow volume is pointing in the direction of the camera instead of away from it. So the face culling is not working like it should be. If i swap glFrontFace(GL_CW); and glFrontFace(GL_CCW); like this:

then the shadow is working when the light is behind the triangles, but if the light is in front of them, it's not working (obviously). Now i don't know, how i could fix this.
Does anyone have a clue what i could change to get it to work properly?
If some screenshots or more code is needed, i will provide it.
Thanks in advance...
cookiehunter

This the classic case when stencil shadow volumes fail if the camera is inside the shadow volume.

There are multiple solutions for your issue, but probably the most simple and most used one are Z-fail shadow volumes, aka Carmack's reverse. You should be able to find a lot of articles about it.

Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
Technical Blog: http://www.rastergrid.com/blog/

This the classic case when stencil shadow volumes fail if the camera is inside the shadow volume.

There are multiple solutions for your issue, but probably the most simple and most used one are Z-fail shadow volumes, aka Carmack's reverse. You should be able to find a lot of articles about it.

That's my recollection too. Depth Fail turns your near plane clipping problem into a far plane clipping problem (which you still have to deal with, but can be dealt with more simply). One solution is to use depth clamp, and another is to push the far clip out to infinity (effectively disabling far clipping). With depth fail you have to cap your shadow volumes (whereas with depth pass you don't, IIRC).