View Full Version : sorting polygons

11-14-2002, 08:27 PM
With depth-testing enabled is there ever any reason to sort polygons before rendering?

11-14-2002, 08:44 PM
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.

11-14-2002, 11:01 PM
...and you have to sort any transparent polygons from back to front in non-convex objects - if you intend using alpha blending.

11-15-2002, 05:27 AM
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?

11-15-2002, 06:07 AM
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,...).


11-15-2002, 08:51 AM
Wow! awesome! now it all makes since. thanks

11-15-2002, 08:58 AM
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?

11-15-2002, 09:35 AM
Sure, why not. Especially if the particles move quickly, it's hard to notice the difference.

11-15-2002, 10:01 AM
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!

11-15-2002, 11:14 AM
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. developer.nvidia.com/docs/IO/1262/ATT/ OrderIndependentTransparency.ppt

11-15-2002, 11:39 AM
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?

11-15-2002, 12:04 PM
Very interesting read, JelloFish, thanks for sharing. That technique is a bit overkill for my simple snow particles I think http://www.opengl.org/discussion_boards/ubb/smile.gif , but I can see its benefit in other scenarios.

11-15-2002, 12:58 PM
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.

11-15-2002, 04:41 PM
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).]