0
\$\begingroup\$

No matter how I experiment with RasterizerState Depth Values, I always get a detached shadow which is called peter panning. Ive even adjusted the near plane for the light camera. It always seems to stay at that certain distance. I can get it no closer. enter image description here

I was wondering on some insight on what the fix could be. Below is the shader code I use when rendering the depth map which has the BIAS values.

   cbuffer cbPerObject
{
    float4x4 gWorldViewProj;
};

struct VertexIn
{
    float3 PosL    : POSITION;
};

struct VertexOut
{
    float4 PosH    : SV_POSITION;
    
};

VertexOut VS(VertexIn vin)
{
    VertexOut vout;

    vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj);

    return vout;
}
RasterizerState Depth
{
    
    DepthBias = 85000;
    DepthBiasClamp = 0.0f;
    SlopeScaledDepthBias = 10;
};



technique11 Light2Tex
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_5_0, VS()));
        SetGeometryShader(NULL);
        SetPixelShader(NULL);

        SetRasterizerState(Depth);
    }
}
\$\endgroup\$
1
\$\begingroup\$

That is a very large depth bias value. Good values for depth bias are most likely around -2 to 2 range. However this might be different for floating point vs fixed point (UNORM) depth buffer formats. Also play around with Slope Scaled Depth bias, but only after your depth bias looks mostly right. Read more about depth bias here: https://docs.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-output-merger-stage-depth-bias

Also make sure that your viewport Z range is set up correctly. It should be Znear = 0, Zfar = 1 in most cases. If you don't set up your viewport Z range correctly, then the following issue could occur: https://stackoverflow.com/questions/17286833/can-not-find-a-proper-shadow-mapping-depth-bias

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .