Sign in to follow this  
hiya83

Early stencil test/cull before pixel shader

Recommended Posts

 

I am writing to SV_Depth in the pixel shader so earlydepthstencil is not an option.

Depth and stencil testing happen at the same time - so either both early or both late.
If you need late depth testing then you're out of luck.

 

That's unfortunate, I guess I'll try a manual stencil test at start of pixel shader. It'll probably complain about divergence I am guessing.

 

I wonder if it works for stencil too; like if I enable that for depth will it do the stencil test at the same time it does the early z... I can give it a test, thanks

Share this post


Link to post
Share on other sites

 

 

I am writing to SV_Depth in the pixel shader so earlydepthstencil is not an option.

Depth and stencil testing happen at the same time - so either both early or both late.
If you need late depth testing then you're out of luck.

 

That's unfortunate, I guess I'll try a manual stencil test at start of pixel shader. It'll probably complain about divergence I am guessing.

 

I wonder if it works for stencil too; like if I enable that for depth will it do the stencil test at the same time it does the early z... I can give it a test, thanks

 

Um look at what you quoted from Hodgman... according to him stencil happens at the same time as depth.

Share this post


Link to post
Share on other sites
I actually don't know if anything changes about that statement once you start using conservative depth though, so I'm interested to hear the result too :D

BTW, the "depth bounds test" is also a thing -- it's a non-standard extension, which rejects pixels based on whether the existing value in the depth buffer (not the depth value of your new pixel!) lies within a particular depth range. Commonly used when doing things like applying lights in a deferred renderer, where you can define the depth range that it should apply to, etc.

Share this post


Link to post
Share on other sites

Conservative depth will allow early depth to remain enabled if the constraint is set up such a way that it won't invalidate the early depth test. Typically this requires that the conservative depth constraint is "opposite" of your depth test function. So for example if you're using D3D11_COMPARISON_LESS for your depth test, you can safely use SV_DepthGreaterEqual without disabling early depth testing. This is because your pixel shader can only increase the depth, and so a pixel that fails the early depth test for having depth >= the depth buffer will continue to fail the depth test no matter what value is output by the pixel shader.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this