openGL-将非线性深度缓冲区转换为线性深度缓冲区

时间:2020-07-28 17:07:47

标签: c++ opengl depth-testing

According to the thread on this page,为计算深度缓冲区而给出的方程式:

F_depth = 1/z - 1/n/(1/f - 1/n)   

是非线性的,仅是因为视角不同。(Note that this is a combination of from the view-space z coord to window coord directly

据我所知:
要将其转换为线性深度缓冲区,我们唯一要做的就是删除透视除法(?),然后执行glDepthRange(a,b) given here

在这种情况下,等式如下:

z_linear = z_NDC * W_clip = -(f+n)/(f-n)*z_eye + ( 2fn/(f-n) )

,并进行深度范围转换:

z_[0,1] = ( z_linear + 1 ) /2
= ( (f+n)*z_eye - 2fn + f - n )/ ( 2(f-n) )

但是,在learnopenGL site for depth testing中已完成:

首先,我们将深度值转换为NDC,这并不难:

float ndc = depth * 2.0 - 1.0; 

然后我们将得到的ndc值应用于反函数 转换以获取其线性深度值:

float linearDepth = (2.0 * near * far) / (far + near - ndc * (far - near)

如何计算非线性到线性深度缓冲区?(即方程式形成了)?

0 个答案:

没有答案