Sign in to follow this  
Zaph-0

Question regarding Z-Buffer and PS.

Recommended Posts

Hi, When a pixelshader is executed where does it test the Z information and decide to set or not to set a pixel ? The reason why I am asking this is because I would like to know if the pixel shader is executed at all (with texture blends, lookups, math, etc...) when the resulting value would be discarded anyway. I think I have to put this into consideration when optimizing my pixel shader. I don't know how this works at all so would really appreciate any reply on this.

Share this post


Link to post
Share on other sites
As long as your shader doesn't manually output a depth value, hi-Z should be able to cull all or most of the pixels that fail the depth test before the pixel shader is executed. This is precisely the reason why most modern engines use an early-Z pass, especially when heavy pixel shaders are used.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
This is precisely the reason why most modern engines use an early-Z pass, especially when heavy pixel shaders are used.


This is what I'm also doing, and I have one question in this regard:

Is it necessary to disable Z-Writes and set the Z-Func to Equal/LessEqual in the normal scene rendering pass or is this only considered a performance improvement? Also, what about setting the color write channels to only red in the Z-Pass, does this also improve performance (in case of R32F as render target)?

Share this post


Link to post
Share on other sites
Quote:
Original post by FoxHunter2
Quote:
Original post by MJP
This is precisely the reason why most modern engines use an early-Z pass, especially when heavy pixel shaders are used.


This is what I'm also doing, and I have one question in this regard:

Is it necessary to disable Z-Writes and set the Z-Func to Equal/LessEqual in the normal scene rendering pass or is this only considered a performance improvement? Also, what about setting the color write channels to only red in the Z-Pass, does this also improve performance (in case of R32F as render target)?


It's just for performance reasons. Disabling z-writes saves you the bandwidth required to write to the z-buffer.

As for disabling color channels, AFAIK it doesn't have any benefits. I would think the driver disables the channels internally when you assign a format like R32F.

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