標籤:useful 等於 prim rect 指定 錯誤 vax actually thread
很久之前查到的各種關於offset的資料,今天群裡面又有人問到,我乾脆發上來,再有人問我就直接貼地址了!unity文檔上的解釋:https://docs.unity3d.com/Manual/SL-CullAndDepth.html
Offset Factor, Units
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.htmlhttp://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
unity shader Offset Factor, Units詳解