Portal
Engine
One of the biggest problems in 3D viewing is define what scene elements hide each others. To better understand the problem think in a scene composed by polygons disposed in random positions. You canīt draw all of them in any order because a closer polygon can be covered by a polygon that are behind it. The magic of make only what is in front of the viewer visible is known as hiden surface removal. To make it exist many technics: Z-buffer, deph-sort, BSP-Tree sort and others. The algorithm used in this case is called portal clip. To understand this algorithm imagine the viewer inside a convex scene. A scene is convex when their polygons do not overlap each others in any point of view where viewer can be. The polygons, in this case, can be drawn in any order because they never overlap each others. Portal engines use this principle to render the scene. The scenery unit is known as "sector": a convex set of polygons where they never overlap (if the viewer is inside them). There is a problem because the sectors must be convex, this limit them too simple models. To create more complex scenes is used portal clip: some of the sector polygons are passages to other sectors. This polygons is known as "portals": polygons (normaly invisible) that work as clip areas to adjacent sectors. The basic view algorithm is: draw the sector where the viewer is, if a portal is visible from viewer point of view, call recursively the sector draw algorithm - drawing the sector linked by the portal. The sector visible througth a portal polygon is a "destin sector" and their polygons must be clipped acording the portal. If more portals are visible from the destin sector, call again the sector draw algorithm making the apropriate clip. The scene is complete when all visible portal polygons have their destin sectors drawn. Portal clip can be thinked as an evolution of BSP-tree sort, as BSP-tree sort and deph-sort are an evolution compared with Z-buffer. In Z-buffer to make hiden surface removal is needed test each pixel - the scenery unit is a pixel. In BSP-tree sort hiden surface removal is performed drawing polygons in the right other, acording the tree, the scenery unit is a polygon. In portal engines the hiden surface removal is made by portal clip througth a convex set of polygons - the scenery unit is a sector. Sure, think if a view method is better than other because the scenery units are biggest between each other is dangerous. Big scenery units mean scene design limitations, but normaly performace increase, too. Some problems of portal approach are: a very complex scene with many objects would be hard to be modeled, the scene must be indoor and the objects modeled with portals and sectors must be static. All this limitations can be atenuated with some additions. Usually portal engines are used to visualize the static scene objects like rooms, walls, pillars. More complex or, moveble, objects like stairs, chairs and animals would be visualized using an other method: Z-buffer, BSP-tree sort, and so on. Advantajes of portal redering: the implementation is relatively easy, big scene clusters are complete clipped very fast; transform universe reference system to camera reference system must be made only in visible sectors and their inside objects - with some precautions the scenery model can be hude without performace loose. Many tests like viewer collision detection can be optimized - made only between viewer and polygons sector where it be (see Collision Detection section).