Portal
Clip
Portal engines make invisible surface removal based on portal clip. The portal is a simple scene polygon, the clipping can be performed with any known method. I implement one method based on "clip edge buffer", probably exists better methods, but it's easy implement. Consider a viewport where X increase from left to right and the portal must be a convex polygon. For each scanline exist two informations associated: one start X value and one end X value. This array of X start-end values is known as edge buffer. During polygon edges scanning, the the minimum and the maximum edge values, for each scanline, are defined. If there isn't portal visible in a scanline, the values stored for this scanline are the maximum viewport X in start X and minimum viewport X in end X. When the destin sector is in rendering their polygons are tested and clipped by the edge buffer limits. The same procedure must be done to set a new clip edge buffer, if another portal is visible througth destin sector. The clip edge buffer, in the sector where viewer is inside, can be initialized with the viewport limits. This method have two problems if the vertical resolution is high: need allocation of to much memory for each rendering recursion level, and to much tests for each scanline. A suggestion (more resolution independent) can be, create a new polygon acording the visible area between the portal and the destin sector polygon. The visible area is the intersection between both polygons.