Z-Sorting Scene

Started by
9 comments, last by _the_phantom_ 19 years, 7 months ago
Hello all, I am trying to figure out the best way to z-sort my scene. Ive searched around the forums and looked through the opengl superbible 3rd edition and havent found it explicitly discussed anywhere. Im not sure what the best way to go around sorting the scene is. Should i build a vertex array with all the data for the current scene and then sort the vertices based on thier depth? So in my render loop i would do this: 1. Apply transforms to actors 2. Insert all object data into vertex array 3. Sort vertex array based on depth 4. Draw vertex array Is this method correct?
Advertisement
dont sort vertices, its a total waste of CPU time. At best you'll want to sort your objects front to back (taking say the center point of the object as the point you move) and draw them again, front to back, to take advantage of the z-buffer and any early z-rejection the hardware might well have in place.
This is what i was originally thinking, but i would have to sort the faces of the objects, not just the objects themselves. The only way i can think of to do that is sort vertices, unless i represent each face as an object, which doesnt sound right.

The reason object sorting doesnt sound like it will work properly is because if say i have a chair, its in a room, its center point is at a lesser depth than the room, so then you draw the chair, and then the room. But the faces behind the the chair that have a greater depth are drawn after, not before the chair.

Maybe my idea of an 'object' is wrong?
Why do you need depth sorting so bad?Is it for implementing transparent objects or something?
Yes, it is so that blending will work properly.
Well then you don't need z-sorting for the entire scene,just for the transparent objects.You can first render all the solid geometry(I guess it's the majority),then turn z-writes off and render transparent objects sorting them back-to-front.If the objects are closed,first render the back faces of an object(using face culling),and then the front faces.If objects don't overlap,it will have good results.
Ah, ok, ive just read a bit about that. You have to draw all objects, then draw all transparent objects from back to front.

So how would i test to see if an object is transparent before i draw it?

Quote:Original post by luridcortex
So how would i test to see if an object is transparent before i
draw it?


????
I don't exactly understand this question.What do you mean "test if it is transparent".You designed the scene,you should know.If you gave the material alpha<1,then the object is transparent.
Yeah, you are right, lol. Im not sure what i was thinking there. Im gonna go try this out, thanks for the help :)
Ok, it kinda works now..

The problem now is sorting the faces. For instance if you have a cube and you draw the faces back to front, the transparency works fine. However if we rotate it 180 degrees you have to change the order in which you draw the faces...

Right now i am using display lists to represent my geometry, i can think of any way to dynamically change the order in which the faces are drawn. Is there a way to do this?

This topic is closed to new replies.

Advertisement