I was making a small tool that converts a terrain mesh into a heightfield image, by making an orthogrpahic depth render from above.
Is it possible for the depth buffer to be linear instead of exponential? Or will I need to make a postprocessing pass (either GPU or CPU) that converts the depth values back into a linear range?
This entirely depends on your projection matrix, doesn’t it? I expect with an orthographic lens, the depth buffer range is linear.
Strictly, with a perspective lens, the depth buffer range isn’t exponential, it’s inverse linear, or 1/x. This looks a lot like exponential, though.
david’s right. this page gives the math behind it and tells you which elements of the projection matrix need massaging: http://www.mvps.org/directx/articles/using_w-buffers.htm
Make the output (post-divide) Z is linear. The easiest to do this is to just an orthographic projection matrix, where W is a constant.