I am trying to visualize my Z-buffer with HLSL. I am working in ATI RenderMonkey to make sure my shaders are good.
I wrote what I thought would show the Z-buffer as white being the furthest and black being the closest, but when tested on a sphere, I get a solid white circle on a black background (which in a real application, I would clear to white). I expected a gray gradient sphere.
What am I doing wrong?
Here is my vertex shader:
float4x4 matViewProjection;
struct VS_INPUT
{
float4 Position : POSITION0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 PositionZW : TEXCOORD0;
};
VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Position = mul( matViewProjection, Input.Position );
Output.PositionZW = Output.Position.zw;
return Output;
}
And the pixel shader:
float4 ps_main(float2 PositionZW : TEXCOORD0) : COLOR0
{
float depth = PositionZW.x / PositionZW.y;
return float4( depth, depth, depth, 1.0f );
}
Thanks!