No return value in PS

Started by
4 comments, last by MJP 6 years, 7 months ago

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 SV_Position.zw 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?

🧙

Advertisement

Why not just return "void"?

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

55 minutes ago, ajmiles said:

Why not just return "void"?

Does that preserve writing to the depth buffer?

🧙

Yup.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

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.

This topic is closed to new replies.

Advertisement