1

There is a way to make holes in Unity, aka an x-ray vision, see the figure below: orange frame x-raying through the wall This is done using two shaders, one having configuration A (cutter) and another - configuration B (target). The shader with configuration A is put into material A and the shader with configuration B is put in material B. Material A is applied to some plane with orange borders. Material B is applied to the 3D grey wall. This works while we are talking about 3D components in the worldspace.

Configuration A (cutter):

        ColorMask 0
        ZWrite Off

        Stencil {
             Ref 1
             Comp always
             Pass replace
        }

Configuration B (target):

        Stencil {
             Ref 1
             Comp notequal
             Pass keep
        }

Question 1: how can one cut through the foreground image on the UI layer and show a small part of the 3D worldspace behind through this cut out "window/hole"? The image on the UI layer has the Default UI Material with the UI/Default shader and it is impossible to add a custom shader to it.

For example, in the following video the castle wall would be the foreground UI image, the picture frame would be the cutter in the UI layer, and the singing person would be an active 3D avatar in the worldspace: https://youtu.be/pxjpWPJo8vM?t=29

Question 2: When creating a shader, Unity 2019.4 proposes the following types: Standard Surface shader, Unlit, Image Effect, Compute, and Ray Tracing. Which is the best option for a light-weight shader pair to cut holes through the UI layer image? It seems, all of them have some code that is not useful for making holes.

Question 3: What gameobject would be the best host for the material with the cutter shader(config A)? Is it a 2D sprite, a UI image, a UI panel, something else?

AlexB
  • 33
  • 5
  • I learnt to do this from [this video](https://www.youtube.com/watch?v=cHhxs12ZfSQ) from Quill18. (Video is currently broken for me at the moment, hope it works for you) – Immersive Nov 12 '20 at 01:03
  • @Immersive the video above shows shaders for the worldspace elements and not for the UI layer elements with the Default UI Material and the UI/Default shader – AlexB Nov 12 '20 at 18:35

0 Answers0