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),
y);
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.