[转]Linear Depth Buffer(线性深度缓冲区)

The Problem with Z-Buffer

If you are a graphics programmer, you are bound to deal with the use of z-buffer for effects. For example, the depth buffer can be used for per pixel fog, soft particles, motion blur, SSAO, depth of field, etc. Using the standard depth, i.e. the value that is obtained by multiplying with World View Projection matrices followed by perspective divide, is often not enough.

The main problem with standard depth is that the depth value is not linear. Most of the time, the first 10% of the scene (the near scene) will be mapped to 0.0 to 0.9 range. In other words, 90% of the precision is used up in the first 10 percent of the viewing distance. If your algorithm relies heavily on depth comparison, you are screwed.

 

The key to handle this problem is to make the depth value linear or making it almost linear. I will describe the two approaches below:

 

Linear Depth Buffer

Notice that multilying World, View, Projection matrices with your position will make it ends up in clip space, (x, y, z, w) = (x_in_clip, y_in_clip, z_in_clip, z_in_view) except that w = z_in_view. We can exploit this fact and instead of storing the standard depth which is obtained by z/w = z_in_clip/z_in_view, we can store linear depth value. There are several variations for mapping z_in_view linearly. For example, you can do:

z_final = z_in_view / camera_far_plane

or you can also do:

z_final = (z_in_view - camera_near_plane) / (camera_far_plane - camera_near_plane)
W-Buffer

The idea of w-buffer is to provide a more distributed linear mapping than for z-buffers by inverting the depth value. By doing this, you effectively map the last 90% of the scene (the far scene) to 0.0 to 0.9 range. In other words, w buffer can still produce artifacts when many of the objects in the scene are close to the camera. In comparison to z-buffer, w-buffer has a lot more precision available for objects in the middle to far distance from the viewer. In code language, you would output:

z_final = 1 / z_in_view
 

In conclusion

I've discussed several techniques to alleviate the non-linearity of z-buffer. I hope it can give you light why you may have a lot of artifacts using the standard z-buffer.

 

from : http://www.3dgametechnology.com/index.php?option=com_content&view=article&id=95:linear-depth-buffer&catid=34:articles&Itemid=55

more flexible depth buffer control titled "quasi-linear depth buffer".
http://dl.acm.org/citation.cfm?id=383530 Autodesk Canada Co.

原文地址:https://www.cnblogs.com/pulas/p/2341462.html