I am trying to figure out if I am doing the right thing to generate shadow volumes using carmack’s reverse, Could somebody here help me?
This is what I do, but it does not work correctly
- Render the Front Facing polygons from the mesh
- Render the Shadow Volume Cap (triangulated silhouette polygon at the far end of the shadow)
- Render the Front Facing Shadow Volume Quads
- Render the Back Facing Shadow Volume Quads
This just dont work,
Could somebody please explain the right steps in this coz I somehow just cant visualize the Z-Fail case in my mind.
You should do it like
- Draw scene to depthbuffer with glDepthFunc(GL_LEQUAL)
- Render front facing triangles of the shadow volume (including the cap at both sides) with glDepthFunc(GL_LESS) & glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);
- As 2, but backfacing triangles glStencilOp(GL_KEEP,GL_DECR,GL_KEEP);
4: Render scene with stencil test.
You may have some help of my demo or Carmacks reversed: http://esprit.campus.luth.se/~humus/?page=OpenGL
This is what I do,
// render the front facing polygons and the cap
// Now the front facing silhouette walls
glFrontFace(GL_CW); // walls have reversed Culling
// now change the stencil op and render the back facing walls
Note that my Shadow Polygons winding order is CW for front facing and CCW for back facing.
Is this right or am I missing somthing??
I don’t even get what you’re trying to do with that code
Especially this one is confusing: glStencilFunc(GL_ALWAYS,128,0xff);
Have you read the source of my demo above, I really think it would help, it’s not all that much code. Also check nVidia’s paper on the subject, it’s really helpful too.