PDA

View Full Version : Relationship between gl_FragDepth and fixed function depth test?



re9012
09-13-2017, 04:54 PM
I came across this scenario recently and after looking through both the GLSL and OpenGL specs, I have not been able to confirm or refute the following:

Is the use of gl_FragDepth independent of the fixed function depth test? That is, can gl_FragDepth write to the depth buffer even when the depth test and/or depth write mask are disabled?

I can reason why enabling the depth test is required for the depth write mask to be honored in the fixed function computation: fragments that pass the depth test use the depth write mask to determine what exactly to write. However, as I understand it, gl_FragDepth is not directly related to the depth fixed function test (it has implications for the early Z optimization, sure, but nothing beyond that).

Does anyone how the answer to this question and, if so, can point me to their source?

Thanks!

Dark Photon
09-14-2017, 06:35 AM
Is the use of gl_FragDepth independent of the fixed function depth test?

They're dependent in that the latter (and depth writes) makes use of the former, if written.
They're independent in the sense that depth tests and writes can be disabled whether or not you're writing gl_FragDepth.


That is, can gl_FragDepth write to the depth buffer even when the depth test and/or depth write mask are disabled?
No. Not through the normal depth buffer write-out by the fragment pipeline.


Does anyone how the answer to this question and, if so, can point me to their source?
Just read the spec (https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.compatibility.pdf) language that talks about "fragment depth", "fragdepth", and "DEPTH_TEST". The gl_FragDepth mentions in the GL spec and the GLSL spec make it pretty clear if/when gl_FragDepth overrides the fixed-function computed fragment depth. And the DEPTH_TEST language is pretty blatant about when that resulting fragment depth is actually used and how.