Keith Z. Leonard

07-06-2008, 11:14 PM

There has been a good bit of discussion about this lately, and it's been very helpful. I am trying to compute EyeZ from a Z buffer read. This is the math that I am using.

vec2 DepthParameter;

DepthParameter.x = FARZ * ONE_OVER_FAR_MINUS_NEAR;

DepthParameter.y = FARZ * NEARZ * ONE_OVER_NEAR_MINUS_FAR;

float EyeZ = -DepthParameter.y / ( DepthParameter.x - TextureDepth.r );

If I output the following, I see what I would expect. Black to white depth.

float ColorZ = EyeZ / (FARZ - NEARZ);

gl_FragColor = vec4(ColorZ, ColorZ, ColorZ, 1.0);

I then try and use this for edge detection, I sample adjacent depths,and if the difference in depth is greater than some value, It's a silhouette edge.

My issue is that my EyeZ doesn't seem to be linear. So the difference scales as it gets farther away from the near clipping plane. Any thoughts?

Thanks,

vec2 DepthParameter;

DepthParameter.x = FARZ * ONE_OVER_FAR_MINUS_NEAR;

DepthParameter.y = FARZ * NEARZ * ONE_OVER_NEAR_MINUS_FAR;

float EyeZ = -DepthParameter.y / ( DepthParameter.x - TextureDepth.r );

If I output the following, I see what I would expect. Black to white depth.

float ColorZ = EyeZ / (FARZ - NEARZ);

gl_FragColor = vec4(ColorZ, ColorZ, ColorZ, 1.0);

I then try and use this for edge detection, I sample adjacent depths,and if the difference in depth is greater than some value, It's a silhouette edge.

My issue is that my EyeZ doesn't seem to be linear. So the difference scales as it gets farther away from the near clipping plane. Any thoughts?

Thanks,