Jump to content
  • Advertisement
Sign in to follow this  

[RenderMonkey] Position from DepthMap

This topic is 2650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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 )

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;


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.

Share this post

Link to post
Share on other sites
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 :(

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!