Portal rendering & portal physics

This is something I’ve always been interested in and has always been very awkward in gmod - portals.

Portals are far from being a mere gimmick, they have a wide variety of very interesting uses for gamemodes, mapping, and general shenanigans. For instance, they allow mappers to decouple “inside” areas from “outside” areas, they allow coders to duplicate instances of the same room/space into multiple locations seamlessly, they can be used for interesting game mechanics or for maps with non-eucledian space.

Rendering portals is fairly straightforward. You set up a custom view point, adjust the cull frustrum so that you don’t render more geometry than needed, and draw over the screen using either stencils or UV mapping over a texture. The crucial part here is the custom cull frustrum - I’m not sure whether gmod had (has?) support for this, but portals had a really bad performance impact if done using the renderview/stencil method.

Another very tricky aspects of portals is handling physics through a portal. This requires being able to create a special kind of “mirroring” constraint between two physics objects (so that they follow each others’ movements relative to the two sides of the portal), and to be able to programmatically ignore contact points. In particular, on a physics object all contact points that appear on the portal or behind it are ignored, so that the object can “go through” walls and not interact with objects its not supposed to.

I don’t think gmod had either of these two things, and most attempts at recreating portals were really jank or prone to strange behaviours. Someone correct me if I’m wrong.

Here’s an example of a portal done using PhysX using the method above (contact points and portal constraint)

Hope this can be done in Rubikon too, and hope we’ll have the necessary bindings to do it :slight_smile:

5 Likes

I need this.

2 Likes

are portals possible in source 2?

1 Like

I would imagine so… It’s just checking if the player collides with a surface marked as a portal and then teleporting them to the sister portal

1 Like

Portal 2 :yum:

1 Like

I hope this is possible for sbox. linked_portal_door was so useful for mapping and connecting different areas even for non-portal-esque levels, so I was really bummed to find out s2 didn’t have it. I already have a use for this in a gamemode I’m working on.

3 Likes

It’s just checking if the player collides with a surface marked as a portal and then teleporting them to the sister portal

Doesn’t work for physics objects.

1 Like

I assume this will be part of source 2, and may require a bit of c# programming to get player teleporting from one portal to another.

1 Like

its not that simple if you want to reproduce what is seen in the video. For example: what if you want to stand in between two portals?

2 Likes

Yes if I’m going to be honest it was early and I didn’t watch the video first. Replicating that will take more code than I was originally describing.

I’d love to see the Portal 2 portal code make it in, but if we at least have the appropriate engine bindings to make this functionality ourselves efficiently (RenderView in GMod was super slow) that would be just fine too, some of my GMod addons are based around portal tech (TARDIS Rewrite, Safe Space) so definitely hoping we can render portals fast in S&Box because it is a massive frame killer in GMod at the moment.

2 Likes