Seamless Portals - Geometry Clipping

I’ve been creating seamless portals for my game, mostly going well, I have portal cameras rendering at the correct perspectives and the player can pass through portals seamlessly, but I have two issues I cannot find a perfect solution for.

1. Camera near plane clipping portal render texture

When the player is close to the portals render texture the camera’s near plane clips rendering of the portal plane. I need this plane to be fully rendered across the screen when the player is that close to it.

2. Clipping geometry behind portals for the portal camera

The camera used by the portals for the render texture image should clip any geometry between the camera and the portal plane. I’ve had partial fixes using a replacement shader for the camera and passing the portal plane to a custom shader to then cull the objects but since im using a replacement shader I cannot find a way to then render all objects with their appropriate material shaders.

Any advice/solutions would be much appreciated!

1 Like

I have a similar issue. What solution were you able to come up with for the near clip issue?

Short answer: use the stencil buffer. And if you are interested in portals in VR, you probably want to check out this article.

1 Like

Yes stencils are awesome and I also stumbled across John’s post which is really really interesting.

I also dissected the three different portal approaches in a blog post of mine. I got very far already, the only thing left is really handling the near clip plane well (special case for me is VR where you have different stencils per eye) for which I have not found a 100% solution so far. One seems to be opaque projection to clip a camera better. A more promising way seems to be portal corridors instead of only a plane. I am currently implementing this and I’ll write a blog post if I get it to work detailing the solution for anyone interested. My first tests are really great.