PDA

View Full Version : Stencil Shadow Volumes problem



grasmo
12-22-2002, 05:27 AM
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 (http://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

AdrianD
12-23-2002, 08:07 AM
it looks like your mesh(or edgelist) isn't closed correctly.
are you sure, that your edge detection algorithm is working right ?
if you only check the indicies of your tris you can't detect edges with same position but different vertices.(ie. because they belonging to triangles with different mapping)
so how do you create your edgelist ?
do you check the indicies or positions ?

grasmo
12-24-2002, 03:17 AM
Hy!

Yesterday I was explaining the problem to a friend when I realized that there is a problem with my edge detection algorithm. If you look at the donut from the side, the faces should be:
front-faced
back -faced
front-faced
back -faced
My algorithm made it:
front
front
back
back.
Here is a describtion of my edgelist-creating algorithm:
I have a list with all triangles. Each triangle has a list of its three neighbours indices and a Facing-The-Light Boolean.
So I checked every Face and all of its neighbours if one faces the light and the other not. If so, the two vaertices were added to a edgelist. Since every edge was twice in the list, the list had to be cleaned. In order to keep a "edge-circle", I setup my algorithm to begin with the smallest number and to create a circle and delete the others (If the first list would contain (1-2, 2-1, 1-3, 3-1, 2-3, 3-2) then the second would be (1-2, 2-3, 3-1)).
My new idea is to add an edge only to the list if the first face is facing the light and the second isn't. That way I should have every edge only once in the edge-list and could be sure, that the winding of the resulting edge list is continuus.
If the winding is not continuus the planenormals of the edgequads are not continuus and that way the OpenGL BackFace/FrontFace culling messes up the wohle thing.
I can probably check my algorithm on the 26.12. because right now I'm not at home. Hopefully it works...

greetings
grasmo