PDA

View Full Version : Sorting alogrithm



tcs
02-13-2000, 05:31 AM
I finally got my transparent-tree stuff working, but there is another problem. When you draw transparent object such as coronas or tree billboards with transparent background you have to sort them ! Does anyone know a fast and easy alogrithm to do this ???

dmy
02-13-2000, 07:04 AM
you can use the C qsort() function to sort things: i believe it will be fast enough.

but for glare effects (coronas,halos,lens flare and so on) i don't see the need to sort...

think about of the nature of glare effects: they are generated by the camera system.
this means they form on the surface or into the lenses.
other effects like diffusion are also intrinsic into some CCD device.

so, if you simply record the position of the effect, you can render them
at once just on the top of the scene (a landscape, if i'm not wrong).

for instance, i render lens flares generated by suns in my application this way, and they look very good.
i've alse implemented an occlusion test to check if the glare generator is visible,
and it's fine to see the lens flare being shutted down by a planet http://www.opengl.org/discussion_boards/ubb/smile.gif

if you're willing to render atmospheric effect like light diffusion into haze...
well in this case you'll have to sort things out.

tcs
02-13-2000, 08:15 AM
I have already finished a corona rendering system, I don't use z-Buffering and draw anything on top of my landscape. But I want to draw sprite trees with transparent background. So I need to sort them

Eric
02-14-2000, 12:00 AM
Hi !

I am quite interested in this topic coz' I ran in that problem some months ago.

I would like to know : when you want to sort your objects, you first have to obtain the transformed coordinates, no ? (I mean transformed by the Model View Matrix).

So, did you just rewrite your own matrix calculations or is there another way ?
I ask this just becoz' I do not see the advantages of T&L acceleration if we are to transform transparent objects ourselves...

Thanks.

Eric

MikeC
02-14-2000, 02:20 AM
Eric - you don't need to do a full matrix transform to do depth sorting. You're only interested in things' distance from the camera, so the only thing you have to calculate is

(myPos-thingPos).magnitudeSquared();

where myPos and thingPos are simple Vector3s. Note that you get the same results sorting by magnitudeSquared as you do by magnitude, and it's a lot faster (no sqrt).

Eric
02-14-2000, 03:57 AM
OOps, that's right...
Thanks Mike and sorry for asking that stupid question.......... http://www.opengl.org/discussion_boards/ubb/smile.gif

Eric

paolom
02-14-2000, 06:05 AM
MikeC: could you be much clearer on your explanation?
- does myPos stand for the viewer position?
- does magnitude stand for vector length?

MikeC
02-14-2000, 06:27 AM
Eric - no problem! http://www.opengl.org/discussion_boards/ubb/smile.gif

paolom - yes, right on both counts.

myPos is the viewer (camera) position.

thingPos is the position of the thing being depth-sorted.

So ( myPos - thingPos ) is the vector from the camera to the thing being depth-sorted.

magnitude == vector length

Sorry; you're right, that could have been clearer.