• Advertisement
Sign in to follow this  

calculate eye-space position from depth

This topic is 2769 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 don't understand the following function:

// calculate eye-space position from depth
float3 posEye = uvToEye(texCoord, depth);
// calculate differences
float3 ddx = getEyePos(depthTex, texCoord + float2(texelSize, 0)) -posEye;
float3 ddx2 = posEye -getEyePos(depthTex, texCoord + vec2(-texelSize, 0));
if (abs(ddx.z) > abs(ddx2.z)) {
ddx = ddx2;
}

how to get eye-space position from depth?

Share this post


Link to post
Share on other sites
Advertisement
Are you asking how uvToEye works in that snippet? Assuming texCoord is the screen-space coordinate of the current pixel, then the function could work like this:

// fetch depth value for current pixel
float depth = tex2D( depthTex, texCoord ).r;

// convert texture coordinate to homogeneous space
float2 xyPos = texCoord * 2.0 - 1.0;

// construct clip-space position
float4 clipPos = float4( xyPos, depth, 1.0 );

// transform from clip space to view (eye) space
// NOTE: this assumes that you've precomputed the
// inverse of the view->clip transform matrix and
// provided it to the shader as a constant.
float4 viewPos = mul( clipPos, c_invViewClipTransform );

// Make the position homogeneous and return
return viewPos.xyz / viewPos.w;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement