Logarithmic depth buffer linearization

本小妞迷上赌 提交于 2019-12-06 00:53:16

With logarithmic depth buffer, the mapping of scene (camera space) depth to values that ultimately end up in the depth buffer (0..1) is:

depth_value = log(C*z + 1) / log(C*Far + 1)

where z is the positive depth into the scene, otherwise obtainable from the w component in clip space after the projection (in your code you can use ..log(clip.w + 1.0)..).

To retrieve the camera space depth in a fragment shader, the equation needs to be inverted:

z = (exp(depth_value*log(C*far+1)) - 1)/C

or equivalently

z = (pow(C*far+1,depth_value)-1)/C

To get a linear mapping from 0..far into a 0..1, just divide it by the far value.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!