# Difference between linear and logarithmic z-buffer

I've searched about this topic for awhile and i couldn't find it on google. I've come across several ways to avoid z-fighting which are linear z-buffer, logarithmic z-buffer and reversed z-buffer. I decided to leave reversed z-buffer for now as i'm not planning to use OpenGL 4.5. The thing is i don't know the difference between linear and logarithmic z-buffer.

By "linear" i mean this:

float fz = gl_Position.z * gl_Position.w;
gl_Position.z = (fz - near) * 2.0 / (far - near) - 1.0;


And by "logarithmic" i mean this:

float w = gl_Position[3];
float C = 0.001;
gl_Position.z = (2 * log(C * w + 1) / log(C * far + 1) - 1) * w;


If i understand those codes correctly, the linear try to map all of the z value evenly. So does the logarithmic one. Sure both of them are totally different but i have tried both and see no or if any minimal differences, both eliminate the z-fighting. So there must be something i missed or don't understand.

edit: As Jimmy said, logarithmic is better than linear. Please add why logarithmic is better than linear z-buffer as i want to know why it is better and not just which one is better.

• naive Z < linear Z < log Z in terms of consistency of number of depth bits available at all levels. If linear Z is enough to eliminate-fighting for you, it's probably faster to use that than to use log Z. Nov 1, 2017 at 18:13