Experimenting with portals in Godot Engine
WASD or arrow keys to move, E to pick up cube
This implementation has several issues that need to be fixed before the portals can be fully seamless. To fix all of them, Godot needs support for custom projection matrices and stencil buffering, which it doesn't have yet.
- Rendering
- Oblique near-plane frustum for portal cameras
- Fix performance with stencil buffering
- Lighting through portals
- Portal camera FOV sync with player FOV
- Portal dynamic updating in editor (optional, but nice)
- Physics
- Seamless first-person player teleportation
- Fix holding RigidBody through portal
- Collision masking for objects behind portal
The full details are in the code, but basically, the portals behave as described below.
Each portal has a camera attached to it, mapped to a ViewportTexture
on the linked portal. These cameras move based on the player position
such that angles look realistic.
When a RigidBody
overlaps the portal, it creates a clone at the
other portal. The clone and real object swap once the real object's
center goes behind its portal. This allows somewhat-seamless object
teleportation.