Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing depth buffer precision far from the camera

Tags:

c++

opengl

I have a project I'm working on that is making movies from a simulation. The simulation is passed from another program that defines the projection matrix.

The issue I am running into is that the other program has a sort of 'fake' orthographic view, what I mean by this is that its projection matrix is as follows:

PerspectiveMatrix = glm::perspective(3.5, 1, 1.0f, 50.0f); 

And it uses the LookAt function:

ViewMatrix = glm::lookAt(
    (2000,-3000,2000), // eye 
    (0,0,0), // center 
    (0,0,1)//up 
);

So what I mean by 'fake' orthographic view is that they have positioned the camera far enough away (and small angle to zoom the scene) that the "view lines" (for lack of a better term) are almost parallel like in a real orthographic projection.

So this is all fine and well but what I've run into, and is an issue in the other program as well, is that all of the high precision depth testing is close to the camera and in my case this is empty space. This means that there is quite a lot of z fighting as shown in the link below:

  Screenshot

So my question is what ways can I change my depth testing in order to maybe bias the buffer towards the far plane? or something along those lines. I have tried moving the NearPlane farther out, which has the result of zooming out the screen, so I compensate with a narrower angle in the perspective. But doing this enough times makes the problem worse, there isn't z fighting but it doesn't draw things at the right depth. The spheres end up on top of everything.

I did find some info at Outerra: http://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and.html They had some ideas for reversing the depth buffer but it was Nvidia specific and I need to be compatible with both ATI and Nvidia

like image 847
user3565590 Avatar asked Apr 25 '14 14:04

user3565590


People also ask

Why is my depth buffer precision so poor?

12.050 Why is my depth buffer precision so poor? The depth buffer precision in eye coordinates is strongly affected by the ratio of zFar to zNear, the zFar clipping plane, and how far an object is from the zNear clipping plane.

What is depth precision?

Depth value precisionThe depth buffer contains depth values between 0.0 and 1.0 and it compares its content with the z-values of all the objects in the scene as seen from the viewer. These z-values in view space can be any value between the projection-frustum's near and far plane.

What is depth buffer in opengl?

A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in 3D space from a particular perspective. Depth buffers are an aid to rendering a scene to ensure that the correct polygons properly occlude other polygons.


1 Answers

Both logarithmic depth and reversed depth mapping described in that blog post will work for you.

Reverse floating point is better, and it works normally in DirectX. In OpenGL it won't bring you any extra precision due to a design flaw, unless the driver exposes the NV_depth_buffer_float extension, through which you can effectively turn off the bias that makes it unusable normally.

AMD supports that extension since their 13.12 Catalyst drivers, so the technique is usable on all 5000+ series AMD GPUs (older series aren't supported by the drivers).

like image 124
camenomizoratojoakizunewake Avatar answered Nov 08 '22 14:11

camenomizoratojoakizunewake