1

I would like, for example, to stack two cubes A and B. The matter is that the top face of A is at the exact same position of B's bottom face.

This render some visual glitches as you can see : enter image description here

Note that the pink grid can sometime be seen through any cube at some angle as well (not expected).

Is there any way to fix this without offsetting all my objects ?

4

1 回答 1

5

这称为深度战斗Z-Fighting,其原因是,在投影后深度值会进行四舍五入,并且当深度测试发生时,深度测试的获胜者取决于参与片段的深度值的四舍五入。

有没有办法在不抵消我所有的对象的情况下解决这个问题?

是的,有一些技术使用模板缓冲区,但需要注意的是,它仅适用于凸几何。首先,您使用深度测试和深度写入渲染重叠对象,但没有颜色写入,设置模板蒙版。下一次迭代,您启用背面剔除并在禁用深度测试、启用模板测试(传递使用的模板值)和启用颜色写入的情况下进行绘制。在模板蒙版区域内,根据 Painter 的算法,事物将过度绘制(即,图层按照绘制时的顺序排列)。

于 2013-06-26T18:52:13.007 回答