Z-fighting解决方案在OpenGL中进行深度测试 - 它们是如何工作的? [英] Z-fighting solutions in depth test in OpenGL - how do they work?
问题描述
描述
我在OpenGL中遇到了Z-Fighting的主要问题,并且我花了相当多的时间为此寻找解决方案问题。一些我发现并理解并不喜欢的:
- 将多边形彼此移开(如OpenGL中的glPolygonOffset )
- 根据Z坐标分割场景,并使用单独的干净z缓冲区绘制场景的一部分。 $ b
那些我不明白的:
- 使用投影矩阵
https://software.intel.com/en-us/articles/使用对数深度缓冲区
$ a ://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and.html> http://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and。 HTML
- 使用投影矩阵
我在程序中实现了第二个,只是把它放到了一个球的顶点着色器中它与地面战斗):
b$ b
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;
并且工作正常!
实际问题
- 任何人都可以解释我怎么改变顶点着色器中顶点的Z坐标解决了这个问题将顶点明显移动到我身上? (场景看起来与人眼相同)。它是如何改变z深度值的分布的?我猜测我错过了关于渲染管道的一些知识。
- 任何人都可以向我解释我们如何使用投影矩阵来解决问题?它是如何工作的?
- 是否还有其他类似的有效方法来解决z战斗问题?
谢谢!
也许深度缓冲精度有问题吗?当使用16位缓冲区时,z战斗可能发生。您可以使用以下方式进行检查:
glGetIntegerv(GL_DEPTH_BITS,& depthBits);
Description
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:
- Moving polygons away from each other ( like glPolygonOffset in OpenGL )
- Dividing the scene according to Z coordinate and drawing parts of the scene with separate clean z-buffers.
The ones I don't understand:
- Using Projection Matrix https://software.intel.com/en-us/articles/alternatives-to-using-z-bias-to-fix-z-fighting-issues
- Using "Logarithmic Depth Buffers" http://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and.html
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!
Actual Questions
- Can anyone explain me how did changing the Z coordinate of the vertex in the vertex shader solved the problem WITHOUT moving the vertex visibly to me ? (the scene looks the same to the human eye). How did it change the distribution of the z-depth values ? I'm guessing i'm missing some knowledge about rendering pipeline.
- Can anyone explain to me how can we use Projection Matrix to fix the problem ? And how does it work?
- Are there any other similarly effective ways to fixing z-fighting problem?
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);
这篇关于Z-fighting解决方案在OpenGL中进行深度测试 - 它们是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!