0
\$\begingroup\$

Does depth test runs before fragment shader,hence not even processing the fragment with frag shader if fragment is discarded Or It first runs the fragment shader and then depth test I.e. fragment shader runs for even the discarded frags.

If prior is false,then can it be achieved some how?

\$\endgroup\$
0
\$\begingroup\$

The answer is: Both.

If your fragment shader writes to gl_FragDepth it will do the depth test after your shader.

If you leave gl_FragDepth alone it will do the depth test before your shader.

source: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FragDepth.xhtml

\$\endgroup\$
  • \$\begingroup\$ Also if you use the discard keyword anywhere, even conditionally it will prevent using early tests \$\endgroup\$ – cozmic Feb 13 '17 at 11:03
  • \$\begingroup\$ If you don't use either and using GLSL430 or higher you can use layout(early_fragment_tests) in; to force using early tests, otherwise it's driver-dependand \$\endgroup\$ – cozmic Feb 13 '17 at 11:05
  • \$\begingroup\$ @cozmic If you use the discard keyword the GPU can still do an early Z test and skip pixels (and the fragment shader) that would not show. It does not affect the regular depth test. What discard prevents is doing the full hidden surface removal on deferred tile renderers when the Z test passes. \$\endgroup\$ – Stephane Hockenhull Feb 13 '17 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.