Hi,
I’m trying to render stencil shadows using the z-fail approach. I already got z-pass shadows to work but the z-fail shadows do not work for some reason. To me it looks like as if there’s something wrong with the back cap of the volume but i can’t figure out what it is. Here’s some rendering code:
vxglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
vxglDepthFunc(GL_LEQUAL);
vxglDepthMask(GL_FALSE);
vxglColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
vxglDisableClientState(GL_TEXTURE_COORD_ARRAY);
vxglEnable(GL_STENCIL_TEST);
vxglStencilFunc(GL_ALWAYS, 1, 255);// Z-Fail shadows (not working )
vxglCullFace(GL_FRONT);
vxglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
vxglDrawElements(…);vxglCullFace(GL_BACK);
vxglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
vxglDrawElements(…);/*// Z-Pass shadows (working)
vxglCullFace(GL_BACK);
vxglStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
vxglDrawElements(…);vxglCullFace(GL_FRONT);
vxglStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
vxglDrawElements(…);
//*/
I’m drawing the silhouette as triangles which form a quad. I also draw the projected, light facing triangles in reversed order (CCW as CW) as the back cap of the shadow volume. As what i heared i don’t need a front cap for the shadows to work.
I properly load the infinite projection matrix. My projected vertices are defined as (vertex - lightPos) with a w value of 0.0. a unprojected vertex simply has a w value of 1.0. I assume this is correct because z-pass shadows work
When drawing the shadows with the z-pass method, everything is fine except the usual camera in shadow problem. Even when drawing the back caps. But when it comes to the z-fail approach, most of the scene is shadowed and occassional polygonal shapes where the geometry is lighted are moving with the camera. strange eh?
I’f be happy if someone could help me with this problem. There seems to be a lot of practice with this shadow tech around here…
Silly me, didn’t know how to write “wierd”. doh!
[This message has been edited by Jens Scheddin (edited 01-11-2004).]