Jump to content
  • Advertisement
Sign in to follow this  
Martin Perry

Reconstruct position from depth

This topic is 2067 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 am trying to reconstruct position from depth in World Space (WS), but my code produce incorrect results.


So what I do:


1) Create depth map:

    for each vertex do:


viewPos = POSITION_WS * matrixView;

Depth = viewPos.z / farClipPlane;


2) Get corners of camera view frustrum in WS (cornerRayWS)

3) Use far plane corners and reconstruct depth for (x, y) -> <0,1>


cornerRayWS_interp = lerp(lerp(cornerRayWS[0], cornerRayWS[1], x),

                          lerp(cornerRayWS[2], cornerRayWS[3], x),



reconstructed_posWS = camera_pos_ws + Depth * cornerRayWS_interp;


But my results are incorrect. You can see input calc values for one camera position and view matrices in atached screen. From that I reconstruct position.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!