Quantcast
Channel: Question and Answer » hlsl
Viewing all articles
Browse latest Browse all 69

XNA 4.0 HLSL – strange depth map

$
0
0

I want to draw my pre-rendered depth map to the scene.

I get my depth value in the following way:

basically (Pixel Shader)

// Depth is stored as distance from camera / far plane distance, 1-d for more precision
output.Depth = float4(1-(input.Depth.x / input.Depth.y),0,0,1);

where (Vertex Shader)

output.Position = mul(input.Position, worldViewProjection);
output.Depth.xy = output.Position.zw;

(input = output of Vertex Shader)

and store it in a RenderTarget2D

depthTarg = new RenderTarget2D(GraphicsDevice, viewWidth,
                viewHeight, false, SurfaceFormat.Single, DepthFormat.Depth24, samples, RenderTargetUsage.DiscardContents);

But somehow, when I draw that (Single), I get this result:
(displaying rgb)

enter image description here

channel r:

(all black)

channel g:

enter image description here

channel b:

enter image description here

channel a:

enter image description here

Why is there data in every color channel althrough i only defined a value on the red parameter (and 1 on a, but you can somehow see the outlines of the model, so it cant be all 1)

And surprisingly, the b channel looks almost like what I am looking for, but has strange lines in it which stay at the same distance to the camera if I move it.

enter image description here


Viewing all articles
Browse latest Browse all 69

Trending Articles