深度渲染伪影

发布于 2024-10-06 09:06:50 字数 982 浏览 1 评论 0原文

我仅将场景深度渲染到不同的帧缓冲区,这个问题有点难以解释,但正如您在图像中看到的深度图一样,它实际上受到网格状伪影的影响。您知道这可能是什么原因吗?

这是创建 fb 的代码:

    self.shadowTexture = glGenTextures(1);        
    glBindTexture( GL_TEXTURE_2D, self.shadowTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, None);

    glBindTexture( GL_TEXTURE_2D, 0);
    self.fbo = glGenFramebuffers(1)
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, self.fbo)
    glDrawBuffer(GL_NONE);
    glReadBuffer(GL_NONE);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D, self.shadowTexture, 0);

alt text

I am depth only rendering scene to different frame buffer, the problem is a bit hard to explain but as you can see in the image the depth map it is actually suffering from grid like artifacts. Do you have any idea what can be the source of this ?

here is the code for fb creation:

    self.shadowTexture = glGenTextures(1);        
    glBindTexture( GL_TEXTURE_2D, self.shadowTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, None);

    glBindTexture( GL_TEXTURE_2D, 0);
    self.fbo = glGenFramebuffers(1)
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, self.fbo)
    glDrawBuffer(GL_NONE);
    glReadBuffer(GL_NONE);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D, self.shadowTexture, 0);

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2024-10-13 09:06:50

您的问题很可能来自于您的投影矩阵在近平面和远平面之间的分离太大(意味着靠近的像素正在遭受浮点精度问题)。缩小两架飞机之间的间隙,这应该可以解决你的 Z-fight 问题。

Your problem most likely comes from the fact that your projection matrix has too much seperation between near and far planes (meaning close together pixels are suffering floating point accuracy issues). Shrink the gap between the 2 planes and that should solve your Z-fighting issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文