title: Cutting holes through UI images in Unity using stencil buffers and shaders
body: <p>There is a way to make holes in Unity, aka an x-ray vision, see the figure below:
  <a href="https://i.stack.imgur.com/e8JSc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e8JSc.png" alt="orange frame x-raying through the wall" /></a>
  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.</p>
  <p>Configuration A (cutter):</p>
  <pre><code>        ColorMask 0
          ZWrite Off
  
          Stencil {
               Ref 1
               Comp always
               Pass replace
          }
  </code></pre>
  <p>Configuration B (target):</p>
  <pre><code>        Stencil {
               Ref 1
               Comp notequal
               Pass keep
          }
  </code></pre>
  <p><strong>Question 1</strong>: 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 &quot;window/hole&quot;? The image on the UI layer has the <em>Default UI Material</em> with the <em>UI/Default</em> shader and it is impossible to add a custom shader to it.</p>
  <p>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: <a href="https://youtu.be/pxjpWPJo8vM?t=29" rel="nofollow noreferrer">https://youtu.be/pxjpWPJo8vM?t=29</a></p>
  <p><strong>Question 2</strong>: 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.</p>
  <p><strong>Question 3</strong>: 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?</p>