- Home /
How to make a 'mirror' and/or 'portal'-like Shader Graph?
Hand crafted a portal-system in Unity (standard render pipeline). Some screenshots: http://electricbrain.eu/dev/portal_ex_0.png and http://electricbrain.eu/dev/portal_ex_1.png . WebGL will be the main platform probably.
this portal-system relies on Camera events like OnPreRender, which does not seem to fire anymore in Lightweight Render Pipeline.
So my question has some partial questions: 1. Is it wise to migrate to the new Lightweight Render Pipeline (LWRP) or not? (my projects will probably not finish soon) 2. Camera events, like OnPreCull and OnPreRender will not work in LWRP? 3. Will it be possible to make a 'portal'-system in LWRP? Do I have to write a custom Render Pipeline to facilitate this? (I hope not, seems awfully complex) 4. I figured, if i can make a 'mirror'-shader, it should be possible to make a 'portal' shader in LWRP. So... I googled, but could not find a 'mirror' Shader Graph for LWRP. Suggestions please?
Answer by Bunny83 · May 05, 2018 at 09:55 AM
Brackeys portal tutorial should give you some hints how you can implement portals with render textures. Yes this approach is a bit ineffective as it simply renders the whole portal camera view to a rendertexture and just displays a portion of it depending on how much can be seen of the actual portal surface. Though this is the easiest way to implement portals.
There are a few things that can be changed though. He simply offsets the camera just in relation of the other portal. For a general portal system this of course doesn't work. You should use TransformPoint / InverseTransformPoint to map the camera position / orientation to the other portal. Next thing is that the near clipping plane should be adjusted to be right behind the exit portal. He designed his two rooms in a way there's nothing in the way for the portal camera. However you want to clip objects between the portal camera and the exit portal. For this you probably want to use an oblique clipping plane.
Further more it would be possible to set a viewport for the portal camera to only render the AABB area of the portal into the render texture. Of course you would need an off-center projection for this. However this is just an optimisation to cut down how much need to be rendered by the portal camera.
Thanks!
This helped me to refactor my portal-system: not using the OnPreRender event in my $$anonymous$$ainCamera made my portals compatible with the new 2018 Lightweight render Pipeline, at least, in the Editor...
(The WebGL version just shows a blue screen, but that's another subject. Sigh...)
Your answer
![](https://koobas.hobune.stream/wayback/20220612162045im_/https://answers.unity.com/themes/thub/images/avi.jpg)