Question regarding Z-Buffer and PS.

Started by
4 comments, last by FoxHunter2 15 years, 8 months ago
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.
Advertisement
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.
That was exactly what I was hoping for, thanks alot...

^_^
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)?
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.

Thanks, I also noticed setting the color write channels manually didn't have any effect.

This topic is closed to new replies.

Advertisement