10
\$\begingroup\$

EDIT: So I've gotten the portal visual effect working with no performance hit, and I've got the physics set up of objects with rigidbodies moving through portals seamlessly, and objects with character controllers moving through it seamlessly. The only thing I'm trying to figure out now is blending two camera views to get the proper first person transition effect. Any ideas on how I'd blend those two? I'm thinking something using a depth only shader, or the normalized viewport rect. My main problem is calculating that in real time, and with angles.

So I've been working on creating a portal effect in Unity3D. Obviously I've taken Valve's Portal as a great influence to programming this. Currently I'm simply using a camera's rendertexture to get the graphical effect across, and then some code to do the rest. The problem is at 2048x2048 it looks as high quality as Portal's, but causes heavy FPS loss. To solve this I'd either have to lower the texture quality or the number of times I update the texture.

Valve has accomplished a high quality portal effect without causing high frame rate loss. How can I do the same? Does anybody have any good ideas for rendering to a high resolution texture without causing frame loss?

I'm considering making my own code for rendering to textures rather then using Unity's built in system, it's doable but would definitely be a hassle. So any thoughts, ideas, or suggestions are highly appreciated.

\$\endgroup\$
13
  • 3
    \$\begingroup\$ I can't find the reference, but I remember somebody saying that Portal didn't use render to texture for that. \$\endgroup\$
    – msell
    Commented Mar 21, 2013 at 17:56
  • 1
    \$\begingroup\$ Check out Pseudo Form, a Portal-esque game (the source is in the main download). There are also other "portal implementations" around the web, but I think this is the most known. Also, play Portal with the developer commentaries on. In some of them, they talk about the challenges of implementing the portals. \$\endgroup\$ Commented Mar 21, 2013 at 18:45
  • 7
    \$\begingroup\$ I can't fathom why you would need a 2028x2048 texture to make a portal rendered at less than 1080p look sharp. You should definitively not need to go above the display resolution you are using for your game in general. I would go so far as to say you should figure out the on-screen size of the portal and use that to select a rendertexture of appropriate size (thus making it very efficient when far away, and "heavier" as the portal gets more screen-space. \$\endgroup\$ Commented Mar 22, 2013 at 7:49
  • 1
    \$\begingroup\$ For the visual effect what approach did you take? Did you figure out how to render only what was visible through the portal? \$\endgroup\$
    – jhocking
    Commented Apr 3, 2013 at 23:44
  • 1
    \$\begingroup\$ You should keep the original question as it was and ask a new question about the new problem. \$\endgroup\$
    – msell
    Commented Apr 4, 2013 at 5:11

1 Answer 1

6
\$\begingroup\$

After hours of research and programming I figured out how to properly get the visual effect for this. If you'd like to just buy a portal system that works for visuals and most everything else you need, check out the Portalizer Unity Package.

I program in C# and that package is in JS, but the logic behind it is incredibly useful and well thought out. In general I followed his logical thinking, with some tweaks for my game and a first person controller.

Essentially what you do is use a modified version of This water shader/script. Have two mirrors in the scene, and have a camera render what it sees in each reflection to the other mirror. You'll need to create a modified transformation matrix to account for the relations between the two portals. To help decrease the performance hit, read This article about near plane clipping. This will help you render only what needs to be seen through the portal.

I may create a more detailed tutorial with pictures and source once I figure out how to blend the cameras properly for a FPS teleport. Right now I'm too exhausted and busy to write a full tutorial and this should suffice because it gives you most of the code needed.

\$\endgroup\$
1
  • \$\begingroup\$ Could you post a link to the repo? \$\endgroup\$
    – Roma Fedor
    Commented Jan 8, 2020 at 22:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .