Sign in to follow this  
warmsun

which step come first? z-test or "pixel shader program" evaluation ?

Recommended Posts

hi,all. i have a question that if z-test failed, will the "pixel shader program" evaluate or not? in other words, which step come first? z-test or "pixel shader program" evaluation ?
thanks for your reply.:)

Share this post


Link to post
Share on other sites
Hello [img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img]Indeed the depth test is performed before invoking the pixel shader (if the depth test fails, the pixel shader isn't invoked)

Share this post


Link to post
Share on other sites
It isn't quite as easy as that.

The pipeline specifies that the z test is performed AFTER the pixel shader is executed, however most hardware has 'early z rejection' ability which allows it to perform the z test before the pixel shader is run but only if the z position of pixel/fragment isn't changed during execution. If you have a shader which changes the z position of the pixel/fragment then it will run before the z-test.

Share this post


Link to post
Share on other sites
[quote name='phantom' timestamp='1318580085' post='4872443']
It isn't quite as easy as that.

The pipeline specifies that the z test is performed AFTER the pixel shader is executed, however most hardware has 'early z rejection' ability which allows it to perform the z test before the pixel shader is run but only if the z position of pixel/fragment isn't changed during execution. If you have a shader which changes the z position of the pixel/fragment then it will run before the z-test.
[/quote]

thanks for your reply, Is the early-z default if I didn't change the z-value ? OR: I need to explicitly tell the hardware do early-z.

Share this post


Link to post
Share on other sites
Early z is on by default. But if you use an unordered acces view in the pixel shader then the pixel wont be clipped at all if i remember correctly so you have to write something like [earlydepthstencil] before the shader entry point

Share this post


Link to post
Share on other sites
If you search for something like "nvidia GPU programming guide" you can find the advice from each GPU manufacturer regarding early-z (AKA, Hi-Z, ZCull, etc) for different generations of GPUs.

The main rules of thumb are -
-- clear your depth buffer every frame.
-- do not change the direction of the z-test ([i]e.g. going from a greater-than test to less-than test[/i]) within a frame.
-- shaders that output modified depth values are the enemy of Hi-Z (unless using DX11 conservative depth writes).
-- shaders that perform clipping/alpha-testing will not contribute to the Hi-Z buffer.

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