Visualization Library 2.1.0
A lightweight C++ OpenGL middleware for 2D/3D graphics
|
[Download] [Tutorials] [All Classes] [Grouped Classes] |
This tutorial shows how to use the powerful vl::SceneManagerPortals class to render indoor or highly occluded scenes order of magnitudes more quickly than simply using frustum culling methods (even if using KdTrees or other accelation structures).
There are cases in which you want to render indoor or highly occluded but very complex scenes. Using frustum culling in this cases is not enough because the objects that remain in the view frustum are still too many. In such situations the solution is to avoid drawing the objects that are occluded by other objects. The vl::SceneManagerPortals class allows you to do so using the so called portal-based hidden surface removal algorithm. The basic concept is very simple, in a typical indoor environment most of the objects are hidden by the walls, the furniture etc. and the content of each room is visible either because the camera is in that room or through a door or window. We will call the rooms Sectors and the doors and windows Portals. If a door is not in our view frustum then also the room behind that door is not visible (unless we can see it through another door or window). Similarly, when a sector is visible the algorithm looks for all the Portals in that sector and checks if the Sectors behind those Portals are visible as well. This process is recursive and the algorithm might end up (but is definitely something you want to avoid!) traversing the whole scene going from sector to sector but usually only a small subset is traversed. When a new sector is discovered the Actors that contains are checked against not only the view frustum but also against the view frustum passing through the portals. This mechanism ensures a much higher probability of culling the Actors in the scene than using plain frustum culling, and the best part is that this is done traversing only a minimal part of the whole data set.
Using the vl::SceneManagerPortals class is extremely simple once you have defined your Portals, Sectors and the Actors that are in each sector. The challenging aspect is defining a good set of Portals and Sectors. This can be relatively simple for highly occluded environments or very difficult for complex or more open scenes. Furthermore the process of defining appropriate Portals and Sectors is very difficult to automate and usually requires human intervention. For example many FPS and even racing games use it. In this case the level editors and artists create appropriate portals in the right places and define by hand the Sectors. Portal and sector automatic generation is possible, for example it has been implemented already in the well-known game Quake I from Id Software, but usually severe limitations apply to the kinds of geometry that can be used and special tools are required.
On the other hand portal-based hidden surface removal not only can be tremendously efficient for the right kind of scenarios but it does not require any special OpenGL extension and thus works the same on any hardware and OpenGL implementation (unlike the various OpenGL extensions to perform occlusion queries like GL_ARB_occlusion_query
which suffer other kinds of limitations).
Note that the vl::SceneManagerPortals can be used in combination or side by side with other scene managers and demonstrates how flexible and versatile Visualization Library's architecture is.
For more information on how to use the vl::SceneManagerPortals class in combination with other scene managers see:
For more information about portal-based hidden surface removal see:
View of the normal scene. | View of the detected portals. | Geometry rendered using only view frustum culling. Note how much geometry is rendered in the background that will never be visible. | Geometry rendered using portal-based hidden surface removal. As we see portal-based hsr can take advantage of highly occluded scenes and can greatly boost the rendering process. |
In the following example we will procedurally create a dungeon with many rooms and will automatically create all the Portals and Sectors. Much of the code is taken by the geometry, portal and sector generation. As you will see the actual code that uses the vl::SceneManagerPortals class is very few. If we had the portals and sectors ready we would just load them into a vl::SceneManagerPortals and install the portal scene manager in a few lines of code!
Note that to outline even more the benefits of the portal-based hidden surface removal algorithm we will also add several highly detailed spheres to each sector. Pressing <F8> will enable/disable the portal-based culling.
[From App_PortalCulling.cpp
]
Visualization Library 2.1.0 Reference Documentation
Updated on Wed Mar 10 2021 16:02:44.
© Copyright Michele Bosi. All rights reserved.