Original Post
Working on an assigment for Uni I came up with this fast solution to sorting blended polygons. I have yet to see this technique used elsewhere or talked about in a tutorial so I thought i would share. It doesn't work in all situations but has worked well for my requirements I hope some of you find this useful. Understanding this stuff requires a working knowledge of vectors. As most of you probably know, to draw blended polygons correctly (in opengl at least) you need to draw all the unblended polygons, then the blended polygons from the furtherest to the nearest. However working out at which polygons to draw first can be a bit of a messy problem and most solutions, while computationally cheap can create visual artifacts. The simplest method is to use the polygon's maximum or average depth and draw the polygon accordingly. This breaks down however if two overlapping polygons have the same maximum or average depth (a few geometric primatives have this problem as I found out) at certain camera angles. Not wanting to make my sorting any more computationally expensive I came up with this neat little solution. When two polygons share the same maximum or average depth the polygon with the smallest angle between it's normal and the viewing direction of the camera is drawn first. One need only calculate this when faced with the previous equality and the angles need not be calculated only the cosine of the angles. i.e in 2D cv (camera view) = 0i + 1j p1n (polygon 1 normal) = 0.707i - 0.707j p2n (polygon 2 normal) = 0.866i - 0.5j cv.p1n = -0.707 (135 degrees) cv.p2n = -0.5 (120 degrees) So polygon 2 will be draw first. This technique won't help with overlaping polygons (those polygons that go through over polygons) of course, and I have no idea what would happen if applied to concave polygons but it can help in some situations. I hope it is useful to someone it certainly saved me some pain! Rory Hart Computational Science Student