Skip to main content
Tweeted twitter.com/StackGameDev/status/1115811753877757952
Bumped by Community user
Bumped by Community user
added 188 characters in body
Source Link
Greffin28
  • 1k
  • 1
  • 9
  • 20

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.

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.

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.

Source Link
Greffin28
  • 1k
  • 1
  • 9
  • 20

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.