Skip to main content
gamedev.net
🔒 Locked

Depth sorting

Started by deepsender 3 replies 1.1k views
Original Post
deepsender
deepsender
I want to depth-sort transparent quads prior to rendering. What is the best way to accomplish depth sorting in OpenGL, and when should it be done? I suppose the sorting should be done after frustum culling and before rendering each quad. But, how do I get the info, from OpenGL, to do the sorting? Here's pseudo code of each frame. glMatrixMode(GL_PROJECTION) gluPerspective(...) glMatrixMode(GL_MODELVIEW) gluLookAt(...) ... Do_frustum_culling() ... for each transparent quad... glPushMatrix() glTranslated(x,y,z) glGetFloatv(GL_MODELVIEW_MATRIX, m) remove_rotations(m) glLoadMatrixf(m) glBegin(GL_QUADS)...glEnd() glPopMatrix() end for Thanks.
Schrompf
Schrompf
Sort only per object. Sort in world space, before any OGL calls. Sorting triangles can be expensive and is hardly worth the work in my opinion.
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
riruilo
riruilo
I have the same problem.



I ask this to my teacher:
> My idea is traverse my secene graph two times, the
> first time I will render all opaque objects, and the
> second time I will render transparent objects, but I
> am not sure this will work with several transparent
> objects overlapped.
>
> Any idea?
>


And he told me this:

Yes.... :-).
The classic way is to do basically as you suggest:
1. render all opaque triangles
2. render all transparent triangles in front-to-back order.
You need to collect all transparent triangles from all objects, into
e.g. a list that you sort. If you are lazy, you use quick-sort and
resort every frame. But bubble-sort is better for utilizing
frame-to-frame coherency (you assume the same triangles are transparent
each time, and just update the nearly sorted list from the previous
pass.) Actually, you can, in a preprocessing step, traverse your scene
graph and collect all your transparent triangles into a list. This
would
probably be the easiest approach.
Regarding intersecting triangles: The correct way is to clip them
against each other.
The lazy way is to disable depth test. In that way, the intersecting
triangles will be rendered as transparent - but with the wrong
ordering.
Often (if you're lucky) the introduced error is not very disturbing.



I thinking about that...

I hope this helps you.

Bye.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
riruilo
riruilo
I realised my teacher is wrong, is not "front to back" is "back to front"

see you
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
deepsender
deepsender
Thanks for posting the stuff from your teacher, riruilo. It helps. So far, all my transparent surfaces are also billboarded, so no overlapping.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.