Jump to content
  • Advertisement
Sign in to follow this  
ventuz_ks

How to achieve Portal effect with view and projection matrix

This topic is 3352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks, I would like to achieve a visual effect like in the Portal game. I want to render a room which contains a screen. This screen should display a kind of extension of the room (behaviour like a window). The rendering on the screen must be perspectively correct from any point of view in the room. How do I have to setup and combine the two sets of view and projection matrix for the main room and the room on the screen to achive this effect? This is for a kind of virtual studio setup. Thanks

Share this post


Link to post
Share on other sites
Advertisement
There's actually a technique for rendering indoor environments called "portals", which im pretty sure is in fact how they are rendering the portals in that game.

Unfortunately if you google any form of "game programming" and "portal" you are probably going to get links to mods for that game or how to mod it (thats what i got last i tried hehe).

But, luckily for you, stencil buffer mirrors work much the same way, and i think would be really easy to adapt to what you are trying to do.

Try googling that (stencil buffer mirrors) and see if you can find a decent tutorial (:

Share this post


Link to post
Share on other sites
In pseudocode:

/* ... */
struct View
{
Matrix4x4 ViewMatrix;
Matrix4x4 ProjMatrix;
/* ... */
}

RenderScene_Recursive( View view )
{
// In the beginning the view is your player's camera view.
RenderNormalObjects( view );
RenderPortals_Recursive( view );
}

RenderPortals_Recursive( View view )
{
// Perform culling, stop recursion if needed, ...

for each portal
{
SetupStencilBufferAndPreRenderPortal( portal );

// Render the zone connected to the portal.
view.ViewMatrix *= portal.GetExitPortal().ViewMatrix;
RenderScene_Recursive( view );

ResetStencilBufferAndPostRenderPortal( portal );
}
}

[Edited by - PVSector on July 22, 2009 3:04:02 PM]

Share this post


Link to post
Share on other sites
Strangely, this book "Mathematics for 3D game programming and computer graphics
By Eric Lengyel" (which I also own) has the full segment explaining Portals online. (I think.) Scroll down to section 7.4 Portal Systems.

Book Section Here

Hope that helps.

Share this post


Link to post
Share on other sites
In that book Eric explains how portals are used for visibility determination
( good old portals like those in Quake, Doom, Red Faction, etc., precalculated PVS or portals placed by artists ). Here, i think, we're talking about transformative portals ( like in Prey, Narbacular Drop, Portal, Portalized ) which are basically holes in space.

(I'm currently researching this topic (after seeing impressive nullsquared's videos) and i've implemented some portal stuff myself.)

Share this post


Link to post
Share on other sites
If you guys have Portal (and I'm guessing you do), the developer commentary may provide some valuable insights on what they're doing with it.

Share this post


Link to post
Share on other sites
Although I don't have space or time to give the details, what you basically want to do is the following:

1) Determine the remote camera position and orientation (the camera transform) that corresponds to the destination of the portal.
2) Build a view frustum in the main scene that encloses the portal.
3) Render the remote scene to that view frustum.
4) Clear the Z buffer.
5) Render a flat planar object (possibly something that's not entirely transparent, but usually something that's invisible) over the portal in the main scene do that the Z buffer is initialized to the plane of the portal.
6) Render the main scene.

Share this post


Link to post
Share on other sites
Thanks so far!
As PVSector mentioned correctly I´m trying to build a 'hole in space' portal.
My problem is to match the parameters of the camera inside the room (A) that contains the portal and the room (B) 'behind' the portal. The room seen through the portal (B) has to be rendered to a rendertarget so I can´t use the same camera parameters for both rooms because the portal object where the rendertarget texture is applied to scales down my room B. So my room B camera needs at least a different FOV to compensate the scaling. And furthermore I have a problem with the perspective. Looking on a texture applied to a planar object (portal) is not the same as looking through this object. Or is my approach completely wrong?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!