Sign in to follow this  

No return value in PS

Recommended Posts

My shadow depth passes need to consider transparent objects as well. If the transparent fragments are "too transparent", I clip them away in the pixel shader. I don't really care about the remaining, non-clipped fragments, except for the depth value. So, I wonder if this is a legal PS (seems to compile fine)?

float PS(PSInputTexture input) : SV_Depth {
    const float a = g_dissolve * g_diffuse_texture.Sample(g_sampler, input.tex).a;
    clip(a - 0.8f);
    return input.p.z;

In order to achieve this, I wonder what represents? SV_Position.xy are screen space coordinates. I presume SV_Position.z (projection Z -> homogeneous divide -> NDC Z -> viewport transform  -> "viewport" Z, which will still be equal to NDC Z for a viewport Z range of [0.0f, 1.0f]) should be equal to SV_Depth?

Edited by matt77hias

Share this post

Link to post
Share on other sites

Like Adam already mentioned, you can just a "void" return type if you just need to discard for alpha testing.

To answer your question about the .zw components of SV_Position: the "z" component is what you call "NDC Z", in that it's after the homogenous divide but *before* the viewport transform. So if you set the MinDepth and MaxDepth of the viewport to something other than 0 and 1, that won't be reflected in the value given to the pixel shader. But you can still use as the output for SV_Depth like you're using, since the viewport transform will be applied afterward. It also won't reflect depth buffer quantization. The "w" component is the inverse of the w component output by your pixel shader, so effectively it's 1 / viewSpaceZ for a perspective projection.

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