OpenGL Z 偏置(多边形偏移)限制

发布于 2024-10-26 14:35:33 字数 413 浏览 5 评论 0原文

我有两个共面的多边形。

我尝试做。

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0,1);

并期望其中一个明显“位于”另一个之上。

这种情况直到大约 70-75 个单位之外(近剪裁平面为 1,远剪裁平面为 10,000)。然后是大约 50 个单位的区域,其中存在 Z 战斗,然后替代多边形似乎出现在顶部。

多边形偏移是在正常 z 计算之前还是之后添加的?如果是在之后,我会认为它在所有距离上都会“正常工作”。

我使用了错误的价值观吗?我是否误解了预期结果?或者这应该有效,而我可能在其他地方做错了什么?

我不敢尝试更大的值,因为场景中还有其他对象,如果数量足够大,它们也可以在很远的距离“跳”到这些对象前面。

I have a two coplanar polygons.

I tried doing.

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0,1);

and expected one to be distinctly "on top of" the other.

This is the case until about 70-75 units away (with a near clipping plane of 1, and a far clipping plane of 10,000). Then a region of about 50 units where there is z-fighting, and then the alternate polygon seems to appear on top.

Does the Polygon Offset get added before or after the normal z-calculations? If it was after, I would have thought it would have "just worked" at all distances.

Am I using the wrong values? Am I misunderstanding the expected results? Or should this work, and I am probably doing something wrong elsewhere?

I was afraid to try larger values, because there are other objects in the scene, and if the number was large enough, they could "jump" in front of those object too at far distances.

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

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

发布评论

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

评论(2

幼儿园老大 2024-11-02 14:35:33

我没有使用过glPolygonOffset,但我只是在官方常见问题解答——如果您还没有看过这篇文章,请务必阅读。还有手册页

根据该参考文献,偏移量是在正常 Z 计算之后计算的,但在深度测试之前以及写入深度缓冲区之前应用。

我能想到两个问题。首先,FAQ 建议您使用 glPolygonOffset(1,1),而不是 (0,1)。第一个“因子”参数乘以多边形的斜率并添加到偏移量。这对于“边缘”多边形显然很重要。如果多边形面向相机,则没关系,但如果它成一定角度,则需要将其向前推动的量随着角度的增加而增加。

其次,您是否仅启用其中一个多边形的偏移?如果您为两者启用了它(或忘记禁用它),那么它将应用于两个多边形,并且净效果为零。

第三,我怀疑您的深度缓冲区太大(鉴于深度缓冲区具有双曲线尺度,有利于靠近相机的物体)。我对此不太确定,因为 glPolygonOffset 应该使用深度值,而不是 Z 值(因此深度缓冲区的比例不应该成为这里的一个因素)。您可能想尝试使用更短的深度缓冲区(可能是 1000),看看是否会产生影响。

I haven't used glPolygonOffset, but I just read up on it in the official FAQ -- required reading if you haven't already seen this. There is also the man page.

According to that reference, the offset is calculated after the normal Z calculations, but applied before the depth test and before being written to the depth buffer.

I can think of two issues. Firstly, the FAQ recommends you use glPolygonOffset(1,1), not (0,1). The first "factor" argument is multiplied by the slope of the polygon and added to the offset. This is apparently important for "edge-on" polygons. If the polygon is facing the camera, it doesn't matter, but if it is at an angle, the amount you need to push it forward increases with the angle.

Secondly, are you enabling the offset for just one of the polygons? If you have it enabled for both (or forget to disable it), then it will apply to both polygons, and have a net effect of zero.

Thirdly, I suspected that your depth buffer is too large (given that depth buffers have a hyperbolic scale which favours objects close to the camera). I'm not so sure about this, given that glPolygonOffset is supposed to work with depth values, not Z values (so the scale of the depth buffer shouldn't be a factor here). You might want to try it with a shorter depth buffer (maybe 1000) and see if that makes a difference.

第七度阳光i 2024-11-02 14:35:33

您可以尝试将一个多边形偏移设置为正,将一个偏移设置为负,我敢打赌这会起作用。

glPolygonOffset(0,1) 和 glPolygonOffset(0,-1)

You can try to set one polygon offset positive one offset negative, I bet that will work.

glPolygonOffset(0,1) and glPolygonOffset(0,-1)

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