Sign in to follow this  

About Reconstruct Pixel Position From Depth?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this