Logarithmic depth: Why w + 1?

Hi.

I’m implementing the logarithmic depth buffer as described in:

But nowhere in any of the articles that preceded the final version does anyone say why they use 1.0 + gl_Position.w
and farplane + 1. Where does this + 1 term come from?

log(1) = 0, so it’s probably to shift all the depth values into non-negative values. Also, Z=0 without the +1 would result in a NAN or similar math error when you took the log.

Makes sense, thanks!