When did the Z axis roll over? (Opengl)

To improve my understanding of OpenGL and 3D, I am trying to implement a simple rendering pipeline that only runs on the processor. Where this makes sense, I try to use the same standards as OpenGL. For example, I use the right coordinate system as OpenGL . As is often the case when learning something new, I now have a question that I can’t find an answer to. If something in the following does not make sense, please forgive and correct me.

In the clip space (the coordinate that you pass gl_Position in your vertex shader), negative Z is away from the user. But in the depth buffer, a positive Z is far away (if you use the default depth settings).

One answer to this question suggests that switching is due to projection transformation. But I did a little experiment (based on WebGL / OpenGL ES) that suggests the opposite: in the clip space, Z indicates from the user even if you are not using projection transform.

So, at some point, after you passed it to gl_Position , OpenGL will flip the Z coordinate. When and how is it?

My hunch is that it is in species conversion , but I could not find the documentation that supports this.

+2
source share
2 answers

OpenGL's Clip-Space is already left (and always has been). Thus, in modern GL there is no space explicitly using the right-handed system, and there is no “flipping” at all. However, the eye space in the old GL was often determined on the right side, and the “flipping” was performed as part of the projection matrix, glFrustum() and gluPerpective() clearly expected positive values ​​for negative negative z that was close to and far from the opposite. However, since you can use arbitrary matrices, you were never forced to define your eyes or object spaces with the right, it was just something like a default convention. And still, many people follow this programmable pipeline convention.

+3
source

According to the WebGL Starter Guide, the z axis is inverted during perspective division, which is performed after the projection is converted.

Here is what he says:

Prospective separation converts the viewing of a truncated cone into a cube centered at the origin with minimum coordinates [-1, -1, -1] and maximum coordinates [1,1,1]. In addition, the direction of the z axis is inverted, as shown in the following figure:

enter image description here

0
source

Source: https://habr.com/ru/post/1502517/


All Articles