Sign in to follow this  
whathappened

OpenGL Flickering problems with Z-fail shadow volumes

Recommended Posts

Im doing shadow volumes (z-fail). But the problem is, suppose I have a quad that casts a shadow volume. Since I use z-fail, I have to cap the volume, which means I will draw a new quad over the old when I cast the shadows. But then the quad is flickering. This is probably because some lack of depth precision (some pixels in the capping-quad will pass the z-test and some wont, since it's drawn exactly on the same spot as the original quad in my scene in the first pass). How can I get around this? I mean, I give the same vertices and Im using GL_LESS for depth testing so this shouldnt happen. I read about something called D3DRS_ZBIAS in DX, can I use something similar in OpenGL? Anyway, is there any way of setting the number of bits used by the depth buffer using glut? [Edited by - whathappened on August 14, 2007 7:36:07 PM]

Share this post


Link to post
Share on other sites
The root of your problem is due to depth buffer precision - although using the glPolygonOffset function should solve this problem there is another approach.

Z-Buffers are non linear, values are stacked close to the eye and are further apart away from the eye. For an explanation see the following article: Using W-Buffers for Improved Depth Resolution. Although w-buffers are largely considered obsolete that article has a pretty decent explanation of why z-buffers are a bit rubbish in places.

In light of this new bit of knowledge you may try adjusting your near and far planes to increase precision. Look for your gluPerspective call and start there.

Share this post


Link to post
Share on other sites
So I should add some offset to the volume? Sholdnt something like
glPolygonOffset(1.0f, 1.0f) do it? It doesnt :)

Never mind, I forgot the glEnable(GL_POLYGON_OFFSET_FILL); Thanks guys, seems to work now! Almost.. there are some camera values for which it doesnt work, a very few... that's weird

[Edited by - whathappened on August 15, 2007 9:59:02 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this