PDA

View Full Version : depth buffer: far objects bleed through closer objects



geohoffman49431
06-13-2004, 11:12 PM
I have a simple program that allows me to place objects within a scene and move around using the mouse and keyboard. But I have problems with the depth buffer. Say I have a box and I move away from the box. The wall behind the box bleeds through when I get far enough away. I have heard that part of the problem is because the depth buffer in non linear and precision is greater for geometry closer to the camera but not good for objects in the distance. So you are supposed to use as high a near value as possible when you call gluPerspective. Here is how I set up my perspective:

gluPerspective(30,w/h,10,40000);

what am I doing wrong? Is 10 too close? I have heard there is another way of hiding geometry that is behind other geometry, something about a w buffer? But that might have been only with directX.

06-14-2004, 01:39 AM
you're not doing anything wrong, it's just a limitiation of the zbuffer's precision. most cards carry 24 bits of depth. with a farz of 40000, and a field of view of 30, you're really stretching the frustum out. think of it as a zoom. if you're zoomed in that much, push the near plane out some more, since you won't see much up close anyway. conversely, if the field of view is large, say 90, then you'll want to pull the near plane in. try experimenting to find a good balance.

V-man
06-14-2004, 06:40 AM
You can read this

http://ee.1asphost.com/vmelkon/zprecision.html

It also presents a method to get around the problem with 2 ways : vertex program or glhMergedPerspectivef

geohoffman49431
06-15-2004, 09:47 AM
I figured out my main problem. Instead of thinking of the 3d graph as three float components I was thinking of it as three integer components. So I was not utilizing the decimal part of the number. I was imagining 1 foot = 1 unit. So now I have made all my objects much smaller. Now one foot equals about .01 units. Also I have made the frustum near plane 1 and the far plane 200 and enabled fog with the same near and far planes to hide objects that "disappear" out the back of the frustum. It looks 100 times better.