This is called portal rendering . It is usually used for low-cost drawing of some classes of the 3D environment, but as you noticed, the contents of the portal need not be associated with the contents of any other portal ...
To achieve the effect, when drawing a portal, he installs a graphic rasterizer to fix the rasterization of objects visible through the portal. To achieve this efficiently, the engine disables occlusion: it only needs to draw those objects that can be seen through the portal.
To make sure your portals can be correctly drawn as “more on the inside than on the outside,” you must make sure to “clear” the visible area inside each portal before drawing it. However, if all your portal scenes guarantee "water resistance", you can only leave by clearing the depth buffer.
source share