Question

I am doing shadow mapping using OpenGL. There is a z-fighting problem when comparing the depth with the shadow map. I can solve the problem using glPolygonOffset. I know this function helps push(or pull) the polygon a little bit so that the z-fighting problem is solved. But I have a question about the function glPolygonOffset. I do not know clearly why the slope of the polygon is related to the offset.

From here:

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.

Here I do not know why "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."

Was it helpful?

Solution

If the polygons have Z slope, then there's a difference in the z-coordinate between the left and right edge of the pixel.

So to put something in front, you have to make sure that it's in front no matter where in the pixel the z-coordinate is calculated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top