openGL 是如何得出公式 F_depth 的,这是窗口视口转换吗 [英] How does openGL come to the formula F_depth and and is this the window viewport transformation
问题描述
#point no.1
通过投影矩阵变换点后,我们最终得到范围[-1,1]中的点,
但是,在深度测试章节中,作者提到
F_depth = 1/z-1/far/(1/near - 1/far) 转换视图空间坐标,即 z=zeye 从 [-1,1] 到 [0,1] .
after transforming points via the projection matrix , we end up with the point in the range [-1,1],
but, in the depth testing chapter , the author mentions that
F_depth = 1/z-1/far /(1/near - 1/far) converts the view space coordinates i.e. z=zeye is transformed from [-1,1] to [0,1] .
我关注了这个帖子,其中一个成员告诉我公式F_depth
实际上是一系列完成的步骤的组合,并概述了这一步:
I've followed this thread, and one of the members tell me that the formula F_depth
is actually a composition for a series of steps done, and outlines this step:
z_Clip = C*z_eye+D*W_eye
w_Clip = -z_eye
where C=-(f+n)/(f-n), D=-2fn/(f-n).
Projective division:
z_ndc = z_clip/w_clip
Depth range:
depth = a + (a-b)*(z_ndc+1)/2
where glDepthRange(a,b) .
我尝试按照他的建议编写公式,但这与learnopenGL 中给出的 >F_depth
公式.
I tried composing the formula as he had suggested, but this is completely different from the F_depth
formula given in learnopenGL.
#point no. 2
还有一个成员告诉我,[-1,1] 到 [0,1] 是窗口视口变换,它有一个 不同的公式本身.
Also another member tells me that [-1,1] to [0,1] is the window viewport transformation, which has a different formula itself.
所以,所有这些对我来说都没有任何意义(对于同样的事情有 3 种不同的公式和解释,同样适用于 openGL),我将列出我对这些矛盾的疑问想法:
So, all of this is not making any sense to me(having 3 different formulas and explanations for the same thing that also for openGL), I'll bullet the queries I have regarding these contradicting ideas:
- F_depth 是从视图空间到窗口的变换的组合吗?空间.
- 深度范围变换和视口变换是相同的?为什么他们有不同的论坛(
Point no.1
和此链接 中的另一个 - F_depth公式是如何得到的?或者怎么组合将世界空间点转换为 [0,1] 的转换次数结果
F_depth
?
推荐答案
@horxCoder 的回答中缺少一些步骤,我想澄清一下.
In the answer of @horxCoder are missing some steps, which I want to clarify.
在教程 LearnOpenGL - 深度测试中声称深度在透视投影是
In the tutorial LearnOpenGL - Depth testing is claimed that the depth at claimed at Perspective projection is
depth = (1/z - 1/n) / (1/f - 1/n)
其中 z
是到视点的距离,n
是到近平面的距离,f
是到视点的距离视锥体的远平面.
where z
is the distance to the point of view, n
is the distance to the near plane and f
is the distance to the far plane of the Viewing frustum.
问题是为什么一个片段的深度由上面的公式给出?
The question is why the depth of a fragment is given by the above formula?
对称透视投影矩阵为(参见OpenGL投影矩阵):>
The symmetrically perspective projection matrix is (see OpenGL Projection Matrix):
1/(ta*a) 0 0 0
0 1/ta 0 0
0 0 -(f+n)/(f-n) -2fn/(f-n)
0 0 -1 0
对于深度,我们只对 z
和 w
组件感兴趣.对于输入顶点 (x_eye, y_eye, z_eye, w_eye),裁剪空间 z_clip 和 w_clip 分量通过以下方式计算:
For the depth we are just interested in the z
and w
component. For an input vertex (x_eye, y_eye, z_eye, w_eye), the clip space z_clip and w_clip components are computed by:
z_Clip = C * z_eye + D * W_eye
w_Clip = -z_eye
哪里
C = -(f+n) / (f-n)
D = -2fn / (f-n)
标准化设备空间 z 坐标由 透视鸿沟
The normalized device space z coordinate is computed by a Perspective divide
z_ndc = z_clip / w_clip
归一化设备空间z坐标映射到深度范围[a, b](参见glDepthRange
):
The normalized device space z coordinate is mapped to the depth range [a, b] (see glDepthRange
):
depth = a + (a-b) * (z_ndc+1)/2
当我们假设深度范围是 [0, 1] 并且输入顶点是 笛卡尔坐标 (x_eye, y_eye, z_eye, 1),结果如下:
When we assume tha the depth range is [0, 1] and the input vertex is a Cartesian coordinate (x_eye, y_eye, z_eye, 1), this leads to the following:
z_eye * -(f+n) / (f-n) + -2fn / (f-n)
depth = (------------------------------------------ + 1) / 2
-z_eye
并且可以转化
-z_eye * (f+n) - 2fn
depth = (-------------------------- + 1) / 2
-z_eye * (f-n)
-z_eye * (f+n) - 2fn + -z_eye * (f-n)
depth = ---------------------------------------------
-z_eye * (f-n) * 2
-z_eye * (f+n+f-n) - 2fn
depth = -------------------------------
-z_eye * (f-n) * 2
-z_eye * f - fn -f (n + z_eye)
depth = ----------------------- = ----------------
-z_eye * (f-n) z_eye (n - f)
由于视空间 z 轴指向视口外,因此从视点到顶点的 z
距离为 z = -z_eye
.这导致:
Since the view space z axis points out of the viewport, the z
distance from the point of view to the vertex is z = -z_eye
. This leads to:
f (n - z) 1/z - 1/n
depth = ----------- = -----------
z (n - f) 1/f - 1/n
这篇关于openGL 是如何得出公式 F_depth 的,这是窗口视口转换吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!