unity shader Offset Factor, Units詳解

來源:互聯網
上載者:User

標籤: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_FILLGL_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詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.