Jump to content

The Protal Effect/Offscreen Rendering


Recommended Posts

Howdy my dudes,

I've been taking at a stab at building out a "portal" type shader for a few days now, and I'm pretty stuck. To elaborate, the goal is to basically to render from a second camera onto a texture (or render buffer), and then project it onto a piece of geometry to be rendered like any other object. Thus creating the illusion of looking into one portal, and out of a second portal (just like the game Portal). I've already solved rendering from the perspective of the other camera (I think.... I basically rebuilt fromNDC() in /mat/), however I'm currently stuck on how to project it properly back onto the geometry.


Let's define the current render camera as "CameraA" and the second, portal camera as "CameraB" for ease of explanation.


The issue that I'm running into is that the method I'm using requires me to sample the rendered scene from CameraB, as a texture. The reasoning being, that we need to clip the texture to make sure we're not looking at a squashed scene, but rather a scene that's clipped by the bounds of the portal geometry. However as far as I'm aware, there's nothing like Unity's render targets in Houdini. You could argue that, that's the purpose of the Render COP, however it's far slower than just shooting more rays into the scene from CameraB. Mestela sent me this lovely video by Roman Saldygashev in which he achieved the effect in mantra, so i know it's possible. 


For even more context, I've been following along with this post by Tom Hulton and his implementation in Unity, http://tomhulton.blogspot.com/2015/08/portal-rendering-with-offscreen-render.html

Though in the attached file, I don't include the camera matching transformations he describes, let's just focus on the portal rendering....

I'm going to attach my test file to this post so all the smart people here can rip it to shreds. Please let me know if you think I'm totally approaching this problem incorrectly as well, as shader math is certainly not my strongest skill... 

 

If anyone has a link to the "Stupid RenderMan Tricks" pdf that inspired both Roman's effect and Tom's effect, that'd be incredible, because all searches on my end have turned up empty, so i'm kinda just winging it right now.

 

JR_PORTALS_v004.hipnc

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Follow-Up: So I've been spinning my wheels on this for another week and really don't have a ton to show for it. I'm attaching the latest pass, I believe I've gotten the camera transforms all worked out, but i still really don't understand the clip-space portion of the problem. My current method is to use camera projected UV's as a way to define the clip space, and it seems pretty close. But it's definitely incorrect. I'm currently building it purely in SOPs as it's way to hard to debug rotations in /mat/, so hopefully this'll be easier to read/help with.  

image.png

JR_PORTALS_v007_ODFORCE.hipnc

Link to comment
Share on other sites

Hi Jake,

Unfortunately, I don't have access to that project file, but the trick is quite simple:

The portals are just objects with their transforms, the planes need to get catch incoming rays.

The algorithm is basically this:

1. transform incident direction and position from camera space to the input portal space

2. rotate them by 180 degrees

3. transform them again from the input portal space to the output portal space

4. trace a ray using the resulting values

Teleporting light is a bit more tricky, as it requires custom illuminance loops (usual shaders will not work), but principles the same: transform light sample positions. Teleporting shadow is even more complicated: a custom shadow ray should be traced from specific position.

To teleport displacement you just need to transform position, but portals boundaries should be checked.

Here is the slides from Stupid RenderMan Tricks.

prmanPortalsPresentation_RP_2008.pdf

Edited by rsd
Link to comment
Share on other sites

  • 2 months later...

Wow, I am so sorry I didn't respond to your post in a timely manner! I'm only like 2 months late... Thank you so much for posting the PDF to the portals presentation, it was quite illuminating. Someone actually reached out with a correct solution (minus light teleportation), which put a swift end to all of my struggling. Keven Weber  is the man who solved all my issues, along with the help of @toadstorm. I've attached the project file below if anyone is curious about it. 

Thanks again for responding 

KW__Portals.hipnc

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...