Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Is it possible to mask part of a 3D object that is behind a UI Panel rect?

Discussion in 'General Graphics' started by solmas, Jan 10, 2023.

  1. solmas

    solmas

    Joined:
    Apr 24, 2018
    Posts:
    11
    Hi everyone! This seems like something that is doable but I'm having a difficult time figuring out how to get it to work.

    Issue: I have a text overlay that is positioned directly in front of a 3D object. I need to mask out the pixels of the 3D object that is covered by the text overlay UI object. The UI and 3D objects both use the same camera because it's a legacy project.

    My current setup:

    UI: The text overlay is a child of a panel and I have a reference to the Image component of the parent panel.

    3D Object: I'm writing an (must be) opaque shader with Alpha Clip true in shader graph for the main material in the 3D object. In the graph, I have a Texture2D and Sampler node and is outputting to Alpha Clip.

    Scripts: I have 2 scripts 1) I mentioned previously, this one gets the reference to the UI Panel Image component and 2) is attached to the object with the material that the shader is applied to.

    My thinking is to get the correct reference to the UI Panel Image component and apply the Source Image to the Alpha Clip channel.

    I hope I'm not missing anything in my description, I'm trying to keep it as simple as possible for you all. I am happy to answer any questions you have to clarify.

    Bottom line is that this seems plausible to me but I'm having a bear of a time actually getting it to work. Am I barking up the wrong tree? Is there a better way to accomplish this?

    Any help is much appreciated!
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,367
    A screenshot would help, but I am wondering from your description if it would help to use two separate canvases. One for your text overlays, behind one for all your other UI purposes.
     
  3. solmas

    solmas

    Joined:
    Apr 24, 2018
    Posts:
    11
    Thanks for your response halley! Hopefully this screenshot is useful enough -- I can't offer much more, unfortunately.



    https://www.dropbox.com/s/4kkp0ow7fpxu8xf/buoySnap.PNG?dl=0

    This is a buoy-like object with the text in front of it from the client's mockup references. I have the buoy and the text currently working, but I got feedback from the client requesting the mask cut-out to better separate the text from the buoy object and that is what I'm trying to achieve.

    I have no thoughts on your suggestion for 2 separate canvases -- if you think it might be appropriate and have any tutorial links or anything I'd appreciate having them!
     
    Last edited: Jan 10, 2023