Visualization Library 2.1.0
A lightweight C++ OpenGL middleware for 2D/3D graphics
|
[Download] [Tutorials] [All Classes] [Grouped Classes] |
In this tutorial you will learn how to perform primitive depth sorting in order to obtain correct transparencies.
Managing transparent objects in the correct way using OpenGL (but also DirectX) can be quite challenging at times. This is because in general, when rendering transparent objects, the order in which such objects are rendered affects the final result. Theoretically the problem could be solved by sorting back to front each single pixel that is generated by the rendering process. In practice this approach is too expensive to implement and for simple cases it is enough to sort front to back entire objects. This works well util the transparent objects in the scene are convex but when we add concave objects we will start noticing some artifacts. In this cases it is necessary to sort back to font the polygons of each object. When two transparent objects intersect each other, though, not even this approach yelds correct results in general. Fortunately this last case is relatively rare compared to the previous ones.
Depth sorting on: | |||
Depth sorting off: |
The example below shows how to apply a vl::DepthSortCallback callback to an Actor in order to sort its polygons. In the example we load an object and we display it with and without polygon sorting to hightlight the effect of the vl::DepthSortCallback callback.
The DepthSortCallback class sorts the primitives of the Geometry object bound to the Actor in which the callback is installed.
This callback in order to work requires the following conditions:
false
(vl::DepthMask) and enable the depth test (vl::EN_DEPTH_TEST), but you wouldn't need to perform any sorting.[From App_PolyDepthSorting.cpp
]
Visualization Library 2.1.0 Reference Documentation
Updated on Wed Mar 10 2021 16:02:44.
© Copyright Michele Bosi. All rights reserved.