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

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

问题描述

我有两个共面的多边形。

我想这样做。

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

和预期一待明显之上的其它

这是直到约70-75单位远(为1的近裁剪平面和10000远裁剪面)的情况下。然后,约50单位的区域有z轴战斗,然后交替多边形似乎出现在顶部。

是否多边形偏移获得前或普通Z计算后添加?如果是后,我会想到它会只是工作在所有距离。

我使用了错误的值?我误解了预期的效果?还是要这样的工作,我可能做错了什么别的地方?

我是不敢尝试更大的值,因为在场景中的其他对象,如果数量足够大,他们在这些面前可以跳过对象,在远的距离。

解决方案

我没有用 glPolygonOffset ,但我只是读了它在的官方FAQ - 必读如果你还没有已经看到了这一点。此外还有手册页

根据该基准,偏移计算的的所述普通的零的计算,但施加的的深度测试和被写入深度缓冲器之前。

我能想到的两个问题。首先,常见问题解答建议您使用 glPolygonOffset(1,1),不是(0,1)。第一个因子参数是由多边形的斜率相乘,加到偏移。这是边缘的多边形显然是非常重要的。如果多边形面向相机,也没关系,但如果是在一个角度,该量需要将它推进着的角度增大。

其次,是你使的偏移多边形只有一个?如果您有它启用了两个(或者忘记将其禁用),那么它将适用于多边形和具有零净效应。

第三,我怀疑你的深度缓冲器过大(给定的该深度缓冲器有一个双曲线规模其附近有利于对象到摄像头)。我不敢肯定这一点,因为 glPolygonOffset 应该与深度值来工作的,不是Z值(所以深度缓冲的规模不应该是一个因素这里)。你可能想用更短的深度缓冲(也许1000)尝试一下,看看是否有差别。

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.

解决方案

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.

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

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