Z-fighting解决方案在OpenGL中进行深度测试 - 它们是如何工作的? [英] Z-fighting solutions in depth test in OpenGL - how do they work?

查看:495
本文介绍了Z-fighting解决方案在OpenGL中进行深度测试 - 它们是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

描述



我在OpenGL中遇到了Z-Fighting的主要问题,并且我花了相当多的时间为此寻找解决方案问题。一些我发现并理解并不喜欢的:


  • 将多边形彼此移开(如OpenGL中的glPolygonOffset )

  • 根据Z坐标分割场景,并使用单独的干净z缓冲区绘制场景的一部分。 $ b

    那些我不明白的:



    我在程序中实现了第二个,只是把它放到了一个球的顶点着色器中它与地面战斗):

    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;

    并且工作正常!

    实际问题




    1. 任何人都可以解释我怎么改变顶点着色器中顶点的Z坐标解决了这个问题将顶点明显移动到我身上? (场景看起来与人眼相同)。它是如何改变z深度值的分布的?我猜测我错过了关于渲染管道的一些知识。

    2. 任何人都可以向我解释我们如何使用投影矩阵来解决问题?它是如何工作的?

    3. 是否还有其他类似的有效方法来解决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:

    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

    1. 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.
    2. Can anyone explain to me how can we use Projection Matrix to fix the problem ? And how does it work?
    3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆