Sorting alogrithm

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 ???

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

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

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

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

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).

OOps, that’s right…
Thanks Mike and sorry for asking that stupid question…

Eric

MikeC: could you be much clearer on your explanation?

  • does myPos stand for the viewer position?
  • does magnitude stand for vector length?

Eric - no problem!

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.