Oats Blog

Pocket Dimensions Tech Experiment

Above you'll see an interesting experiment I made where the player can summon a doorway to a pocket dimension. Unlike many other space-warping effects like portals, these pocket dimensions do not involve any teleportation or far-off render targets - the pocket dimension actually does occupy the space behind wherever it's placed, even though it doesn't appear so. It does so by masking areas inside and outside the pocket for visibility, and flipping collision when the player enters and exits.

In the rest of this post I'll loosely break down how it's done and pose some ideas for expanding on this tech.

Creating the Doorway Mask

The crux of this effect is masking parts of the scene outside the pocket vs inside the pocket, and to do that we need a screen-space texture that can tell our materials when to make themselves transparent.

To get the inside-vs-outside mask I used a scene capture component mimicking the player camera, and placed a post process material on it that would make it render only a black and white mask of only the pocket dimension doorway. I placed invisible planes with custom depth enabled on the pocket doorway, and the post process material is designed to identify those planes and ignore everything else.

Masking out Materials

Now that the mask is working, we need our materials to respect it. For this effect to work all of the materials in the pocket, and any that might overlap a pocket, need to have masked or transparent opacity. I've made a pocket dimension master material to speed this up, where instances can either mask themselves to show inside the pocket or out.

Our doorway now acts like a window that lets us see different things inside, but you'll notice if you walk through it the effect doesn't persist. We'll need to write a script that inverts the mask when our camera passes through the window.

Finally, our pocket doorway reveals and hides objects as intended!

Collision and Lighting

Notably even though our pocket dimension doorway reveals a different space inside, entering the pocket has us colliding with the same objects as outside - and our invisible room is very much tangible on the outside! An overlap volume, a bit of scripting, and tagging objects as being 'inside' or 'outside' the pocket should help us clear this collision issue.

You might notice that the lighting is a bit funky. Ideally the inside of our pocket doesn't receive the light of the outside world and can have its own lights inside. We can use lighting channels to fix this.

Improvements

These pockets require a lot of setup, so here are some improvements I made to help with creating and managing them:

In the initial demonstration, I let the player place and summon a pocket at will. I'm not gonna go into the placement system but I do summon/unsummon the pockets at runtime. To do this easily I made the pocket scene a level instance, and I use a pocket manager blueprint to manage the placement and loading/unloading of pockets (and the player state relative to pockets too). This means I only have to load 1 thing (a level) when the pocket is summoned, and it is easy for me to edit pocket dimensions by opening their level asset.

Given more time I would write some scripts that quickly unhide all of the materials in the pocket dimension level for easier editing, and do automatic tagging and light channel assignment.

For the keen graphics programmers out there, there are probably more performant ways of generating the pocket visibility mask. I'm sure using a whole scene capture just to generate a black and white mask is not great.

Further Possibilities

There are lots of ways you can flavor this tech, and I'd be excited to see people expand on it. Here are a few ideas:

Environment-dependent pockets: This is an idea I've been pursuing a bit, where the surface that you place the pocket on changes the environment inside. It's easy to do by assigning your pocket-surfaces different physical materials and then checking the physical material with your placement raycast. The biome of the pocket interior can change based on surface material.

In a similar vein, you can have variations of the pocket based on horizontal, vertical, or angled placement. Maybe if the pocket is placed on the ceiling a ladder could drop dow or if placed on a slope it could form a path down through the earth.

Seamless non-euclidean travel: Combining pocket dimensions with a bit of sneaky teleporting could let the player seamlessly travel long distances unusally quick. Just make the pocket dimesnion a corridor with a few bends, at some point in the corridor teleport the player to an identical version far away, and then mysteriously they will exit the pocket someplace far away. You don't need pockets to do this, but I think having the player place down the entrace would help sell the effect.

A really confusing maze: You could make a very confusing maze that overlaps itself and lets you take 4 90 degree turns in a row. It would be quite evil.