Meaning and usage of the factor parameter in glPolygonOffset
Asked Answered
G

1

14

I am having difficulty understanding the meaning of the first parameter in glPolygonOffset function.

void glPolygonOffset(GLfloat  factor, GLfloat units);

The official documentation says that factor

Specifies a scale factor that is used to create a variable depth offset for each polygon.

and that

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 × units , where DZ is a measurement of the change in depth relative to the screen area of the polygon, and r is the smallest value that is guaranteed to produce a resolvable offset for a given implementation.

I understand what r and unit are. What I don't understand is what DZ is, i.e. what is meant by the "measurement of the change in depth value to the screen area of the polygon" and why would I ever need to set factor to anything other than 0.

If i want my wireframe to be offset all I need is to add/substact a couple of units to/from the depth value, don't I? What's the meaning, purpose and usage example of the factor parameter (and the DZ mentioned in the document)?

Glossography answered 17/11, 2012 at 13:47 Comment(0)
M
20

I have to admit some ignorance here, but I found this article which explains it. They say:

To achieve a nice rendering of the highlighted solid object without visual artifacts, you can either add a positive offset to the solid object (push it away from you) or a negative offset to the wireframe (pull it towards you). The big question is: "How much offset is enough?" Unfortunately, the offset required depends upon various factors, including the depth slope of each polygon and the width of the lines in the wireframe.

They then explain the depth slope this way:

The depth slope is the change in z (depth) values divided by the change in either x or y coordinates, as you traverse a polygon. The depth values are in window coordinates, clamped to the range [0, 1]. To estimate the maximum depth slope of a polygon (m in the offset equation), use this formula: m = max {|delV / delS|,|delV / delT|}. (where del is a partial derivative)

So they conclude that:

For polygons that are parallel to the near and far clipping planes, the depth slope is zero. [...] For polygons that are at a great angle to the clipping planes, the depth slope can be significantly greater than zero, and a larger offset may be needed. Small, non-zero values for factor, such as 0.75 or 1.0, are probably enough to generate distinct depth values and eliminate the unpleasant visual artifacts.

Meridional answered 17/11, 2012 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.