polygon smoothing

Moderator
Posts: 916
Joined: 2002.10
Post: #1
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?
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #2
I vaguely remember something about blending being needed for smoothing. Maybe thats just for smooth points though.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
You might try inio's idea... sorting the polygons and drawing antialiased lines around the polygon edges.
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #4
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, 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.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #5
Quote: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)
Quote this message in a reply
Moderator
Posts: 434
Joined: 2002.09
Post: #6
Quote: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.)

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #7
Quote: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.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #8
Or maybe you could draw smooth lines around the polygons.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #9
Quote:Originally posted by MacFiend
Or maybe you could draw smooth lines around the polygons.

see post 3 and 4 Rolleyes
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #10
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:
Quote: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.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #11
Quote: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)"
Quote this message in a reply
Programmer
Unregistered
 
Post: #12
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
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #13
yes
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #14
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.
Quote this message in a reply
Programmer
Unregistered
 
Post: #15
Quote: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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Polygon budgets Kerome 1 2,873 Mar 7, 2010 04:55 AM
Last Post: mikey
  glut polygon winding strangeness OptimisticMonkey 2 3,069 Sep 7, 2009 06:27 PM
Last Post: OptimisticMonkey
  Getting the Normal for a polygon. Jaden 3 5,771 May 1, 2009 01:47 PM
Last Post: Nosredna
  Smoothing geometry via subdivision TomorrowPlusX 1 2,823 Aug 30, 2007 02:46 PM
Last Post: OneSadCookie
  Smoothing tangents for bumpmapping TomorrowPlusX 1 2,540 Aug 13, 2007 10:54 AM
Last Post: TomorrowPlusX