sorting polygons

With depth-testing enabled is there ever any reason to sort polygons before rendering?

Yes, because if you sort front-to-back fragments that have the same window space position get rejected earlier and do not require an expensive depth buffer write. Also most current hardware has some form of hierarchical z-buffer for which it also proves to be efficient to have polygons sorted.

…and you have to sort any transparent polygons from back to front in non-convex objects - if you intend using alpha blending.

okay so sorting seems nessicary for alpha blending applications. I assume the transparent polygons must be drawn last and the farthest ones away should be drawn before the nearer one right? But even with fast sorts such as quicksort and mergesort, with a large number of polygons wouldn’t the sort slow down the graphics pipeline? And after sorting how would a programmer know at what point he/she should stop drawing the polygone left in the sorted list?

Well, quicksort and stuff is not the way you sort polygons.
If you are interessted in sorting polys, then you should look for BSP-Trees (Binary Space Partitioning Trees). That´s the way most engines use (ie. Quake 1,2,3,…).


Wow! awesome! now it all makes since. thanks

How about for something simple like a particle engine? I imagine in this case it might be easier to just perform a sort on the z values of each particle, would that be a correct assumption on my part?

Sure, why not. Especially if the particles move quickly, it’s hard to notice the difference.

I’m currently not sorting right now, with about 300 particles simulating snowfall with blended quads, and only rarely can you notice blending weirdness. Probably due to the speed of the particles, as you mentioned. Thanks!

For transparent polygons tho you can use depth peeling to eliminate the need for sorting. As video cards get faster this is going to be an appropriate choice. OrderIndependentTransparency.ppt

depth peeling? what’s that? Translucent polygons should be drawn in order of the farthest ones first then the closer ones on top of those correct?

Very interesting read, JelloFish, thanks for sharing. That technique is a bit overkill for my simple snow particles I think , but I can see its benefit in other scenarios.

Well sorting artifacts are hardly noticible in fast moving particle systems when depth testing is turned off. Depth peeling really kicks butt for those cases with tough to sort intersecting transparent polygons. Geometry sorting will always be important, but new hardware is seriously taking the load off of scene management.

with certain blending modes sorting is not needed eg one,one
also for particle systems disabling depthbuffer writes works in 99% of the cases
edit by ‘works’ i mean ‘looks ok’

[This message has been edited by zed (edited 11-15-2002).]