debonair
debonair

Reputation: 2593

Understanding GL_ARB_conservative_depth extension

OpenGL says that if depth function is GL_LESS and layout qualifier is depth_less, then OpenGL will perform the early depth test.

Now if the original value in buffer is 0.5 and if the depth for particular pixel is 0.8, it will fail the early depth test. But if we are modifying the value to 0.4 then it should not fail. How does this work in this case?

Upvotes: 3

Views: 1316

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54642

I don't think the combination of values in your question makes sense. With the (default) GL_LESS depth comparison function, you need to use:

layout (depth_greater) out float gl_FragDepth;

to still allow for early depth testing. With this declaration, you guarantee that, if you change the depth value in the shader, you will only make it larger.

With the GL_LESS comparison function, fragments that fail the depth test will have depth values larger than the current value in the depth buffer. This means that the early depth test can be used without affecting the result with depth_greater:

  • If the early depth test is applied, it eliminates fragments with depth larger than the current value before the fragment shader.
  • If the early depth test is not applied, the fragment will be processed by the fragment shader. Since it's guaranteed that the fragment shader will only make the value larger, it will still be larger than the current depth value, and will be eliminated by the depth test after the fragment shader.

It's perfectly legal to use any layout qualifier with any depth function. But if you use:

layout (depth_less) out float gl_FragDepth;

with GL_LESS, it really does not help, and early depth testing will not be used.

Upvotes: 6

Related Questions