Hi folks this should be an easy task but for some reason I do not get it worked out...
I just want to get a visualization of the depth in my scene using a shader:
float4x4 matViewProjection;
float4x4 matWorld;
float4 eyePos;
struct VS_OUTPUT
{
float4 position : POSITION0;
float depth : TEXCOORD0;
};
VS_OUTPUT vs_main( VS_INPUT input )
{
VS_OUTPUT output;
output.position = mul( input.position, matViewProjection );
float3 posWorld = mul(input.position, matWorld);
output.depth = distance(posWorld, eyePos);
return( output );
}
To get the depth value (or so I thought) I calculate the distance between the position in world space and the view position.
And the corresponding pixel shader
float4 ps_main(VS_OUTPUT input) : COLOR0
{
float depth = input.depth;
return float4(depth, depth, depth, 1.0f);
}
Which results nothing but a white color
So I started trial & error multiplying a value to depth:
float depth = input.depth * 0.005f;
which gives a satisfying result depending on the distance to the object. So if I get closer to the object I will have to adjust the value again.
So theres something very wrong...
Thanks for reading!