Is there any way to increase OpenGL depth buffer precision?

Started by
3 comments, last by Simulacrum 15 years, 1 month ago
Hi all, I'm having a problem drawing two objects in the scene. They're very close each other and they don't show correctly when the camera move away, some vertices put on top of others and they shouldn't (yeah, the typical depth precision problem). I have searched in google and I've found this: http://developer.download.nvidia.com/SDK/10.5/opengl/samples.html#simple_depth_float It seems that solve my problem, but this example uses FBO. Is there any way to increase OpenGL depth buffer precision without using FBO? Thanks in advance and sorry for my poor English.
Advertisement
The brute force way is to add more bits to the depth buffer, for example by requesting a pixel format with higher depth buffer precision (16 vs. 24 vs. 32 bits) or some other method like the one you linked.

The algorithmic way, which you should focus on first, is to setup the depth properties such that precision is not wasted in the first place and thus maximizing the usage of what you have instead of requesting more of the resource you're wasting. For example, see this.
The OpenGL depth buffer is not a linear. I think its log linear. Basically, most of the precision is first portion of the depth range.
So - what you can do is for the closeup objects, specify appropriate values for the camera's near and far planes, and also look at glDepthRange (near,far) this should also help with the depth problem.

You can try this technique (which is my technique) for having a linear depth buffer
http://www.geocities.com/vmelkon/zprecision.html
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by BionicBytes
The OpenGL depth buffer is not a linear. I think its log linear. Basically, most of the precision is first portion of the depth range.
So - what you can do is for the closeup objects, specify appropriate values for the camera's near and far planes, and also look at glDepthRange (near,far) this should also help with the depth problem.



Here is some information about z-buffer precision from the Opengl Faq.

This should further help what you're trying to explain.
The difference between a dream and reality is only what you choose to do about either of them.

This topic is closed to new replies.

Advertisement