Allows you specify a depth offset with two parameters. factor and units. Factor scales the maximum Z slope, with respect to X or Y of the polygon, and units scale the minimum resolvable depth buffer value. This allows you to force one polygon to be drawn on top of another although they are actually in the same position. For example Offset 0, –1 pulls the polygon closer to the camera ignoring the polygon’s slope, whereas Offset –1, –1 will pull the polygon even closer when looking at a grazing angle.
基本等于没解释。
unity论坛上的解释:
https://forum.unity3d.com/threads/offset-parameters.23281/ 有:
Polygon offset allows the application to specify a depth offset with two parameters, factor and units. factor scales the maximum Z slope, with respect to X or Y of the polygon, and units scales the minimum resolvable depth buffer value. The results are summed to produce the depth offset. This offset is applied in screen space, typically with positive Z pointing into the screen.
The factor parameter is required to ensure correct results for filled primitives that are nearly edge-on to the viewer. In this case, the difference between Z values for the same pixel generated by two coplanar primitives can be as great as the maximum Z slope in X or Y. This Z slope will be large for nearly edge-on primitives, and almost non-existent for face-on primitives. The factor parameter lets you add this type of variable difference into the resulting depth offset.
A typical use might be to set factor and units to 1.0 to offset primitives into positive Z (into the screen) and enable polygon offset for fill mode. Two passes are then made, once with the model‘s solid geometry and once again with the line geometry. Nearly edge-on filled polygons are pushed substantially away from the eyepoint, to minimize interference with the line geometry, while nearly planar polygons are drawn at least one depth buffer unit behind the line geometry.
来自https://www.opengl.org/archives/resources/faq/technical/polygonoffset.htm
来自opengl的解释:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml或https://msdn.microsoft.com/en-us/library/windows/desktop/dd373973(v=vs.85).aspx提到:
When GL_POLYGON_OFFSET_FILL
, GL_POLYGON_OFFSET_LINE
, or GL_POLYGON_OFFSET_POINT
is enabled, each fragment‘s depth value will be offset after it is interpolated from the depth values of the appropriate vertices. The value of the offset is factor×DZ+r×unitsfactor×DZ+r×units, where DZDZ is a measurement of the change in depth relative to the screen area of the polygon, and rr is the smallest value that is guaranteed to produce a resolvable offset for a given implementation. The offset is added before the depth test is performed and before the value is written into the depth buffer.
glPolygonOffset
is useful for rendering hidden-line images, for applying decals to surfaces, and for rendering solids with highlighted edges.
有个blog关于这个的解释:
http://www.voidcn.com/blog/cubesky/article/p-6092419.html
http://kovax.blog18.fc2.com/blog-entry-50.html
每一个Fragment的深度值都会增加如下所示的偏移量:
offset = (m * factor) + (r * units)
m是多边形的深度的斜率(在光栅化阶段计算得出)中的最大值。这句话难以理解,你只需知道,一个多边形越是与近裁剪面(near clipping plan)平行,m就越接近0。
r是能产生在窗口坐标系的深度值中可分辨的差异的最小值,r是由具体实现OpenGL的平台指定的一个常量。
一个大于0的offset 会把模型推到离你(摄像机)更远一点的位置,相应地,一个小于0的offset 会把模型拉近。
http://miffysora.wikidot.com/glpolygonoffset终于,这里有讲一点关于m是怎么计算的了。不过貌似有点错误
然后查到:http://www.glprogramming.com/red/chapter06.html#name4
然后继续查: https://www.inf.ufes.br/~thomas/graphics/OpenGL/docs/glspec1.1/node58.html