paroj / gltut

Learning Modern 3D Graphics Programming
https://paroj.github.io/gltut/
MIT License
1.57k stars 377 forks source link

Chapter 5, couldn't grasp the paragraph #128

Open zzxoto opened 3 years ago

zzxoto commented 3 years ago

Here is the paragraph from Chapter 5 in the book:

"Earlier, it was said that the window-space Z value of 0 is closest and 1 is farthest. However, if our clip-space Z values were negated, the depth of 1 would be closest to the view and the depth of 0 would be farthest. Yet, if we flip the direction of the depth test (GL_LESS to GL_GREATER, etc), we get the exact same result. Similarly, if we reverse the glDepthRange so that 1 is the depth zNear and 0 is the depth zFar, we get the same result if we use GL_GREATER. So it's really just a convention."

The first sentence, "Earlier, ... 1 is farthest. " is crisp. The second however, "However, if our clip-space Z .. 0 would be farthest" throws me completely. Due this, other sentence couldn't be grasped as well, because they refer to this sentence.

I understand that [-1, 1] NDC Z coordinate is mapped to [0, 1] Screen space Z coordinate with 0 being closest to the screen. And thus, GL_LESS or GL_LEQUAL is favorable depth testing function to prioritize geometries closer to near plane to draw over far plane. All that is understood and even then I couldn't make sense of the sentence that I have marked out above. I am just worried if there is more to depth buffer testing, that the confusing sentence above is trying to convey.

Thanks