Unity3D Indie (Free) Portal Effect Project Sources

Hello everyone! Due to popular demand finally I’m releasing project sources of the Unity3D Indie Portal Effect. In two words, the technique is based on using multiple cameras (3 in this case) and then selectively drawing just Z-values of the portal gates in the 1st pass so that they leave opening in the rest of geometry due to Z-test. This is followed by the 2nd and 3rd passes which clear Z-values of the portal gates and allow the scene to be drawn in the openings from 2 other cameras. The order of drawing things is managed by camera ordering and render queues ordering. On top of that there is a script positioning the 2 helper cameras appropriately relative to the portal gates and to the main camera. Walking through the portals is handled separately by the teleportation script. Currently it works only for the player but there’s been some effort to teleport rigid bodies as well. I hope you make some really cool games/demos/etc. with this, I’d like to think, smart technique. It requires no stencil, no render to texture, just plain old shaders and multiple cameras. Pretty neat, huh? I insist you let me know if you create something with this technique!!! I’m very very curious to see it put to good use!!! Giving me some credit also wouldn’t hurt ๐Ÿ˜‰ Enjoy!

Binary (Win32): unity_portal_effect.zip

Project Sources: unity_portal_effect_source.zip

29 Comments

  • Dude, thank you so much for this. And thank you so much for giving it away for free. I’ll put you on my game’s credits. ๐Ÿ™‚

  • Hi
    I am creating a game with Unity. I want use your “Portal”-Package and I want to put your Name, how you said, in the Credits, but I doesnt find your Name on this Website. Can you tell me your name please? ๐Ÿ™‚

  • Hi, I played around with the portal effect, and it awesome!
    Just wondering is it possible to have more than 1 set of portal facing different direction? Basically I’m trying to have 4 ‘windows’ on each side of a cube which I can look through it. Each windows will consist 4 different world.
    I want to incorporate this with Vuforia AR, which could look awesome if its achievable.
    Thanks!

    • Yep, it can totally be done but requires encapsulating this portal functionality into some class that will create the portal/camera pairs automatically and assure the global order of rendering. Otherwise you can add more cameras and portals by hand but it will quickly become bothersome, e.g. if you add one more cube you will yet again have to add more portals/cameras. This is just a demo of the technique, done with a Portal-like game in mind (i.e. one pair of portals at a time).

  • Hi, Algoholic! I seem to be having trouble with your package. Do you mind giving me a hand? The portals don’t render correctly (the cameras are looking at wrong directions) if the portals are not face to face each other. Please e-mail me. Thank you!

  • Thanks for the answer. Just a final one. How to I fix the Clipping issue? Say if I place the cube towards a portal. And when I view it in another portal, it has clipping issue on the cube. When I rotate around, part of the cube will be clipped. I tried to change the the Near and Far Clipping planes as well the FOV, it still had the issue.

    Sorry that I need to ask here. Sometimes I have to ask some obvious stupid question in order to learn.

    Thanks.

    • You should use a custom clipping plane defined by the portal surface. Since Unity’s built-in shaders do not support clipping planes in the demo I actually do a little bit of near clipping plane adjustment to imitate a custom one but of course as you play around you will see the artifacts. The only way around this is to write your own shader including the custom clipping plane functionality.

      Or actually you could go with the same trick that portal uses (i.e. writing to depth buffer) but fill the rest of the screen (apart from the portal) with z=0 so that nothing gets drawn there.

      I might release a paid version of this package with all the enhancements mentioned so far. Let me know if you’d be interested in buying it.

  • Hi, Stanislaw.
    Your project is very helpful, and the idea to achieve this effect is just excellent, but I seem to have problems replicating your scene. How do you deal with which camera is rendered on which plane? Because for me always the one of additional cameras with a higher depth will get rendered on both planes :/

    • Make sure you have a second, identical mesh under the main one with the FillZ shader, or whatever it was. That needs to be active on one of the portals. Then make another camera parented to the main camers, set the depth to the camera’s, minus one, and then set it to Depth Only. Have the second mesh on the PortalHelpers2 layer, and make the new camera only render that layer.

  • Hi guys. and thanks for the great assets! ๐Ÿ™‚

    For those who are seeing clipping artifacts… I sort of know why. from the looks of it, it is using a straight camera with the default matrix, which probably won’t look right. I will see if I can reverse the matrix, so an actual reflection appears! ๐Ÿ˜‰

    Of course, this is only useful for mirrors, but it will help remove weird stuff… ๐Ÿ™‚

  • Throwing assets from unity_portal_effect_source.zip in unity,an error has occurred.May be something i did wrong or really was a mistake in the script.I know how to make teleport,but i need to know how to make agencies to show, what can be seen in a different portal.I hope for your help.Sry for bad english.

  • I’m trying to make a doctor who game, so this is essential for the bigger on the inside effect, but I can’t seem to make it work, please help!

    • Hmm it should be comparable. The only thing is with a texture you can render to a smaller one and here we’re always using full resolution.

  • Hello! I love your package, thank you very much for putting it out for free ๐Ÿ˜€
    But i’m having trouble setting it up. I can’t figure out which script goes where, which mesh goes where, which shader goes where etc… I hope you can help me. Regards ๐Ÿ™‚

  • Hi,I am a beginer for Unity3d from China. Your portal’s tutorial is perfect,but it puzzled me too much. Can you give a detailed tutorial on Youtube? Thank you very much for your wonderful work.

  • Very nice and thanks for sharing !
    I’m trying to figure it out ๐Ÿ™‚ and have one question:
    At the end of the FillScreen script you are changing the MeshFilter vertices. I can’t figure out what you are doing, it seems that rendering of that mesh are turned off…


Leave a Reply to vv Cancel reply

Your email address will not be published. Required fields are marked *