I´m writing an opengl app which uses transparency/translucency algorithms based on depth ordering.
My first approach calculates bounding box center distance to camera for all the objects, but i realized that one bounding box can be closest to camera than other, but its center is farthest.
The orientation of the boxes can be different so axis aren't aligned.
How can i calculate correctly bounding box distance to camera?
The best approximation can be done by sorting the objects using the farthest OBB point Z-component in camera space (the point with the highest/lowest Z-component in camera space depending on handedness) and hence comes the name Z-sorting. Also you can use a squared distance just fine.
Remember that when issuing a draw commands you need to render one of them first (you can't draw them partially unless you break each of them to separate objects.
In your case object1 should be drawn first, and notice that it has the farthest point along the camera axis.
The algorithm in a nutshell:
P.S. I am yet to think of a case where this might fail that's why I said approximation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With