OpenGL Z-Biasing (Polygon Offset) Limitations

落花浮王杯 提交于 2019-12-06 08:15:54

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!