Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
3  
I can't find the reference, but I remember somebody saying that Portal didn't use render to texture for that. –  msell Mar 21 '13 at 17:56
1  
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. –  Vasco Correia Mar 21 '13 at 18:45
7  
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. –  Stig-Rune Skansgård Mar 22 '13 at 7:49
1  
For the visual effect what approach did you take? Did you figure out how to render only what was visible through the portal? –  jhocking Apr 3 '13 at 23:44
1  
You should keep the original question as it was and ask a new question about the new problem. –  msell Apr 4 '13 at 5:11
show 7 more comments

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.