1
\$\begingroup\$

Accoring to this, depth testing is usually performed after the fragment shader stage. Why is that? I thought that a fragment is sent with its depth value to the FS, then the depth test happens before the FS executes, so the gpu can avoid a spare FS execution if the pixel is covered by a closer one.

Why is it not like that?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

As far as why a depth dest would happen before or after the fragment shader, there is a section in that wiki link on Early Depth Test as well as an entire article about it here.

When a depth test is performed in the fragment shader itself, it's possible that the Fragment's output depth value is tested against the depth of the sample being written to. There is a line in that article:

If the test fails, the fragment is discarded. If the test passes, the depth buffer will be updated with the fragment's output depth, unless a subsequent per-sample operation prevents it.

This "per-sample" operation means that a fragment shader can be instructed to only perform depth tests on a per-pixel basis and you would therefore want/need it in the fragment shader.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .