Search Unity

Unity UI Shader that hides what is behind it.

Discussion in 'UGUI & TextMesh Pro' started by User340, Jul 16, 2017.

  1. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Does anyone have a UI shader that essentially cuts a hole in the UI? I tried the DepthMask shader from the wiki with no luck. Everything behind the image would be invisible revealing the camera that is behind.
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    You can achieve that through various means, wither using a RestMask2D with the appropriate image.
    Or alternatively use the Soft Alpha Mask UI component in the Unity UI Extensions project (link in signature) which can use alpha masking to mask an image.

    hope that helps.
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I don't believe a Mask can achieve this effect. To clarify, I am having my Camera's viewport rect conform to a RectTransform as if it were an image itself. This is why I would like my camera to essentially block the UI controls that are behind it.
     
  4. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
  5. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    294
    I am trying to achieve this exact same effect. Been googling but can't find anything. Anyone got any ideas?
     
    User340 likes this.
  6. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    With 3D objects the DepthMask shader does exactly this. For some reason it just doesn't work w/ the UI system.
     
  7. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    294
    Sadly, I specifically need it to work with the UI, actually, probably only on the UI. My use case it actually exactly the same as yours was. Camera's render position and size is set by a rectTransform, and I want to remove all the UI within that rect.