Search Unity

Question UI mask using "Render Objects"?

Discussion in 'Universal Render Pipeline' started by Josiah_Ironclad, Oct 27, 2021.

  1. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    I'm trying to mask a specific UI object outside another, while leaving everything else alone.

    I.e.:
    upload_2021-10-28_17-5-20.png
    (btw, both objects inside the mask are children of the mask object)

    There will be multiple of the mask object, but only one red object.

    Mask components and shaders (I think) won't work since I need the mask to affect a single specific object, and the red object doesn't have a sprite, (it's literally just a colored rectangle). So I'm trying to use the experimental (at least in 2020.3.10f1) Render Objects in the URP asset_renderer.

    I tried following this Unity manual/docs page as a start, and it works perfectly for any 3D object, but not for UI (Unity UI/UGUI, whatever it's called). And yes, I did use the Transparent Layer Mask in the filtering, and set my Render Feature's queue to Transparent, as opposed to following the page's screenshots verbatim.

    Something I found out while randomly changing the options, is that if I try preventing my custom "Background" layer from rendering (which I have the desired object as), nothing happens, but if I instead (or also) unselect the default "UI" layer from the Transparent Layer Mask, the UI instantly disappears.

    Been trying to make this work for the past 2-3 days, still as clueless as when I started.
     
    Last edited: Oct 28, 2021
  2. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    78
    Did you get anywhere with this mate?
     
  3. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    I just made the red object (simple flat color image object) be a certain size. It links into the overarching system this was being made for.

    So I get the top-left of the red object, and make its size as much as it needs to be for the bottom and right sides to touch the edges of the big background (mask) object. It works because it's all simple squares on a grid. Every time I move the visible object, the red object snaps to the grid. If it's at [9,9] and the background size is [10,10], then I know it'll need to be [2,2] in width and height in grid coords to cover its and the remaining grid cells, then I convert that to whatever pixel scale I'm using for it to not just be 2x2 pixels big.
    I also did lots of checks like if the visible object was completely outside the background, the red object would have a size of 0.

    tl;dr: I ended up not using any kind of masking or stencil shading, just made the red object change size so it looks like it's not going outside of the grey background. It works because both are squares so there's no warping visible.