Strange issue with shadow volumes

Started by
12 comments, last by b3rs3rk 19 years, 4 months ago
finally i've finished my shadow volumes demo. Works (i hope...) but there's a strange bug (maybe it's strange for me but not for you ogl-gurus), here's a screen: http://www.neoborn.com/users/b3rs3rk/shadow%20bug.jpg in a nutshell, i don't know why, but it's rendered also the base of the volume, instead of being rendered only the part on the floor. Anyone knows how to fix this? PS: a special thank to rodzilla who helped me a lot with his advices :)
Advertisement
It looks like this is simply the result of leaving the shadow volume open at the base. The volume should be a closed surface, so in this case, you'll need to render an extra quad to close off the bottom.
looks like both the near and far shadow volume caps are wound the wrong way. Try reversing them...
Then again if you are uisng depth-pass shadows, then you should not be using near/far shadow caps.
tryed, but nothing changes :/
Hmmm could you post your code ? It's difficult to guess with the screenshot only.
Are you doing z-pass or z-fail ? Still drawing the shadow as a big blended gray quad (not sure but in this case I'd draw caps even in z-pass mode) ?

Please help us so we can help you ;*)
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
in my render function I clear the buffers, draw the scene (a simple room and a shadow caster quad) and then i do these passes:

glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );    glStencilFunc( GL_ALWAYS, 0, 255 );	glDisable( GL_LIGHTING );		glDepthMask( GL_FALSE );	glDepthFunc( GL_LEQUAL );	glEnable( GL_CULL_FACE );    glEnable( GL_STENCIL_TEST );	glCullFace(GL_BACK);	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);	Quad.DrawShadow(LightPos,100);		glCullFace(GL_FRONT);	glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);	Quad.DrawShadow(LightPos,100);    glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );	glDepthMask( GL_TRUE );    glCullFace( GL_BACK );	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);	glStencilFunc( GL_EQUAL, 0, 255 );	glColor4f( 0.0f, 0.0f, 0.0f, 0.5f );	glEnable( GL_BLEND );	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );	glPushMatrix();	glLoadIdentity();	glBegin( GL_TRIANGLE_STRIP );		glVertex3f(-0.1f, 0.1f,-0.10f);		glVertex3f(-0.1f,-0.1f,-0.10f);		glVertex3f( 0.1f, 0.1f,-0.10f);		glVertex3f( 0.1f,-0.1f,-0.10f);	glEnd();	glPopMatrix();	glDisable( GL_BLEND );	glDisable( GL_STENCIL_TEST );	glDisable( GL_CULL_FACE );
OK, seems you're doing z-pass.
Do you draw caps for your shadow volume (I'm pretty sure you don't) ?

A solution for your problem would be to draw caps. A better one (to me) would be to make sure you draw shadows on objects only (the problem on your screenshot is shadow that's cast "in the air"). You could use the z-buffer for this : objects are wherever the z value is smaller than 1.0.

The following (before drawing your shadow quad) would (I think) do the trick :

glDepthRange(1.0, 1.0); // make sure the shadow quad is at 1.0
glEnable(GL_DEPTH_TEST); // test the depth
glDepthMask(GL_FALSE); // but don't write
glDepthFunc(GL_GREATER); // and draw only when the z value is < 1.0

And don't forget to reset this mess after drawing the shadow quad...

Not sure about this anyway... Are OpenGL gurus here ? ;*)

Hope this helps.
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
this way i get rendered only the base of the volume o_O

maybe i should try rendering the caps :/ ( how ? )
I assume you didn't forget to reset the depth range right after drawing the quad (glDepthRange(0.0, 1.0)).

Drawing caps is easy :
- render all triangles of your shadow casting object that don't "see" the light (i.e. light is in their "back") ;
- render all other faces displaced using the function you used to extend the shadow volume (i.e. translate all vertices 100 units away from the point light IIRC).
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
Quote:Original post by rodzilla
I assume you didn't forget to reset the depth range right after drawing the quad (glDepthRange(0.0, 1.0)).

Drawing caps is easy :
- render all triangles of your shadow casting object that don't "see" the light (i.e. light is in their "back") ;
- render all other faces displaced using the function you used to extend the shadow volume (i.e. translate all vertices 100 units away from the point light IIRC).


shouldn't it be

- render all faces of your shadow casting object that "see" the light (i.e. light is in their "front") ;
- render the same faces displaced using the function you used to extend the shadow volume (i.e. translate all vertices 100 units away from the point light IIRC) but with vertics in reverse order.

This topic is closed to new replies.

Advertisement