# Obtain linear depth values on FBO and deal with small differences

I've a render target on which I have both a color and a depth attachment. In a second pass I need to run a filter whose width depends on the derivative and values of the depth.

Now, if I try, in the second pass where I'm accessing the texture on which I rendered on previously, to display the depth information all I have is a grey blotch:

http://imgur.com/UFm5oI6 (Don't pay attention to background, I'm showing just non-background values)

Before displaying it I modify it by:

float depthValue = texture(depthTexture, uv);
depthValue =(depthValue - 0.1)/0.9;


as my near clip is 0.1 and far one is 1.0

Instead, if I run the program with gDEBugger and look at the content of the depth texture what I see is a much cleaner result:

http://imgur.com/TtOgMY2

Why what I see is totally different? How gDEBugger show the values? Are the value I fetch from the depth texture wrong? Should I render depth values differently?

Moreover, the width of the kernel doesn't really change as it is computed based on depth value and depth derivatives and those two are practically identical, at least judging from what I see. Is there a way to make these differences more marked?

Sorry if it's a dumb question. Thank you.

You are aware that when you sample the depth buffer, what is returned is in window-space, right?

That is the final coordinate space OpenGL transforms into. After projection, GL applies the viewport transformation from NDC -> window-space, part of which includes depth range. Traditionally, window-space Z is clamped [0,1] and the full range is used; thus 0 is the nearest point and 1 is the farthest.

Your discussion of the near plane at 0.1 and far plane at 1.0 leads me to believe you are discussing a different coordinate space (for instance, if you defined those values in your projection matrix then they are measured in eye-space). In window-space, given the default depth range your near plane is actually 0.

• Yes, when I generated the depth texture I did have zNear and zFar inside the projection matrix. Because I need linear value then I tried to get to the original values as I need (I understand the above is the wrong thing, should be this link, right? In any case for visualization I keep using the window-space ones I still get the same grey blotch and not even close to what I see in the texture via gDEBugger, no differences are appreciable. What can be the issue? – user48448 Jun 22 '14 at 17:04