How do the video screens in Prey work?


#1

A lot of the screens you watch videos on in Prey show a 3D space when you look through them. This effect is even used to show more inquisitive players a secret when somebody walks off screen at one point.

Does it work like how most people understand video game mirrors to work? By rendering a new room on the other side?

I’m just extra perplexed because most of the screens are windows that can be broken, but still work, even with massive holes in them.

It’s a really cool looking effect.


#2

Yep, in the game fiction they’re “Looking Glass” (nod) and they’re fully-immersive 3D screens effectively.

The engine tech is definitely rendering them as normal environments and then using something like a mask to paint only over the unbroken bits of the glass screen surface (the screens aren’t pre-broken as you can smash them in many different ways and the broken part forms around where you hit them). So, unlike most game engine mirrors, this isn’t a low res or visibly different render but looks indistinguishable from any other bit of level geometry. Anything you see in the game behind some glass could be fake and you’d not know it. What’s more, you don’t even necessarily see the glass when the Looking Glass is on.


#3

Wow, thanks so much!


#4

If I’m understanding the effect correctly, it sounds like a similar effect they used to render the other side of the portals in Portal (for example). I saw a video about recreating the effect in Unity once, but I forget what type of shader it was. Maybe a stencil shader, maybe a replacement shader, maybe something else. Anyway, you can set up a shader to render the view of another camera elsewhere in the level, and match that camera’s translation and rotation to an offset of the player’s view. In Portal they give you a relatively unobstructed view (except for the particle effect that comes off the edge), but you could do more complex things like put cracks and holes in it by being clever about how you apply the shader, I think.

Disclaimer: I’m not any sort of game developer, I’ve just watched a few videos on YouTube out of curiosity.


#5

I have zero graphics programming knowledge, but there’s alot of info about this online. This technique is called “portalling”, which unfortunately due to the game Portal is now very difficult to search for on google.

Portal is probably the most obvious example of this technique. In layman’s terms, it’s essentially a flat texture connected to a camera, which moves and rotates based on the position you view the texture from.

All the documentation for Narbacular Drop (The game the Portal team made as Digipen students) is available online, this is the quote from their technical design document.

Portal Effect
The creation of our portals takes place with some extremely simple trickery along with a lot of tedious things to make it work well.
Essentially, a portal is just a textured quad. But the contents of the texture are dynamic and the texture coordinates change based on how you’re looking at the quad.

To create the contents of the texture:

  1. Convert the current camera position and look vector into coordinates relative to the portal.
  2. Find this position and rotation in relation to the portal’s exit.
  3. Move the camera to the point and rotation found in step 2.
  4. Render the scene while culling all objects between the camera and the portal exit.
  5. The render surface is now the source texture for the portal and the camera should be moved back to where it was before step 1.

To render the quad with the proper texture coordinates:

  1. Convert each coordinate into screen space.
  2. Copy the normalized screen space x and y components into the u and v coordinates of each vertex.
  3. Render the quad.

This also seems like a good technical explantion: https://torinmr.github.io/cs148/

As for the room itself, I’d guess the room you see in the looking glass videos is hidden outside the level somewhere. If you think back to Half Life 2, those Dr Breen videos you see around City 17 were all running in realtime. There’s a room outside each level with a camera and a Dr Breen model that plays the animations. You can see a video here of someone getting into the room: https://www.youtube.com/watch?v=q_nmpl6yIBA&t=2m32s

This technique is actually something you’ve seen alot and probably never really noticed, because it’s how skyboxes work. Instead of building an entire city environment in the background, you build a miniature version of the city and use portalling to render it at a larger scale. In hindsight it makes the whole helicopter sequence in Prey a really good gamedev in-joke. https://www.youtube.com/watch?v=D6HenZtZje8


#6

TBH, skyboxes are typically a lot simpler and don’t use anything complex like a portal. Because they’re behind the geometry of the level. So you just do [clear everything] [skybox render] [clear depth buffer] [level render] into the main buffer.

There are a few tricky thing with portals and any similar techniques [all speculation on what Prey actually does].

The sheer volume of additional rendering needed to render the new area means the need to us a (stencil) mask to reduce how much wasted rendering is done - note that you need to render the stuff in the main level to know how much surface is exposed, then you need to render that surface through the portal with the occluded area masked to prevent running expensive shaders on stuff you can’t see, then you need to put that rendered texture into the main level.

If you mask a non-occluded area [with a transparent fill] then you can make a hole but you have to render the stuff behind it first. And that (masked) edge is not going to be anti-aliased (if you use MSAA, which Portal does but Prey doesn’t) because it’s not a geometry edge. Of course, the edges in Prey are very straight so the likely technique used is breaking the surface geometry and removing the missing bits rather than using a texture effect/mask to remove it - so the surface is broken via generating new polygons to define the hole and then texturing over the ones left.

The HL2 cameras of Breen are a great example of doing something like portalling but much less cleanly: yes, it’s a render to texture that is projected into the world but it’s not the right texture for your camera each time. They make a generic, say 256x512, texture and render to it, just one sample per pixel of that intermediary. Then use that surface to render into the final scene. But it’s the same texture (maybe LoD means they lower the texture res as you get further away, often not even that) if you’re looking standing on the bottom right corner or the top left. So the sample density (as stuff closer to the camera is bigger) is not uniform from your perspective. The clever thing about proper portalling (as Prey does, which you can tell due to no quality drop, unlike most mirrors/reflections in games - even the ones that do it expensively) is that the texture is correctly built and so the sample density through the portal is identical to the main scene. Rather than a generic intermediate texture, it’s sampling for each pixel in the final scene.


#7

So from reading through this I feel like only the visual effect is being described here for the portal. What I don’t understand is how they are making the portal feel like an open space and have half of an object be through one and the other?


#8

So from my understanding of Preys engine it doesn’t normally use PVS but I believe it is what they are using to achieve the effect. This is a good read on how PVS works in the Source Engine for optimization purposes.

What you are seeing is the engine stitching two portals areas together temporarily. Imagine we have two separate rooms like in this image

Normally if you are standing in the black room you can’t see what’s in the red room and vice versa.

But what would happen if we added a window (yellow) that told the engine these rooms are connected in this way?

To the player it would render like this

Keep in mind the engine doesn’t care about physics. We can tear holes wherever we want and have them show things that physically do not make sense.

Portal 2 in fact makes use of this technique in one particular level where the room is much bigger on the inside then it is on the outside for gameplay purposes. So we ended up with an entity called linked_portal_door which sadly was never ported to any other branch of the engine because it lets you do fun things with it