0
\$\begingroup\$

I've been thinking about how to implement a portal, and after a quick search, everyone seems to do it by adding a camera per portal and then just update the other portal's view with that camera's view.

But if portals were real (like our real, the real in front of the monitor), they'd bend space in another dimension. Like the puzzle where you draw 5 points randomly on a sheet of paper and tell someone to connect those dots to all other dots without crossing lines (possible for 4 but not 5 dots). The trick to solving this puzzle is by bending the paper and poking through it at the right location (creating a "portal").

My question now is, can you implement the same technique in a game (engine) in 3D? Has someone done it before, and if yes, how does the math look like? Also, what would the pros and cons of doing it like this be? Is it more computational work to do? It sounds like it's just calculating with matrices, so doesn't sound that difficult for a GPU.

Please help me prevent another sleepless night, I've got stuff to do tomorrow. /s

\$\endgroup\$
6
  • \$\begingroup\$ The math looks like adding a second camera viewpoint. That may sound glib, but it's literally mathematically equivalent and a whole lot less work than trying to wedge bent space equations into every part of the rendering pipeline. \$\endgroup\$ – DMGregory May 2 '20 at 18:54
  • \$\begingroup\$ Yes, it can be done. One easy approach would be ray marching. I won't expect as good performance with ray marching, however that depends on the scene too. That is without considering space curvature. Perhaps ray casting/tracing is possible? If you can put the space curvature into neat equations that can be solved directly. \$\endgroup\$ – Theraot May 3 '20 at 4:29
  • \$\begingroup\$ For prior art, see Flight through a Wormhole. I have no idea how the code to render that looks like. \$\endgroup\$ – Theraot May 3 '20 at 4:31
  • \$\begingroup\$ If it is just matrices, it won't be the usual ones, you need a projection that a 4D matrix can't describe. Why? Because the viewing volume is curved. Heck, for the example above, it is discontinuous. You want portals, right? I do not think you are doing that with just matrices. That is my opinion. \$\endgroup\$ – Theraot May 3 '20 at 4:35
  • \$\begingroup\$ For making portals with cameras, which is not what you want, see Coding Adventure: Portals and, of course, Portal Problems - Lecture 11 - CS50's Introduction to Game Development 2018. \$\endgroup\$ – Theraot May 3 '20 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.