PDA

View Full Version : GL_POLYGON_SMOOTH and quads



Tokage
09-12-2006, 11:21 AM
I'm working on a game, and in it I enable GL_POLYGON_SMOOTH in order to make polygons look nicer. Unfortunately, it has a tendency to make my quads look like two right triangles. Like this: http://nicf.net/images/quad.jpg

Is there anything I can do to get rid of that irritating line down the middle?

plasmonster
09-12-2006, 01:25 PM
There's a discussion and demo of this in the online redbook (chapter 7).

Basically each polygon fragment gets its percentage of pixel coverage converted to alpha, which can then be used to blend the polygon with the contents of the framebuffer, which in turn makes the edges look smoother. The trouble is if 2 polys share a blended edge, and standard blending is used, then each edge will contribute some fraction of the background (say, black) to the result, leading to darkened lines. (Quads will actually be rasterized as 2 triangles with a shared edge.)

So for polygon smooth to work right, you need to have a destination alpha channel in your framebuffer, sort your polys front to back, and draw with glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE). This allows accumulation of alpha (with saturation) in the framebuffer while at the same time scaling subsequent color contributions to prevent artifacts. Even this isn't really foolproof.

For general purpose AA, consider using the multisample extension (if supported). It works great for the entire scene and without having to sort anything.

http://www.opengl.org/registry/specs/ARB/multisample.txt

Tokage
09-12-2006, 04:41 PM
Thanks, that helped a lot. My setup doesn't appear to support multisampling, but that modified alpha function works beautifully.

Serge K
09-13-2006, 11:35 AM
Just make sure that all primitives drawn with this blend function are sorted front to back.
Since it uses alpha channel to calculate uncovered part of the pixel, fully covered pixel will prevent sequential drawing in the same place.