Jump to content
  • Advertisement
Sign in to follow this  
luridcortex

OpenGL Z-Sorting Scene

This topic is 5154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!