Portals in TenGine
Contributions
Portals
Rendering
Portal Manager
Entities
Project Overview
Project Duration - 4 Weeks
Genre - Puzzle
Engine - TenGine (In-house)
Team Size - 1
Platfroms - PC & Playstation 5
Personal Notes
I don't usually like puzzle games but Portal was definitely one that piqued my interest.
Making my own version of a game such as Portal has only strengthened my respect for such a defining game in the industry.
Over the project duration, I've been able to independently explore new ideas, really letting me do what I want with a more liberal iterative approach.
Development Process
Portals
The first thing I worked on was to get a portal placed into the world, and it rendering something on the portals' texture.
When rendering the player's view through a portal, we must render a separate image using a virtual camera which looks out of the opposite portal. To obtain a correct image and efficient rendering performance, we render only what is visible through the limited field of view of the opposite portal and exclude objects which lie between the virtual camera and the plane of the opposite portal.
— David Kircher, the Portal physics & rendering engineer for Portal.
Following this concept, we take the camera of the player, the camera of the first portal and the camera of the linked portal, positioning the first portals camera to the linked portals position and vice versa relative to our movement, and Voilà! When we render, the portal will be rendering the linked portals' view.
tg::cMatrix4x4f player_camera_transform = player_cam->transform.world;
tg::cMatrix4x4f current_portal_transform = m_portal_model->transform.world;
tg::cMatrix4x4f linked_portal_transform = m_linked_portal->getModel()->transform.world;
tg::cMatrix4x4f cam_relative_to_current = player_camera_transform * current_portal_transform.invert();
tg::cMatrix4x4f new_camera_transform = cam_relative_to_current * linked_portal_transform;
Teleporting was using the same matrices as the prev, and getting the velocity to be transformed into the direction of the linked portal was similar to the caclulation for the cameras.
tg::cMatrix4x4f current_portal_mat = getModel()->transform.world;
current_portal_mat.invert();
tg::cVector3f vel_relative_to_current = traveller->getVelocity().transformVec( current_portal_mat);
tg::cVector3f vel_relative_to_link = -vel_relative_to_current.transformVec(
m_linked_portal->getModel()->transform.world);
A portal on the roof rendering nothing
When a second portal is placed, it renders what the roof portal sees.