I am trying to use shadow volumes to cast shadows from a triangle mesh but I am at a loss as to how to get the stencil buffer to increment the pixels on the model.
In the last pass, when I draw the whole scene with the lights on I use
glStencilFunc(GL_EQUAL, 0, -1);
This is what displays when I use back face culling and draw the shadows with
glStencilFunc(GL_NEVER, 1, -1);
and front face culling and draw the shadows with
glStencilFunc(GL_ALWAYS, 1, -1);
It appears to me as though I am never writing to the stencil bits on the model, but rather, that I’m writing to the stencil bits on the shadow volume itself. Is this because of my normals? Am I calculating normals with the wrong light vector? Is it because I’m incrementing bits on the wrong pass?
This is what displays when I use backface culling with
glStencilFunc(GL_ALWAYS, 1, -1);
and frontface culling with
glStencilFunc(GL_NEVER, 1, -1);
And, finally, this is what is displayed when I make no calls to glStencilFunc until the last pass where I draw the whole scene with lights and I call
glStencilFunc(GL_EQUAL, 0, -1);
Which is close to what I want except that it seems these shadows are only ever drawn by the stencil bits on the quads that make up the shadow volumes and never by the stencil bits on the model itself.