2
votes

I haven't realized this for a while, but my depth map is messing up. For: black pixels = near clipping plane, and white pixels = far clipping plane - Basically, if I walk towards a 100x1x100 square on the ground, and walk INTO it (reaching coordinates of 99, 0, and 99), the entire depthmap turns white. That's indicating that each pixel is at the far clipping plane, which I do not want! example

This is the code that handles rendering the depth map:

GraphicsDevice.Clear(Color.White);
effect.MainEffect.CurrentTechnique = effect.MainEffect.Techniques["DepthProcess"];
GraphicsDevice.SetVertexBuffer(line);
effect.MainEffect.CurrentTechnique.Passes[0].Apply();
GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

And the HLSL code (vertex shader, pixel shader):

DVOut DVShader(VIn _in)
{
    DVOut o;
    o.position = mul(_in.position, WorldViewProjection);
    float a = o.position.z/o.position.w;
    o.color = float4(a,a,a,1);
    return o;
}

float4 DPShader(DVOut _in) : COLOR
{
    return _in.color;
}

technique DepthProcess
{
    pass Pass0
    {
        ZEnable = TRUE;
        ZWriteEnable = TRUE;
        AlphaBlendEnable = FALSE;
        VertexShader = compile vs_2_0 DVShader();
        PixelShader = compile ps_2_0 DPShader();
    }
}

Is this because of a 1/0 error? Or something wrong with the multiplication with matrices? Or w/e?

1

1 Answers

0
votes

Solved. Somehow, the multiplication was setting the W component to a very small value.

Instead of homogeneous division, I divided by 10, which gave an acceptable result.