Reconstruct position from log depth

Started by
2 comments, last by mgoss 11 years, 9 months ago
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;
Advertisement
http://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/
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.
I hope this makes sense to anyone know what I'm talking about.

This topic is closed to new replies.

Advertisement