PDA

View Full Version : Sorting for Transparency



tmason
02-17-2015, 06:22 AM
Hello,

So I would like to optimize my drawing calls to account for transparency.

Long story short, what I have been doing is sorting all of my OpenGL meshes from opaque to fully transparent before the scene is loaded and then drawing.

However, after reading, you must also sort from furthest to nearest.

The problem is I am not sure how this can be done dynamically in the scene with an std::vector or QVector based iteration of all of my objects I need to draw.

Consider the logical steps I am going through now:


Load all of my objects into Computer RAM via loaders.
With loaders I assign the correct materials to the object (colors, textures, etc.)
Sort by transparency
Load into OpenGL
Draw into OpenGL using the rendering loop.

I guess what I am asking is how do people sort the objects drawn from furthest to nearest per frame based on the active camera position?

What's the high speed way that I am missing?

Thank you.

__bob__
02-17-2015, 06:30 AM
What you want as no nice solution :
- oit (order independant transparency) not perfect but works
- depht peelling : need a lot of tweak and may be slow

GClements
02-17-2015, 08:06 AM
I guess what I am asking is how do people sort the objects drawn from furthest to nearest per frame based on the active camera position?
You need to use a topological sort (http://en.wikipedia.org/wiki/Topological_sorting).

You can't use std::sort (or qsort() etc) because (in general) there isn't a total ordering. To make matters worse, the graph may well have cycles, in which case you have to split polygons in order to break cycles.

If the objects' positions relative to each other are fixed, you can generate a BSP tree on loading (or beforehand). This makes it much simpler to determine the correct order for any given viewpoint. However, for complex geometry, it will typically require many polygons to be split.



What's the high speed way that I am missing?

Depth peeling. See e.g. here (https://developer.nvidia.com/content/interactive-order-independent-transparency).