PDA

View Full Version : Polygon offset fails at short distance



Pirracas
11-13-2007, 12:05 PM
I am implementing hidden line removal as explained in chapter 14 of the red book Hidden-Line Removal with Polygon Offset (http://www.glprogramming.com/red/chapter14.html#name16)

I have a moving camera. Initially it works fine, but when I move the camera so the object is closer to it, it starts to behave very strange, with even some polygons and lines start to dissapear or have artifacts (the near clipping plane is okay, because when I disable the polygon offset everything is alright).

Do you have an idea of what can be wrong?
Maybe it has to be with this comment at the end of the polygon offset chapter:

Also, since depth values are unevenly transformed into window coordinates when using perspective projection (see "The Transformed Depth Coordinate" in Chapter 3), less offset is needed for polygons that are closer to the near clipping plane, and more offset is needed for polygons that are further away.
but I don't know very well how to fix that.

dorbie
11-14-2007, 09:47 PM
The hardware may have some kind of optimized z storage that spends precision differently, or it may simply be a bug.

Nearer the eye the framebuffer has more precision but other issues can start to kick in, for example clipping might introduce another interpolation path or there may be a lack of vertex or interpolator precision that becomes apparent.

(1.0, 1.0) technically should work but it's skating a bit close to the edge. You could comfortably increase that without too many ill effects.

Within conformance OpenGL implementations have a lot of lattitude w.r.t. issues like the internals of the depthbuffer scheme or interpolation, and the polygon offset conformance test is particularly weak.

Pirracas
11-15-2007, 09:38 AM
Thanks a lot for your help.
I tried with several values but didn't have any luck. It changed the point were it started to look bad but it didn't work perfectly.

Finally I have decided to use the glDepthRange() method instead.

dorbie
11-17-2007, 12:07 AM
An alternative is to adjust the frustum near & far values (scaling TBLR appropriately).

There is one other factor to consider, on some hardware (and it's increasingly rare) z invariance is not guaranteed if you fill with different state. So for exampel is you turn texture or lighting or any of a number of features off between passes the zbuffer will produce inaccurate results. Now this SHOULD only ammount to rounding errors which offset could fix, but it may be a factor for you.

I'd say the OpenGL you are using has a poor implementation of polygonoffset.