Jump to content
  • Advertisement
Sign in to follow this  

Reconstruct position from log depth

This topic is 2261 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

Here how I'm applying the logarithmic depth in the vertex shader.
output.Position.z = log(output.Position.z / 0.001) / log(FarPlane / 0.001) * output.Position.w; //log(z/zn)/log(zf/zn)

Reconstructing in pixel shader. Not sure if i'm doing this correctly.

//read depth
float depthVal = DepthMap.Sample(depthSampler, texCoord).r;

//Compute screen-space position
float4 position = float4(input.ScreenPosition.xy, depthVal, 1.0f);
position.z = exp(depthVal * log(FarPlane / 0.001)) * 0.001; //(exp(z*log(zf/zn))*zn : z = depth value

//transform to world space
position = mul(position, InvertViewProjection);
position /= position.w; Edited by mgoss

Share this post

Link to post
Share on other sites
Thanks, but I haven't been able to solve the problem with this. I need the position reconstructed for my point lights.

I tried this. But it didn't work.

float z = DepthMap.Sample(depthSampler, input.ScreenPosition);
float x = input.ScreenPosition.x * 2 - 1;
float y = (1 - input.ScreenPosition.y) * 2 - 1;
float4 position = float4(x, y, z, 1.0f);
position.z = exp(z * log(FarPlane / 0.001)) * 0.001;

position = mul(position, InvertViewProjection);
position.xyz /= position.w;

Note: I'm using SlimDx if that matters. Edited by mgoss

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!