简体   繁体   English

0.00是OpenGL中顶点的有效z值吗?

[英]Is 0.00 a valid z value for vertices in OpenGL?

In OpenGL your viewpoint is always at [0,0,0]. 在OpenGL中,您的视点始终为[0,0,0]。 Say you have a vertex at this point as a part of a cube or some other object. 假设此时您有一个顶点,作为立方体或其他对象的一部分。 Is that vertex in front of or behind the camera/viewpoint? 该顶点是在摄像机/视点的前面还是后面? After projection I always end up with w=1 when z==0, which also (as expected) happens to vertices with z==-1. 投影之后,当z == 0时,我总是以w = 1结束,这(按预期)也发生在z ==-1的顶点上。 So practically vertices with z=0 and z=-1 ends up at equal distance after projection. 因此,实际上z = 0和z = -1的顶点在投影后以相等的距离结束。

Look how vec(2,2,0) and vec(2,2,-1) ends up with same screen coordinates here: https://jsfiddle.net/sf4dspng/1/ 在这里查看vec(2,2,0)vec(2,2,-1)如何以相同的屏幕坐标结束: https : //jsfiddle.net/sf4dspng/1/

Result: 结果:

vec1:  x=2.0000, y=2.0000, z= 0.0000, w=1
proj1: x=0.9474, y=2.0000, z=-0.2002, w=1
norm1: x=0.9474, y=2.0000, z=-0.2002, w=1
view1: x=1.0000, y=0.0000, z= 0.3999, w=1

vec2:  x=2.0000, y=2.0000, z=-1.0000, w=1
proj2: x=0.9474, y=2.0000, z= 0.8018, w=1
norm2: x=0.9474, y=2.0000, z= 0.8018, w=1
view2: x=1.0000, y=0.0000, z= 0.9009, w=1

Why is that? 这是为什么?

The coordinate system after all of your transformations are applied and the implicit perspective divide occurs after your vertex shader has been ran is called normalized device coordinates . 应用所有转换后的坐标系,以及在运行顶点着色器后发生的隐式透视划分,称为标准化设备坐标 In this space, the visible range of coordinates is from (-1,-1,-1) to (1,1,1) ; 在此空间中,坐标的可见范围是(-1,-1,-1)(1,1,1) everything else gets clipped. 其他所有东西都会被剪掉。 (0,0,0) would be in the center of the screen, and halfway into the scene. (0,0,0)将位于屏幕的中央,并进入场景的一半。

In clip coordinates , the coordinate system of values returned by your vertex shader, the visible range of XYZ values is (-w,-w,-w) to (w,w,w) , since NDC is computed as clip coordinate's XYZ values divided by the W value. 片段坐标 (顶点着色器返回的值的坐标系)中,XYZ值的可见范围是(-w,-w,-w)(w,w,w) ,因为NDC是作为片段坐标的XYZ值计算的除以W值。

Beyond that, it's up to what your vertex shader implements. 除此之外,还取决于您的顶点着色器所实现的功能。 Things like "object" and "view" space are commonly implemented by vertex shaders, but OpenGL is not actually aware of their existence. 诸如“对象”和“视图”空间之类的东西通常由顶点着色器实现,但是OpenGL实际上并不知道它们的存在。 Visible values for those spaces are dependent on how you implement it in the vertex shader, and since the space transitions are usually defined using matrices, the visible coordinates depend on the matrix you use. 这些空间的可见值取决于您在顶点着色器中的实现方式,并且由于空间过渡通常是使用矩阵定义的,因此可见坐标取决于您使用的矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM