HY!
I am currently trying to implement shadow Volumes. Right now I am using the zpass-approach as described in the “Practical and robust Stencil Shadow Volumes…” from Nvidia.org. Here is the hadowing setup:
glCUllFace(GL_BACK);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
RenderSilhouetteEdgeQuads;
glCUllFace(GL_FRONT);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
RenderSilhouetteEdgeQuads;
Originally my algorithm rendered diffuse & specular light where the Stencil-Buffer is not 1. It works so far fine for simple objects (cube, pramid).
Then I tried loading a torus (my program loads .obj-files). Imagine a torus lying on a x/z-plane. If you look through the hole from the side, you should see some shadow and some illumination. But the shadow is opened by a backfacing silhouette edge quad and therefor negativ. So I changed my algorithm to the following:
glCUllFace(GL_BACK);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
RenderSilhouetteEdgeQuads;
glCUllFace(GL_BACK);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
RenderSilhouetteEdgeQuads;
glStencilFunc(GL_EQUAL, 0, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
RenderWitSpecularLight;
Whenever the stencil buffer is an odd number, there is shadow. That works pretty well for the donut problem.
Then I tried rotating the donut. I implemented the Shadowing Object as an OOP-Object with its own rotation functions. If the donut is rotated by 90° along the x-axis (you can see through the hole along the z-axis), there is another shadowing problem. Here are also two shadow volumes opened: First the volume from above and then the one from below. Since the second area (the hole) should be in shadow, the rest should also be in shadow. But I have exactly the same configuration as with the unrotated donut.
As this might me a little bit hard to imagine (and also because of my bad english), I will upload the program (requires windows & glut) along with screenshots on www.grasmo.de/opengl/stencil.html within the next hour or so. Look at the readme.txt for notes on the keyboard commands…
Thanx in advance
grasmo