   GLSL depth texture access
  I have bound a DEPTH_COMPONENT texture to an fbo(with CLAMP, CLAMP, NEAREST, NEAREST, TEXTURE_COMPARE_MODE=NONE, DEPTH_TEXTURE_MODE=LUMINANCE)Binding in GLSL as Sampler2D I am attempting to access the stored depth valuesI was not expecting the values to be linear, but was a little shocked to find that most values come in the range of 0.999 to 1.0Clearly I'm reading this wrongly. The sampling on it is very, very steepWhat's the correct procedure for extracting linear values from the depth texture component?Am I going about this totally the wrong way? Looking @ other examples on the net I see most people seem to be generating their own depth data instead (either in the depth channel, or on an extra colour attachment etc). Ideally I'd like to do this with fixed functionalityAny help would be very appreciatedCheers all   
  Try this:uniform vec2 CameraRange; // x is ZNear, y is ZFarfloat linearize_depth(in float depth){return (2.0 * CameraRange.x) / (CameraRange.y + CameraRange.x - depth * (CameraRange.y - CameraRange.x)); } ;  Wow. CheersI'll give that a shot when I get homeSo the zNear affects the depth gradient?I'll have to be more careful with my choice of scale from now onI was aware there were issues surrounding the use of particularily low zNear's, but never really understood why.Once again - thanks a load   ;  Yes, since the depth buffer samples depth values between near and far non-lineraly the choice of near and far (especially the far/near ratio) can heavily affect depth precision.Check this out, especially 12.050.   