title: Linear Depth to World Position
body: <p>I have the following fragment and vertex shaders.</p>
  
  <p>HLSL code 
  `
  // Vertex shader 
  //----------------------------------------------------------------------------------- </p>
  
  <pre><code>void mainVP( 
     float4 position     : POSITION, 
     out float4 outPos   : POSITION, 
     out float2 outDepth : TEXCOORD0, 
     uniform float4x4 worldViewProj,
     uniform float4 texelOffsets,
     uniform float4 depthRange)   //Passed as float4(minDepth, maxDepth,depthRange,1 / depthRange)
  { 
      outPos = mul(worldViewProj, position);
      outPos.xy += texelOffsets.zw * outPos.w;
      outDepth.x = (outPos.z - depthRange.x)*depthRange.w;//value [0..1]
      outDepth.y = outPos.w; 
  } 
  
  // Fragment shader  
  void mainFP( float2 depth: TEXCOORD0, out float4 result : COLOR) { 
      float finalDepth = depth.x;
      result = float4(finalDepth, finalDepth, finalDepth, 1);
  }
  </code></pre>
  
  <p>`</p>
  
  <p>This shader produces a depth map. </p>
  
  <p>This depth map must then be used to reconstruct the world positions for the depth values. I have searched other posts but none of them seem to store the depth using the same formula I am using. The only similar post is the following 
  <a href="https://stackoverflow.com/questions/28066906/reconstructing-world-position-from-linear-depth">Reconstructing world position from linear depth</a></p>
  
  <p>Therefore, I am having a hard time reconstructing the point using the x and y coordinates from the depth map and the corresponding depth.</p>
  
  <p>I need some help in constructing the shader to get the world view position for a depth at particular texture coordinates.</p>