In practice, however, these problems solved themselves. Unfortunately, this involves modifying every supporting vertex shader and can impact performance (as it requires calculating the vertex world position). This is a vertex shader feature that allows extra clipping based on proximity. To counteract this, we used Clip/Cull Distances. This causes problems with depth precision which, although acceptable for normal reflections, become obvious when the player gets too close. As the viewing angle of the portal shallows, the far plane rotates, intersecting the near plane off-screen. Unfortunately, projection matrices can’t represent six independent planes, so modifying the near plane inevitably affects the far plane. This is a straightforward solution, the only requirement being a change to the projection matrices. This ‘clips’ (stops rendering) the objects behind the portal’s surface. The first was to modify the projection matrices to create an oblique ‘near plane’ aligned with the surface of the portal. While this might look strange, this ‘convergence’ (multiple objects occupying the same space) can also cause discomfort viewed in VR.įortunately, this was a problem with several well-established solutions, the same solutions we employed when implementing reflections. Having established the correct point-of-view, the next task was to remove all the geometry behind the portal, which was now being drawn over the top of the new scene. These were excluded due to their incompatibility with other systems, and why all the ‘pass-though’ mirrors in Shadow Point are also flipped on the x-axis. Finally we applied the ‘local to world’ matrix to move back into world space, but this time on the opposite side of the portal.įor any objects moving through the portals - including the player - we applied the same process… with the exception of transformations that would require scaling. We could then apply custom transformations depending on the portal’s gameplay purpose: Z-flip for a normal mirror, or X- and Z-flip for ‘pass-through’ mirrors. To calculate the point-of-view from which to render the portal, we took the position of the player’s view into the portal’s local space by applying the ‘world to local’ transformation matrix (the combined translation, rotation and scale) of the portal to the camera view matrices. We’re going to be getting into some very technical and in-depth discussions to explain how we created portals in Shadow Point. With portals being a crucially important part of Shadow Point, it was very important that we were meticulous in the planning and implementation of this feature. We also decided we couldn’t support recursion - the ability to see a portal through another portal - which simplified implementation and avoided problems like infinite recursion (the classic ‘endless hallway’ effect).
Most importantly, we placed a hard limit on the number of portals we could render at any one time, with a maximum of three, constrained further still in rare instances to two or one. Since one portal requires the whole scene to be redrawn, a single portal doubles the amount of rendering required, on top of the cost of the game logic when the player interacts.ĭue to our target being a mobile VR device, we decided early on to set limits on how the player could interact with portals, and strictly capped the size and complexity of the surrounding scenes. Finally, it draws the new scene relative to this position. As for creating portals, each one takes the player’s position relative to itself, then applies that transformation on the opposite side.
In fact, every mirror in Shadow Point is effectively a portal that references itself with a flipped Z-axis. We approached rendering portals in a very similar way to rendering a mirror. In a nutshell, how do portals work in Shadow Point? In this article, Matt Hubery, Senior Programmer at Coatsink, dives into the challenges of making portals a reality on mobile VR. Shadow Point, our launch title for the Oculus Quest, combined real-time shadow-casting, mirrors, gravity manipulation and reality-spanning portals into a mind-bending puzzle game – all on a mobile form factor.