2

Lets say I've implemented in openGL a crude model viewer with shading which renders a series of blocks, such that I have something that looks like this.

http://i.imgur.com/TsF7K.jpg

Whenever I rotate my model to the side, it causes an unwanted jagged effect along any surface with a steep viewing angle.

http://i.imgur.com/Bgl9o.jpg

I'm pretty sure this is due to the polygon offset I used to prevent z-fighting between the model and the wireframe, however I'm not able to find the factor/unit parameters in openGL which prevent this unwanted effect.

  1. what are the best values of factor and unit for glPolygonOffset to prevent this?

  2. would implementing anti-aliasing alleviate the problem? is the trade off in performance trivial/significant?

  3. is this perhaps a shading issue? should i try a solution along this line of thought?

4

2 回答 2

3

对我来说,这看起来不像是Z战斗..

如果您正在绘制平面阴影对象,然后在其上绘制一些 GL_LINES,这些线条将产生这种效果,因为它们没有抗锯齿。

为什么不在对象上应用网格纹理?这样您就可以利用 OpenGL 的纹理过滤。您可以尝试:

  • 在此纹理上启用 MIN_ 和 MAG_ 过滤。
  • 使用 gluBuild2DMipmaps 使用 mipmaps 创建纹理。(请参阅生成 Mipmaps
  • 启用各向异性过滤?(见此
于 2010-04-11T17:42:04.487 回答
1

您可能会在陡峭的角度(即当所有点具有非常相似的 z 值时)发生 z-fighting,因为
1)您的 z-buffer 分辨率太低,即您设置了 16 位 z 缓冲区 - 尝试将分辨率更改为 32 位
2) 您的模型非常小,即您的所有点都靠得太近了。您可以尝试放大模型。

使用固定偏移会产生不一致的结果,因为大多数 z 缓冲区方案偏向于提供更高分辨率,越接近近裁剪平面,即越靠近近裁剪平面,您需要的偏移越小。

这是一篇gamedev文章,更深入地讨论了这个问题

请注意,抗锯齿和更改着色器在这里不太可能有太大帮助(除非你做了一些时髦的自定义像素着色器来调节 z 值,但这对我来说似乎有点过头了,尽管我不是像素/片段着色器方面的专家,所以它可能可行)

于 2010-04-10T11:55:27.313 回答