paroj / gltut

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

Overlap and Depth Buffering Explanation #15

Closed paroj closed 8 years ago

paroj commented 13 years ago

Originally reported by: Anonymous


Given the following quote from the online opengl documentation for glDepthFunc:

"GL_LESS - Passes if the incoming depth value is less than the stored depth value."

Along with the following quotes from the Overlap and Depth Buffering tutorial page:

"When the test is true, the incoming fragment is written."

I don't believe the following sentence is correct (but would very much like to understand if I'm wrong):

"So GL_LESS means that, when the incoming fragment's depth is less than the depth from the depth buffer, the incoming fragment is not written."

Shouldn't it be?:

"So GL_LESS means that, when the incoming fragment's depth is less than the depth from the depth buffer, the incoming fragment is written."

.

As a beginner this is my understanding of the described depth comparison process:

Writing 1st wedge object

offsetUniform.z is 0.0f so window-space Z value is 0.0f

No previous depth value stored so glDepthRange Max used

(winZ GL_LESS DepthRangeMax) comparison is actually (0.0f < 1.0f = TRUE)

Test passed

Therefore: fragment colour written and current depth of 0.0f written

.

Writing 2nd wedge object

offsetUniform.z is -1.0f so window-space Z value is 1.0f

Previous depth value stored is 0.0f

(winZ GL_LESS PreviousDepthValue) comparison is actually (1.0f < 0.0f = FALSE)

Test failed

Therefore: fragment colour is not written and current depth remains 0.0f

.

To me this process corresponds with the output image shown in Figure 5.3.

Thank you...


paroj commented 13 years ago

Original comment by Anonymous:


Thank you for confirming, these tutorials are excellent.

Peter

paroj commented 13 years ago

Original comment by Jason McKesson (Bitbucket: alfonse, GitHub: alfonse):


This looks like a simple typo. I have checked in a fix for this.