Jump to content
  • Advertisement
Sign in to follow this  

About Reconstruct Pixel Position From Depth?

This topic is 3092 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 read some article about this topic. But i found that they all render a quad(two triangles) in final pass, perhaps, that's deferred rendering? But, i usally render all scene primitives in final pass(example SSAO pass). I want to reconstruct pixel's view space position as below. Is this correct? In application, I render all scene primitives by calling DrawIndexedPrimitive. //------------------------------------------------------------------------- In Vertex Shader, I calculate: float4 oPos_ProjSpace:TEXCOORD1 //that's vertex position in projection space. float4 oPos_ViewSpace:TEXCOORD2 //that's vertex position in view space. oPos_ProjSpace = mul(float4(iPos_ModelSpace), matWVP); oPos_ViewSpace = mul(float4(iPos_ModelSpace), matWV); //------------------------------------------------------------------------- Then, In Pixel Shader. I use oPos_ProjSpace to calcuate the Texture coordinate(Textrue is Linear Depth Render Target. Value = .z/fFarZ), and use it to sample Linear Depth Render Target to get Depth. //ProjS=>NDC=>Texcoord oPos_ProjS /= oPos_ProjS.w; float2 Texcoord = (oPos_ProjS.xy + 1.0f) * 0.5f; Texcoord.y = 1.0f - Texcoord.y; fDepth = tex2D(smpLinearDepth, Texcoord).r; I use oPos_ViewSpace and fDepth*fFarZ to combinate pixel's view space position. oPos_ViewSpace.z = fDepth*fFarZ. Then the oPos_ViewSpace is the pixel's View space position. //-------------------------------------------------------------------------- I want to know is it correct? Thanks all!

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!