PDA

View Full Version : Logarithmic depth: Why w + 1?



raga34
01-08-2015, 11:18 AM
Hi.

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

http://outerra.blogspot.co.uk/2013/07/logarithmic-depth-buffer-optimizations.html

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?

malexander
01-08-2015, 12:31 PM
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.

raga34
01-08-2015, 01:26 PM
Makes sense, thanks!