DEPTH_TEST and Fragment-Shaders

Hi,
I’m confused. I learnt and read that the Depth-Test is performed after a fragment shader computed a fragment’s attributes. But now I read in GPU Gems 2 (34.2.3 Z-Cull) that the Depth-Test is a good means to avoid unneccessary fragment-shader executions.
What is correct? Thx :confused:

Both :wink:

In theory the depth-test is done AFTER the shader. That is how the pipeline is designed.

In practice hardware can often compute the depth-value of a pixel independently from what the shader does, so it can compute the depth-value without executing the shader. So, as an optimization, the depth test is usually done before the shader, to prevent unnecessary shader computations, when the depth-test will fail anyway.

Only when you actually write the depth-value yourself in the shader, the hardware MUST execute the shader to actually know the depth-value. In this case the depth-test is done after shader execution.

Jan.

cool, that was fast. Thx :slight_smile:

I tested it in a small example and it is really true what u told me :slight_smile:

When you use alpha test, depth comparison is also done after fragment shader execution whereas you don’t write gl_FragCoord.z.

And as if all this weren’t enough, there’s also earlyZ and HiZ, which keep track of the depth range within a tile or a hierarchy of tiles to avoid redundant fragment work. The moral of this story is to draw front-to-back, if you want to take advantage of z-culling…

http://developer.amd.com/media/gpu_assets/Depth_in-depth.pdf

Interesting paper :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.