Also, a common trick for visualizing a perspective depth buffer is to just ignore the range close to the near clip plane and then treat the remaining part as linear. Like this:

float zw = DepthBuffer[pixelPos]; float visualizedDepth = saturate(zw - 0.9f) * 10.0f;You can also compute the original view-space Z value from a depth buffer if you have the original projection matrix used for generating that depth buffer. If you take this and normalize to a [0,1] range use the near and far clip planes, then you get a nice linear value:

float zw = DepthBuffer[pixelPos]; float z = Projection._43 / (zw - Projection._33); float visualizedDepth = saturate((z - NearClip) / (FarClip - NearClip));