Archived

This topic is now archived and is closed to further replies.

Linear Zbuffer Precision

This topic is 5115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I''m writing a 3d dog-fight flight simulation game that takes place over an island. The island is rendered as a heightfield. I would like to add a transparent blue quad halfway up the heightfield to represent the ocean. However, when I do this, I have problems with Z fighting (the water level jumps around a lot when the camera moves - very ugly). My depth buffer is 24bit, my bpp is 32 and my near/far clip planes are .1 to 5000. I think I''m getting problems because OpenGL uses more depth buffer precision for closer objects, leaving not enough draw the ocean against the heightfield correctly. Is there any way to force OpenGL to use linear zbuffer precision? I think that would probably fix the problem. Most of my scene is far away, with only other player models being close to the camera most of the time. I have looked at this - From the Gamedev OpenGL FAQ: What is Z-fighting, and how can I avoid it? Z fighting is a graphical artifact which occurs when two more overlapping faces share similar values in the Z buffer, causing the faces to flicker randomly as the camera moves. This can be caused if your application is using a 16-bit Z buffer. The solution here to this is often to request a 24-bit Z-buffer in your pixel format descriptor, and to set the screen display depth to 32-bit. However, you can''t guarantee on support for 32-bit display modes (and thus 24-bit z-buffers) on all systems. A better solution is often to position your near and far clip planes differently. Because of the non-linear function used to generate Z values, values closest to the eye have far more precision than those farther away. Simply doubling the distance of the near clip plane will give you double the precision. You can also move the far clip plane inwards, however this is less likely to have such a dramatic effect.

Share this post


Link to post
Share on other sites
So, try moving your near clip-plane back. The pertinent bit of information is that objects closer to the near clip plane are what will have more precision (not the eye), so if you move it back you will essentially be making objects in the distance "closer" and give them more depth precision.

peace and (trance) out

Mage

Share this post


Link to post
Share on other sites
Hi Telamon. Is there any reason you can''t move your near clip plane out to 1 or even slightly further? That should make it stop.

Straight out of an openGL FAQ on depth buffer:

roughly log2(zFar/zNear) bits of precision are lost.

So, if zNear gets small, you lose tons of precision.

Share this post


Link to post
Share on other sites