Hide mesh walls for portal effect

Hello, guys! I am making a portal effect and planing to place a cube map at the bottom of the “can”, and side walls would be of panning material with distortion. The problem is I don’t know how to get rid of outer walls that should not be visible.

On screenshot below marked these with X. In other words I would love to have sort of a pocket, that that you can look into only from particular side and should be invisible from other directions. Sort of Harry Potter Invisibility Cloak :slight_smile:

Not super straightforward with how rendering works.
The fragments in the back don’t really have context to figure out if they are obscured or not.

One option would be to draw into the depth buffer, then when drawing the shape, check if it is obscured by the depth buffer or not, you could then also use that same depth buffer to figure out if other elements behind the portal should draw in font, inside, or behind it

I think I’ve seen some people use shape functions to do something similar as well

Thank you for the hint. Watched few videos about stencil buffer, looks like it could help. But did not manage to do it so far, I can only paint the whole thing even it is obscured by other meshes.
Looks like I need depth but not stencil buffer, will investigate further.

You could split the mesh into a cap and inside mesh, draw the cap into the stencil buffer, then draw the inside mesh only where the stencil is

maybe you can fake it with a camera on the other side of the wall, capture this camera to render target and just place it masked into the middle of the portal.

Yeah, render target could work, but its performance heavy.

I continued experimenting with stencil buffer and understood that post process material can not help me. Because the picture is already rendered when it is input in post process, so it can not know what is below the surface we would like to discard. May be I am wrong?

Another way is trying to make sort of opacity mask for black hole material, and somehow it should be dependent on cap position.

This is a possible solution, beautiful but heavy on performance, it works!
Youtube: UE4 Tutorial: How To Build A Seamless Unreal Portal Door

I think I would stick with TextureSample+Reflection vector Material. Its not dynamic and has no real depth but very light.

Did it with custom stencil!

Hey there,
I know you already solved it with a custom stencil, but another option could be to just use a TwoSidedSign and then a one minus depending on the direction your normals are facing.


Here’s an example with a couple open cylinders, the top one with a normal mat and the bottom one with the material set up on the right.

2 Likes

Thank you! I tried your method but nothing happened.

I wanted to get the following result: red shaded part should not be visible at all, only its internal part and only when looked from the “hatch”, and the one in blue circle should be visible.

Oh, I see. Sorry, I thought you were only trying to hide the faces on the one side of the cylinder. Pay no attention to me :sweat_smile: