深度渲染伪影
我仅将场景深度渲染到不同的帧缓冲区,这个问题有点难以解释,但正如您在图像中看到的深度图一样,它实际上受到网格状伪影的影响。您知道这可能是什么原因吗?
这是创建 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题很可能来自于您的投影矩阵在近平面和远平面之间的分离太大(意味着靠近的像素正在遭受浮点精度问题)。缩小两架飞机之间的间隙,这应该可以解决你的 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.