cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

ckotinko1
Adept I

Is it good idea to use 'discard' with conservative_depth?

Hello.

I rely on conservative depth extention in my pixel shaders:

layout (depth_greater) out float gl_FragDepth;

Is this feature compatible with shaders with discard instruction?

1 Solution
gsellers
Staff

Hi,

Yes, you can use discard; with conservative depth. The conservative depth feature controls whether the hardware runs your shader at all whereas executing discard; in the shader prevents the depth write from occurring. In the example you gave, if the depth test hardware determines that if you only make gl_FragDepth greater than it would have been then it is safe to not run the shader if the depth test is set to LESS or LEQUAL. However, if your shader executes discard, the resulting value will not be written to the depth buffer and nor will any other output from the shader.

Thanks,

Graham

View solution in original post

1 Reply
gsellers
Staff

Hi,

Yes, you can use discard; with conservative depth. The conservative depth feature controls whether the hardware runs your shader at all whereas executing discard; in the shader prevents the depth write from occurring. In the example you gave, if the depth test hardware determines that if you only make gl_FragDepth greater than it would have been then it is safe to not run the shader if the depth test is set to LESS or LEQUAL. However, if your shader executes discard, the resulting value will not be written to the depth buffer and nor will any other output from the shader.

Thanks,

Graham