Jump to content
  • Advertisement
Sign in to follow this  
Rogalon

OpenGL Sorting of transparent objects with 50k+ Polygons...

This topic is 4830 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

Hi gamedevers, in my 3D application (openGL) I'm currenty facing the problem of drawing a semi transparent (rotating!) object that consists of many polygons. I know how to sort the polygons very fast using radix sort but I still don't get (silly me) how to determine the right order on how to sort the polys. I need to sort depending on the distance to the camera. But how do I determine this distance correctly? The object is defined with a local center of (0/0/0) and then translated via the modelviewmatrix (glTranslate) into global space. The may or may not be a rotation (glRotate) encoded in the modelview Matrix before the translation. So I figure the final destination to the camera is dependent on the modelview matrix. Do I really need to multiply all centerpoints of my polygons with the mv matrix by hand before sorting. (Would render all the T&L Hardware pretty useless - wouldn't it?) Or is there any other way to do the sorting. I already thought of BSP trees of some sort but I would need to insert the rotated object every time there is a rotation - wouldn't I? Thanks for your time and answers... ;)

Share this post


Link to post
Share on other sites
Advertisement
lol all about bsp tree this week. actually you wouldn't have to remake the tree every time you rotated. because for z-ordering tree(node based) only the relative positions of the triangles matter. if you're only doing rotations, the relative positioning of them do not change, I'm not sure if you sheer tho, I think even this will maintain the relative ordering, but don't quote me on that. bsp tree takes a triangle and determins what triangles are infront of it, and what are behind, and makes a tree based on this information, this information does not change under a rotation. if a triangle is infront of another triangle, and you rotate it it's still in front of that triangle.

Tim

Share this post


Link to post
Share on other sites
of course the triangles themselves would change, so you can't store them in the nodes only pointers to them.

Share this post


Link to post
Share on other sites
Thanks for you fast answer. I'm not entirely sure if I understand what you're saying though.
If I'd put my model into a bsp tree and rotated the model by eg. 180° around it's local y axis than - if the camera is fixed - it would have to be drawn in a different order. So the positions have changed. (That's true even if there are only two planes - rotate them by 180° around their local axis and the order they'd have to be drawn changes.)
Maybe I don't really get how to read the information out of the BSP tree. (I must admit I'm not too much into these tiny little tree things)

What if I don't use any BSP trees - brings me back to my initial question would I have to do all the model transformations manually on the CPU?

Thanks again

Share this post


Link to post
Share on other sites
Quote:
Original post by Rogalon

What if I don't use any BSP trees - brings me back to my initial question would I have to do all the model transformations manually on the CPU?

Thanks again


Yes. Graphics cards in PCs do not allow the programmer to perform the geometric processing stage (or vertex shading), then access the data and, for example, sort it and then send it to the rasterization stage (or fragment shading).

But, as stated before, if your model is static, a BSP tree will be a much smarter solution.

Tom

Share this post


Link to post
Share on other sites
Quote:
Original post by Rogalon
But how do I determine this distance correctly? The object is defined with a local center of (0/0/0) and then translated via the modelviewmatrix (glTranslate) into global space. The may or may not be a rotation (glRotate) encoded in the modelview Matrix before the translation.


Once you have set the model's matrices, fetch the modelview matrix with:

float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix );

Then invert it (inverse rotation and translation) and transform your camera location with that. Camera is now in model's local space and you can depth sort the polygons as is, no need to transform them (unless you're using skeletal animation or some other dynamic deformation..)

ch.

Share this post


Link to post
Share on other sites
Thanks christian - why didn't I think of that... ;-( - sounds like a good way to solve my problem as long as I haven't implemented an octree into my app.

Is this how polygon sorting is normally done (inverting the modelview matrix and multiplying it with the camera location)? Or do the hardcore engines usually rely on bsp trees? (Btw - the link to bsp trees didn't work for me so I still don't really know how to get the polygons drawn in the right order by using a bsptree)

Thanks for your help, Rogalon

Share this post


Link to post
Share on other sites
Quote:
Original post by Rogalon
Is this how polygon sorting is normally done (inverting the modelview matrix and multiplying it with the camera location)? Or do the hardcore engines usually rely on bsp trees?


Only engine I took a peek is Quake, and it's kinda hacked up. There's transparent surfaces like glass and water that are part of the whole "world-bsp", so they get automatic sorting with that. For other transparent dynamic objects, it may have done some depth-sorting on object-basis.
They first drew solid polygons and then took another pass with the alpha-surfaces disabling depth-writes.

You might not even need all that heavy polygon-sorting, try out different things and see what has a good ratio on "looks-good/works-fast". I could go with object-sorting, it may come out looking nice.

Quote:

(Btw - the link to bsp trees didn't work for me so I still don't really know how to get the polygons drawn in the right order by using a bsptree)


Works for me. (?)

ch.


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!