Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

What I do is I prepare a front cap. It is a quad that fills the space that is not covered by a clipped portal.

The way I do that is that I calculate a line that is the result of portal clipping the near plane. This gives me a line in 2D. Then I find a point on that line that is closest to the centre (that will be a point that lies on a line perpendicular to the line we've just found, and it goes through 0,0, this makes it a lot easier, and we use that perpendicular dir anyway when constructing the quad). With that point, I am able to construct a quad. One important thing is that I make it a bit wider to cover any artefacts. Only a very little bit wider. I use a constant (0.0001f). I was experimenting with relying on near plane dist and other stuff and this constant turned out to work the best.

When I render the portal, I first render the portal as usual and then I render front cap (with no depth checks - it's near plane, right? but there are usual stencil checks (equal to current stencil depth, I increase it by one). When closing the portal (after interior is drawn) I render it the same way (one important difference is that test for stencil is provided value has to be less than in the buffer and I replace the stencil buffer content). I used to have decrease there, I used to not extend the cap, I was also experimenting with not using near plane. There were lots of odd things happening, sometimes the whole thing disappearing, sometimes there were just very narrow lines that were not covered (you could see stuff behind the portal).

Thank you very much for the help! I will try it as soon as possible!

You're welcome. If you have any questions or issues, let me know and I'll try to help. And if you'd like to show the thing you're working on, I'd be happy to take a look at it :)


Thanks for the offer! 
I tried to implement your way of making the cap, but I'm stuck :/  What I did:

1) Getting the intersection between the portal plane and the camera near plane (this is a 2D line on the near plane)
2) get the nearest point to the center of the near plane (which is orthogonal to the "intersection 2D line“ from step 1)
and then I have no idea how to build a useful capping geometry out of this information.

Are you building the capping quad in front of the near plane directly? As soon as my camera has minimal offset to the portal plane, the intersection from portal plane and near clip plane is not in the frustum anymore :/
I could add some screenshots, but I don't think this would really fit into the forum which should be about "tea for god" :)

Thank you very much in advance!

ps: I am doing a pure research project to understand how it works :)

Hey, send me an e-mail to and I will send you drawings of how to build a cap with some source code (although you may need to rewrite it a bit, to match you needs, axes etc)