Polygon offset parameter

There are two parameters in polygon offset, m and r. m is said to be the greatest slope of z. The method that i do is:
for every triangle, there are three edges and for every edge there are two values dz/dx and dz/dy. Then there are six values, and m is the Max of them. Is that right?

But i don’t know how to get the value of r. Could anyone give me an example of the method to get r?

Thanks.

Well, I have found that the parameters that you put into glPolygonOffset are off the cuff, roll-the-dice see if it looks good type values. Play with it, see what works.

Originally posted by Poma:
There are two parameters in polygon offset, m and r. m is said to be the greatest slope of z. The method that i do is:
for every triangle, there are three edges and for every edge there are two values dz/dx and dz/dy. Then there are six values, and m is the Max of them. Is that right?

Actually no, m is defined as

m = sqrt((dz/dx)^2 + (dz/dy^2))

but can be approximated as

m ~= max(abs(dz/dx), abs(dz/dy))

You can calculate dz/dx annd dz/dy for a polygon as follows (considering x0-2, y0-2 and z0-2 the coords of the three vertices)

dz/dx = ((z1 - z0) * (y2 - y0) - (z2 - z0) * (y1 - y0)) / ((x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0))

dz/dy = ((z1 - z0) * (x2 - x0) - (z2 - z0) * (x1 - x0)) / ((x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0))

Basically those are the components of the gradient of z over the polygon.


But i don’t know how to get the value of r. Could anyone give me an example of the method to get r?

R depends on the precision of your rasterizer, you have to choose an appropriate value depending on your code.