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:
glFrontFace(GL_CW);
glStencilFunc(GL_ALWAYS, 0x0, 0xff);
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
drawShadowVolume();
glFrontFace(GL_CCW);
glStencilFunc(GL_ALWAYS, 0x0, 0xff);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
drawShadowVolume();
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:
glFrontFace(GL_CCW);
glStencilFunc(GL_ALWAYS, 0x0, 0xff);
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
drawShadowVolume();
glFrontFace(GL_CW);
glStencilFunc(GL_ALWAYS, 0x0, 0xff);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
drawShadowVolume();
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