I'm trying to understand the tutorial 27th in Nehe website. This is about how to cast a shadow of an object using stencil buffer in OpenGL. The idea here is checking the directions of all the faces of the object with the direction of light, and the result will define whether or not this face make a shadow. In the case of making a shadow, we will draw "shadow" into the stencil buffer as the following code.
// First Pass. Increase Stencil Value In The Shadow
glFrontFace( GL_CCW );
glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
doShadowPass( object, lightPosition );
// Second Pass. Decrease Stencil Value In The Shadow
glFrontFace( GL_CW );
glStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
doShadowPass( object, lightPosition );
My question here is why "glFrontFace" function in the second pass help remove shadow between objects in the scene?
I Hope to see your answer. Thanks so much!
P/S:this is the explanation in the tutorial, but I don't get it
"They are rendered in two passes as you can see, one incrementing the stencil buffer with the front faces (casting the shadow), the second decrementing the stencil buffer with the backfaces ("turning off" the shadow between the object and any other surfaces)."