I've had major problems with Z-Fighting in OpenGL and I've spent quite some time finding solutions for this problem. Some of the ones I've found and I understand and didn't like:
The ones I don't understand:
I've implemented the second one in my program by just puting this into the vertex shader of a ball (it z-fought with the ground) :
float C = 1.0;
float far = 2000.0;
gl_Position = u_projView * a_position;
gl_Position.z = 2.0*log(gl_Position.w*C + 1.0)/log(far*C + 1.0) - 1.0;
gl_Position.z *= gl_Position.w;
and it worked!
Thanks!
Maybe there's a problem with depth buffer precision? When using 16-bit buffer, z-fighting is likely to happen. You can check it using:
glGetIntegerv( GL_DEPTH_BITS, &depthBits);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With