I would like to mask a camera to only render to a certain (non-square) region of the screen, to be used as an overlay, for splitscreen, or any other application.

The goal is obviously to prevent any unnecessary rendering from that camera, so I specified performance, but I'm also happy to hear the easiest to implement option as well.

What I'm considering so far:

  1. Stencil shader on a mesh in front of the camera - but my understanding is that doing so would require modifying all shaders on world objects, which isn't ideal. Is there an easier way I'm missing?
  2. Transparent mesh with a cutout - I could cut out a hole in a mesh and the solid part would block rendering of objects behind it, but I'm not sure how to make that part be transparent so other things can render

I'm using Unity 2019 LTS and the built-in render pipeline

I feel like there must be a simple answer I'm missing but maybe I'm wrong?

  • \$\begingroup\$ Can you tell us a bit about the shape of this camera view, what it represents, and what's rendered around/outside it? There may be easier or more complicated options depending on those specifics. \$\endgroup\$
    – DMGregory
    Commented Mar 29, 2021 at 23:53
  • \$\begingroup\$ Sure, it's for a voronoi splitscreen system. So multiple cameras would be rendering to their own screen regions, the shape of which could change moment to moment. I could render one camera as fullscreen and the others on top of it, or all could be masked. Does that help? \$\endgroup\$ Commented Mar 29, 2021 at 23:58
  • \$\begingroup\$ I don't think that putting something like a transparent mesh with a cutout in front of the camera as a sort of mask will actually cull anything behind the mesh; in other words, the engine would still render everything and simply draw the mask over the other rendered graphics. There would be no performance savings. See docs.unity3d.com/Manual/OcclusionCulling.html \$\endgroup\$
    – Kevin
    Commented Mar 30, 2021 at 0:04
  • \$\begingroup\$ What render pipeline are you using? \$\endgroup\$
    – Kevin
    Commented Mar 30, 2021 at 0:16
  • \$\begingroup\$ @Kevin The built in render pipeline in 2019 LTS, sorry I forgot mention it! \$\endgroup\$ Commented Mar 30, 2021 at 0:46


You must log in to answer this question.

Browse other questions tagged .