Search code examples
c#unity-game-engineshader

How can I make a shader that makes the intersection of two 3D objects transparent?


I need a shader that can make intersection of two 3D objects transparent. I know how can I make two sprites intersection area transparent. I use stencil buffer in shader. But I don't know how I can do this in 3d objects. Please help me , thank you!

enter image description here


Solution

  • you can work with 3 objects, and use the stencil buffer to do the effect.

    One of the objects will have

    Stencil{
       Ref valueA
       Comp aways
       Pass replace
    }
    

    the second:

    Stencil{
       Ref valueB
       Comp greater
       Pass replace
    }
    

    the third:

    Stencil{
       Ref valueB
       Comp less
       Pass replace
    }
    

    the trick is to put the second and third object in the same position