为什么我在使用 gl.polygonOffset 时需要因子?

why do i need factor when using gl.polygonOffset?

我不明白 polygonOffset 如何使用 WebGL。我经常发现自己在试验 factorunits 参数。

我认为我得到了更一致的结果:

gl_Position.z += someEpsilon;

我知道文档中提到了一个导数,它似乎确实根据三角形的角度表现不同。

为什么我不能以某种方式将深度值增加一些单位,一个单位是深度缓冲区可以容纳的最小数量?

Why can't I just somehow increment the depth value by some number of units, a single unit being the smallest number the depth buffer can hold?

好吧,你可以。根据OpenGL ES 2.0 specification, section 3.5.2 "Depth Offset", page 59的等式(3.8),应用的多边形偏移o为:

o = m ∗ factor + r ∗ units

其中

The minimum resolvable difference r is an implementation-dependent constant. It is the smallest difference in window coordinate z values that is guaranteed to remain distinct throughout polygon rasterization and in the depth buffer.

因此,如果您希望 o 保持不变,只需将 factor 设置为零,并为 units 使用一些适当的值,即 1.0.