Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Sorting alogrithm

  1. #1
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Bremen, Bremen, Germany
    Posts
    58

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

  2. #2
    Member Regular Contributor
    Join Date
    Feb 2000
    Location
    milano, italy
    Posts
    282

    Re: Sorting alogrithm

    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.
    Dolo/\/\ightY

  3. #3
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Bremen, Bremen, Germany
    Posts
    58

    Re: Sorting alogrithm

    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

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Re: Sorting alogrithm

    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

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Sorting alogrithm

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

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Re: Sorting alogrithm

    OOps, that's right...
    Thanks Mike and sorry for asking that stupid question..........

    Eric

  7. #7
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Italy
    Posts
    77

    Re: Sorting alogrithm

    MikeC: could you be much clearer on your explanation?
    - does myPos stand for the viewer position?
    - does magnitude stand for vector length?
    --
    Paolo M.

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Sorting alogrithm

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •