PDA

View Full Version : sorting polygons



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

Asgard
11-14-2002, 09: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.

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

reubenhawkins
11-15-2002, 06: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?

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

Jan.

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

yakuza
11-15-2002, 09: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?

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

yakuza
11-15-2002, 11: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!

JelloFish
11-15-2002, 12:14 PM
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

reubenhawkins
11-15-2002, 12:39 PM
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?

yakuza
11-15-2002, 01: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.

JelloFish
11-15-2002, 01: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.

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