- Home /
Creating portal camera view with render textur
Hi there,
I'm trying to build a simple portal mechanic like the one in Valves Portal and Portal 2. Currently I'm struggling with the visual part. I'm using the Unity Pro feature Render Texture. The Camera creating the render texture for the blue portal is a child of the orange portal game object and is moved by an script relative to the position of the main (player) camera to the blue portal. Rotation and other camera properties are equal to the main camera. Still if I place both portals like an two sided mirror I don't get the wanted window-effect since somehow the render texture doesn't fit right...
In the picture the orange portal is on the back side of the blue one and is rotated by 180 degree. On the left side you see both cameras (main camera & texture camera) having almost the same position. Which seam to be the wrong approach. Can anybody help me to figure out how to move position the texture camera properly?
Thanks alot!
You can find my project here: https://github.com/Saduras/Testchamber
You're not going to get it perfect like that. You're rendering one angle, while your camera is looking from another. You need to do some maths to rotate your portal cameras to match your main camera, otherwise you've essentially got a TV screen.
Sounds like my approach is not completely wrong. Any hints for the direction of math I should look for? I'm actually pretty good at math, but feels like and don't understand the rules of 3D cameras well enough...
Well, you essentially want to match the projection matrix, such that the inner camera's projection point (the frustum of the pyramid) matches the projection of the main camera. Not quite sure how you'd achieve it, but that should work.
Working on this myself. This was very helpful for the maths: OpenGL Program$$anonymous$$g/$$anonymous$$ini-Portal
Your answer
![](https://koobas.hobune.stream/wayback/20220613115250im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making Portal-Like Objects 2 Answers
Portal effect using render textures: how should I move the camera? 2 Answers
True Portal Effect 1 Answer
create a portal with texture render 3 Answers
Save RenderTarget (Color Format: Depth) into a png as a heightmap 0 Answers