Flickering problems with Z-fail shadow volumes

Started by
2 comments, last by whathappened 16 years, 8 months ago
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]
Advertisement
Hello,

try googling for glPolygonOffset() This should solve your problem.

Jeroen
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.
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]

This topic is closed to new replies.

Advertisement