sorting polys

Hi all,

I have some transparent (billboards) polys and I need of course to sort them so I will draw them back to front…

Can somebody help me

Are you certain they need sorting? If they are just alphamasked, you can just use an alpha test and draw them in any order. If they are partially transparent, like smoke, mist, and so on, then they do need sorting. So what exactly is your difficulty? Finding the distances to the billboards, or keeping the billboards facing the viewer? Or perhaps you just want suggestions on which sort to use? Radix (usually best) or qsort (usually good enough).

[This message has been edited by DFrey (edited 09-19-2000).]

Well what they are is trees… and what you have to do is draw the stuff behind first so it will be blended (and because I have to change the depth mask to false to prevent opengl from getting rid of trees behind others (and geometry) because of the depth test)

so I do it like this

render solid stuff (depth mask true)
depth mask false
render alpha blended stuff

anyway I originally was using a BSPTree to figure out what was in front of what, but it does not work, so I want to find other ways of determining what is in back of what so I can render in the proper order…

what I need help with is what is the best sorting method, (just by name is ok if it is just qsort or radix and the like, and how do you determine how far somthing is away (a poly is not 10 feet exactly away because it is dimensional (that is its center may be 10 feet, but its edges arn’t…

Anyway how do you determine how far a poly is and how do you sort them

[This message has been edited by frogger (edited 09-19-2000).]

Are your trees alpha masked? By that I mean are most pixel’s alpha values near 0 or 1? If so, you should be able to just use an alpha test when drawing the trees and draw them in any order. You’d still want to turn off depth writes, but leave depth testing turned on. On the other hand if the trees are truly alpha blended (many alpha values not near 0 or 1), then you need the distance for sorting. So as far as determining the distance, I just use the distance to the center of the billboard. Works fine. Popping artifacts and poke through may occur if you use them in a tight group though. If I’m just prototyping something, I’ll just use a qsort to sort the distances. Otherwise I’ll spend the time writing a radix sort (which I can never remember).

[This message has been edited by DFrey (edited 09-19-2000).]