View Full Version : polygon smoothing
skyhawk
2003.09.30, 06:07 PM
okay, clear cut, I want polygon smoothing for this silly project we have in ICG. apparently just enabling GL_POLYGON_SMOOTH didn't do it.
any ideas? I don't think "sorting" would be neccessary since they are all on the same plane. but if sorting is mandatory, how would I got about doing it?
MacFiend
2003.09.30, 06:24 PM
I vaguely remember something about blending being needed for smoothing. Maybe thats just for smooth points though.
OneSadCookie
2003.09.30, 06:26 PM
You might try inio's idea... sorting the polygons and drawing antialiased lines around the polygon edges.
If speed isn't an issue, GL_POLYGON_SMOOTH is your easiest answer probably. it works something like this:
1. allocate a GL context with an alpha buffer. The cheesy 1-bit alpha buffer you get by default with 1555 contexts won't cut it, you need a full 8-bit alpha buffer. You don't need a z-buffer though.
2. clear the color and alpha buffers to 0 before each frame (mandatory)
3. Disable all z-buffer
4. glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE)
5. draw polygons in order front to back.
Now, my method works more like this. This write-up assumes one texture per object. You'll need to slice up the loop at the end to switch textures. Also, this was written in about 15 minutes and not significantly proofread beyond looking for inappropriate red dotted underlines; If something doesn't make sense, it was probably a typo/thinko so please point it out:
1. Generate topology graphs for your models storing edge-poly connectivity and edge convexness. Also store whether the edge should be smoothed even if both polygons are visible (texture seams, color breaks, etc).
2. Allocate a GL context like normal.
3. Before drawing, for each world object you want anti-aliasing on, determine back-facing polygons on your own and from that store the following lists of edges with a front-facing tri that's attached to that edge:
a. Convex Silhouette edges (edges where exactly one connected tri is hidden).
b. Aforementioned "overlay" edges where both adjacent triangles are visible.
4. Draw the scene as normal.
5. Set the polygon mode to GL_LINE, GL_LINE_SMOOTH, and set the blend func to (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
6. Now, go through the list of objects you want smoothing on, and perform the following steps:
a. set glDepthOffset to push geometry away from the camera just a bit to hide the inside edge of the lines we're gonna draw
b. enable any arrays you need for drawing your object, and GL_EDGE_FLAG_ARRAY.
c. load up the arrays with the vertex position/color/normal/texture coord/vertex color of the polygons you recorded earlier as being attached to a silhouette edge
d. load up the edge flag array so that only the silhouette/overlay edges get drawn
e. call glDrawElements
Now, if you don't mind a little bit of almost-invisible z-fighting and don't need overlay edges, you can skip all of the complex parts of 6 and just use GL_LINE (though GL_LINE_STRIP would be preferred, the overhead to collect strips might not be worth it).
There's also one catch - some GeForce 2/3 cards can't draw anti-aliased textured lines. So in that case, you have two options:
1. use non-textured lines that approximate the color of the texture (looks amazingly good actually)
2. do a funky 3-pass process involving the alpha buffer.
Here's some code that does this (iniospaceModel.cpp), but if you can glean anything useful from it I'd be amazed. It doesn't implement the separate drawing for silhouette/overlay edges, but I think it does do the data collection for them. It does however have the funky alpha buffer trick I mentioned though (search for bNoSmoothTexturedLines). However, it won't compile on it's own, it's just a little teeny hunk of the rather uncreatively named iniospace 3D game engine that never really made it off the ground.
skyhawk
2003.10.01, 03:36 PM
Originally posted by inio
If speed isn't an issue, GL_POLYGON_SMOOTH is your easiest answer probably. it works something like this:
1. allocate a GL context with an alpha buffer. The cheesy 1-bit alpha buffer you get by default with 1555 contexts won't cut it, you need a full 8-bit alpha buffer. You don't need a z-buffer though.
2. clear the color and alpha buffers to 0 before each frame (mandatory)
3. Disable all z-buffer
4. glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE)
5. draw polygons in order front to back.
okay, when I did this, it draws my quad strip (which is draw n first), and then I see some faint wispy things where my carousel should be. I think the problem may be, I CAN'T draw polygons front to back, because all polygons are on the z=0 plane (orthographic projection)
MattDiamond
2003.10.01, 03:57 PM
Originally posted by skyhawk
okay, when I did this, it draws my quad strip (which is draw n first), and then I see some faint wispy things where my carousel should be. I think the problem may be, I CAN'T draw polygons front to back, because all polygons are on the z=0 plane (orthographic projection)
I suspect that what matters is which polygon is drawn first, not what Z they are at. The blending tells OpenGL how to composite the resulting 2D overlapping images. I don't think it matters whether in the original model the objects are coplanar or not.
(Not that I've done blending myself yet, but I think that's how it works.)
Originally posted by MattDiamond
I suspect that what matters is which polygon is drawn first, not what Z they are at. The blending tells OpenGL how to composite the resulting 2D overlapping images. I don't think it matters whether in the original model the objects are coplanar or not.
Exactly. You don't even use the z-buffer for anti-aliased drawing. Infact, you may need to explicitly disable it. The alpha buffer takes care of all your hidden surface removal needs. Effectively it becomes a Painter's algorithm in reverse.
MacFiend
2003.10.03, 05:52 AM
Or maybe you could draw smooth lines around the polygons.
skyhawk
2003.10.03, 10:50 AM
Originally posted by MacFiend
Or maybe you could draw smooth lines around the polygons.
see post 3 and 4 :rolleyes:
arekkusu
2003.10.10, 05:46 PM
If you are using an ATI 9600, 9700, or 9800, YOU ARE SCREWED.
Polygon antialiasing is NOT AVAILABLE on these cards. Hooray for "progress".
Thomas Fortier <TFortier@ati.com> writes:
The Radeon 9600 and later cards from ATI have no hardware support for AA
polygons, so unfortunately there is nothing that can be done to address this
missing driver feature.
As far as AA points and lines go, those features are present in the
hardware, but not yet exposed by our GL drivers. We do have plans to
implement them, but I can't comment on when drivers will be released with
those features supported.
Yes, this breaks many existing applications. No, ATI doesn't give a shit.
Originally posted by arekkusu
If you are using an ATI 9600, 9700, or 9800, YOU ARE SCREWED.
Yes, this breaks many existing applications. No, ATI doesn't give a shit.
Well, somebody shot himself, and many others, in the foot with that one. Really, the managers need to take their heads out of their rears.
"you see, my thingy has this cool feature. YOU just can't use it. ha-ha (Simpsons style)"
Programmer
2003.10.14, 10:58 PM
Could you enable full-scene anti-aliasing for these cards?
Edit: look what I happened to find on the Apple site... http://developer.apple.com/qa/qa2001/qa1268.html
skyhawk
2003.10.14, 11:12 PM
yes
arekkusu
2003.10.15, 01:00 AM
Yes, but this is a terrible solution, especially if you need multiple contexts, or render to windows.
There was a discussion about FSAA on mac-opengl recently.
Programmer
2003.10.15, 11:43 AM
Originally posted by arekkusu
Yes, but this is a terrible solution, especially if you need multiple contexts, or render to windows.
There was a discussion about FSAA on mac-opengl recently.
I would rephrase that to: "this is a terrible solution if you need multiple contexts or render to windows". Even then its not completely clear because your window sizes might not be that large, you might not need that many contexts, and you might have plenty of VRAM. I do agree, however, that it is not a be-all-and-end-all solution. For a wide class of situations, however, it does just fine and it has visual advantages over just edge anti-aliasing.
It would be nice if ATI provided edge anti-aliasing too. It looked like an ATI guy was asking how important this was on the macopengl list so perhaps there is hope.
arekkusu
2003.11.19, 06:24 PM
FSAA is a terrible solution for ANY 2D app, because:
1) the quality is worse than the old hardware smoothing
2) requires much more VRAM / fillrate
3) isn't as flexible (can't mix aliased and antialiased primitives)
For 3D apps FSAA probably seems like an OK solution since you generally want to avoid sorting your scene back-to-front to get correct alpha draw order. But it still is a big waste of time/space for a small quality improvement.
kelvin
2003.11.20, 03:25 AM
ATI's drivers suck. Just buy an nVidia card. There, problem solved.
arekkusu
2003.11.20, 06:21 AM
APPLE DOESN'T MAKE A 15" LAPTOP WITH AN NVIDIA CHIPSET.
</screaming>
Besides which, even if my personal system is OpenGL-compliant, what about my customers who bought machines with ATI chips? Eh!?
As a developer, you have the responsibility to test your software on all currently available systems.
kelvin
2003.11.20, 07:44 AM
okay, sorry, next time I'm being sarcastic I'll make sure and be as discreet as possible so as to kill anyone with over obviousness.
kelvin
2003.11.20, 07:47 AM
ever thought of changing the polygon fill mode to draw them antialiased lines rather than drawing GL_LINES?
Mars_999
2003.11.20, 04:09 PM
Originally posted by arekkusu
APPLE DOESN'T MAKE A 15" LAPTOP WITH AN NVIDIA CHIPSET.
</screaming>
Besides which, even if my personal system is OpenGL-compliant, what about my customers who bought machines with ATI chips? Eh!?
As a developer, you have the responsibility to test your software on all currently available systems.
You need to check again. The 12" Powerbook has a Nvidia 5200 GPU
OneSadCookie
2003.11.20, 05:47 PM
You need to learn to read, Mars. He want's a 15" laptop with an NVidia card.
arekkusu
2003.11.20, 05:56 PM
Originally posted by kelvin
ever thought of changing the polygon fill mode to draw them antialiased lines rather than drawing GL_LINES?
Yes, I thought of that. The current Radeon 9x00 drivers don't support point or line antialiasing either.
Line antialiasing is unreliable in any case-- the G4FMX can only draw lines 1px wide, for example. And the Radeon 9x00 doesn't draw anything if the width is < 1.0, which is out of spec.
In the past I've replaced both points and lines with textured quads, but now quads are broken as well. I started another thread about this earlier.
Mars_999
2003.11.20, 08:08 PM
Originally posted by OneSadCookie
You need to learn to read, Mars. He want's a 15" laptop with an NVidia card.
Whoops. Still stating the truth that their is a Nvida GPU laptop just in case no one knew that.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.