Hi,
We know that it is possible to modify the pixel's depth value using "System Value" semantic SV_Depth in this way:
struct PixelOut
{
float4 color : SV_Target;
float depth : SV_Depth;
};
PixelOut PS(VertexOut pin)
{
PixelOut pout;
// … usual pixel work
pout.Color = float4(litColor, alpha);
// set pixel depth in normalized [0, 1] range
pout.depth = pin.PosH.z - 0.05f;
return pout;
}
As many post-effect requires the depth value of current pixel (such as fog, screen space reflection), we need to acquire it in the PS. A common way to do that is to render the depth value to a separate texture and sample it in the PS. But I found this method a bit clumsy because we already have depth value stored in the depth-stencil buffer, so I wonder whether it is possible to access from NATIVE depth buffer instead of ANOTHER depth texture.
I found this on MSDN: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-semantics
that mentions READ depth data in shader. I tried this in Unity:
half4 frag (Vert2Frag v2f, float depth : SV_Depth) : SV_Target
{
return half4(depth, depth, depth, 1);
}
However it turns out to be a pure white image, which means this depth values in all pixels are 1. So is that MSDN wrong? Is it possible to sampling a NATIVE depth buffer?
Thanks!