OpenGL Z-Biasing(多边形偏移)限制 [英] OpenGL Z-Biasing (Polygon Offset) Limitations

查看:21
本文介绍了OpenGL Z-Biasing(多边形偏移)限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个共面的多边形.

I have a two coplanar polygons.

我尝试过.

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

并期望一个明显在"另一个之上.

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

这种情况直到大约 70-75 个单位(近剪裁平面为 1,远剪裁平面为 10,000)为止.然后是大约 50 个单位的区域,其中有 z-fighting,然后交替的多边形似乎出现在顶部.

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.

多边形偏移量是在正常 z 计算之前还是之后添加的?如果是在之后,我会认为它在所有距离都有效".

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.

推荐答案

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

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.

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

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.

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

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.

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

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.

这篇关于OpenGL Z-Biasing(多边形偏移)限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆