Search Unity

Question How to render a transparent object on top of other objects with URP pipeline and ARFoundation?

Discussion in 'Shaders' started by lele1592, Nov 29, 2022.

  1. lele1592

    lele1592

    Joined:
    Sep 10, 2018
    Posts:
    4
    Hi there!

    I am looking for a solution that allows for rendering a transparent object on top of other objects (which will be hidden through a shader mask).

    What happens with this is the following:

    upload_2022-11-29_16-51-15.png

    First, I used mask shader and then I set up a dithering shader to the box (in red) through the URP pipeline.
    upload_2022-11-29_16-52-16.png

    Unless the shader also renders inside the box ( I don't want to do this), this solution works on Editor, but when it runs on mobile platforms (both IOS and ANDROID) it substitutes a uniform white color to the red box.

    Any ideas?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,043
    Is there a reason to use dithering and not transparent?
    Seeing how it should look is also helpful.
    Which unity version?
     
  3. lele1592

    lele1592

    Joined:
    Sep 10, 2018
    Posts:
    4
    Thank you for your reply.
    I am using Unity 2022.1.23f1.

    Actually, there is no reason why I am using dithering instead of the transparent shader. Some days ago, I was using Unity 2021, dithering was working fine by rendering only front faces to the camera, while with transparent also inside faces was rendering (I don't want this). With the new version of Unity, also dithering renders internal faces.

    However, in this case, I'd like to see:

    1. The yellow cube (opaque and transparent) in front of the grey box;
    2. Delete grey box pixels inside the yellow cube;
    3. Render only the outside faces of the yellow cube;




    Thanks a lot!
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,043
    Ahh now I understand.
    Maybe use stencil buffers to do this?
    Some stencil portal tutorials might be helpful
     
  5. lele1592

    lele1592

    Joined:
    Sep 10, 2018
    Posts:
    4
    Yes, thank you. I will try to do that.

    In the meantime, I tried working on it and it seems to work quite well.
    It's strange but when I build the app on both IOS and Android devices running ARFoundation, the cube with the mask shader applied doesn't work and is recolored with the white color.
    Maybe it is not compatible with the ARBackground feature in my rendering pipeline?
    Do you have any ideas?
     
    Last edited: Nov 30, 2022
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,043
    I am not sure what you mean exactly.

    I have worked with stencil here for AR portals:


    Using this system: