[RenderMonkey] Position from DepthMap

Started by
0 comments, last by wh1sp3rik 12 years, 8 months ago
Hello,

I have problems to get position from depth map.
my code:

VS: ( this code is generated by RenderMonkey for Quad )


struct VS_OUTPUT
{
float4 pos : POSITION0;
float2 texCoord : TEXCOORD0;
};

VS_OUTPUT vs_main( float4 inPos: POSITION )
{
VS_OUTPUT o = (VS_OUTPUT) 0;

inPos.xy = sign( inPos.xy);
o.pos = float4( inPos.xy, 0.0f, 1.0f);

// get into range [0,1]
o.texCoord = (float2(o.pos.x, -o.pos.y) + 1.0f)/2.0f;
return o;
}


PS:


sampler2D DepthMap;
float4x4 matViewProjectionInverse;


float4 ps_main( float2 texCoord : TEXCOORD0 ) : COLOR
{
float2 ScreenPos = texCoord;

ScreenPos.x = (ScreenPos.x*2.0)-1.0f;
ScreenPos.y = (ScreenPos.y*2.0)-1.0f;
float4 Screen3DPos = float4(ScreenPos.x,ScreenPos.y, tex2D( DepthMap, texCoord ).x ,1.0f );

Screen3DPos = mul( Screen3DPos, matViewProjectionInverse );
Screen3DPos /= Screen3DPos.w;
Screen3DPos.w = 1.0f;

return Screen3DPos;
}


So, what i am doing there. I get Screen position in range -1 to 1 with depth of z.
I multiply it with Inverse of ViewProjection matrix to get World matrix. I divided result with w and display position as color.

Color looks ok, but when rotating with objects, color are changing, strange.

Where is a problem ? thank you very much.


DirectX 11, C++

Advertisement
ha, few hours of thinking ...


i found a problem (i hope )


float4 Screen3DPos = float4(ScreenPos.x, -ScreenPos.y, depth ,1.0f ); i forgot minus sign on Y axis :(

DirectX 11, C++

This topic is closed to new replies.

Advertisement