Hi, I work with XNA and I want to render the depth information of my scene into a texture. But all I get is my scene (some cubes) completly colored in white. So the depth information I determined is greater or equal 1.0 I guess. How is it done right? I googled a lot, but I can't find my mistake :'-(... Do I have to make any settings in XNA before rendering?
it looks good,
your cubes are drawn but black or not drawn at all ?
try also add 200.0 instead of 200
(in c++ it will ruin your calculation, not shure about hlsl)
maybe you values are very close to near plane, try to divide by smaller number (20),
when they are still black try 2. What are positions of your cubes ? and dimensions ?
It works with this code. But I find it very ugly to use a magic number like 25 as a factor in this case. How can I calculate this factor from my matrices? :-/
VertexToPixel PositionsVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float4 inColor: COLOR)
{
VertexToPixel Output = (VertexToPixel)0;
float4x4 preViewProjection = mul (xView, xProjection);
float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
Output.Position = mul(inPos, preWorldViewProjection);
Output.Color = 1;
Output.Color.rgb = Output.Position.z;
return Output;
}
PixelToFrame PositionsPS(VertexToPixel PSIn)
{
PixelToFrame Output = (PixelToFrame)0;
Output.Color = PSIn.Color/25;
return Output;
}
My cubes have a dimension of 0.9x0.9x0.9 at positions (0,0,-10), (0,0,-9) ... (0,0,10).
My camera is at (0,10,-20) looking at (0,0,0).