# Reconstruct position from log depth

This topic is 2337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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.

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 on other sites
http://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/

##### 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 on other sites
I hope this makes sense to anyone know what I'm talking about.

1. 1
2. 2
Rutin
23
3. 3
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013158
×