3
\$\begingroup\$

In Portal or Portal 2, let's say you pick up a cube and put it most of the way through a portal on a very thin wall. The cube should clip outside the backside of the wall. How does Portal do this, or how can this be done in general?

\$\endgroup\$
2
  • \$\begingroup\$ We can't necessarily answer how Portal specifically does this. You should rephrase to ask how it can be done in general, as there is more than one way. \$\endgroup\$ Aug 24, 2013 at 18:25
  • \$\begingroup\$ Good suggestion. Edited. \$\endgroup\$
    – Keavon
    Aug 24, 2013 at 18:44

1 Answer 1

6
\$\begingroup\$

You're looking for a form of antiportals combined with portal rendering. Portal rendering is an old technique for breaking the world apart into sectors and only rendering the objects (or pieces of objects) within a given sector at a time and using visibility sets to figure out which portal to render. Antiportals are a technique by which you cull objects (or individual faces or vertices) which are occluded by a solid plane. Note that traditional portal rendering would not cull the objects halfway through a portal, though antiportals could be used for this. This you can generate an antiportal for each "portal" in the game and then use it to draw only the visible half of the object on the "outward" side of the portal.

There are a few ways to do this. The most obvious "brute force" way is to simply clip the whole object at the polygon/triangle level against the portal. This would not have been an uncommon approach in years past with low-poly models were Portal written back then, but it's probably not what a modern engine would do.

Another option is to use GPU clipping. This can be a combination of vertex clipping and fragment culling. The position of any fragment can be calculated in the fragment shader when rendering in many rendering engines. This position can be compared against the antiportal's plane and then only drawn if it's on the front side (easily determined with a dot product).

While it doesn't go into any great depth on how the portal rendering works, you may find the Narbacular Drop technical design document of interest. This is the student game that inspired the original Portal, whose team members were hired by Valve to implement the portal mechanics of Portal in Source. See also this Gamasutra article. The rendering is mostly a well-known solved problem and the real trick of making Portal actually work was the physics, which is a much more interesting and challenging problem to solve.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks. A couple questions for clarification: wouldn't clipping vertices on the other side of the antiportal cause the tris visible on your side of the antiportal to not render? For example, one of the 3 vertices is clipped, causing the tri between it and the other two to not be drawn, causing weird splinters visible through the (in-game) portal? Next, is this what GPU clipping prevents by clipping the rendering past the antiportal in a straight slice? \$\endgroup\$
    – Keavon
    Aug 24, 2013 at 22:15
  • \$\begingroup\$ Clipping vertices does not cause the whole vertex/tri to disappear. See en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm. \$\endgroup\$ Aug 24, 2013 at 22:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .