Search Unity

Question Intersections but only for certain objects

Discussion in 'Shader Graph' started by alanmthomas, Jan 20, 2020.

  1. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    197
    I'm attempting to create an intersection shader using shader graph. That part is easy as there are plenty of tutorials available. The part that I'm running into difficulties with is having that intersection only affect certain objects. For example, let's say I have objects on a layer called "ground". I have others on a layer called "sensors". Then there are yet other objects on other layers. I'd like to be able to render only the intersections between ground and sensors. In the image below, the off-white section is on the ground layer. the yellow box on the sensors layer. Ideally, the yellow box wouldn't render, rather it would color the off-white section yellow where they intersect. The pink area that is currently obscured would be completely visible.

    Does anyone have any suggestions? I feel like something like this should be doable but I'm not able to get my head around it.

    Thanks!
     

    Attached Files:

  2. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Is that what you mean:
    https://forum.unity.com/threads/intersection-shader-cull-front-minus-cull-back.536812/ ?
    If you apply the shader from this thread to the yellow box the box would not be visible, only the intersection surfaces with other objects.
    Then if you dont't like to get any intersection on red, apply stencil mask 1 to it.
    This works for standard render pipeline, but it should also be possible to get it working in URP or HDRP.
     
  3. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    197
    That's it! Thanks so much!
     
    tomekkie2 likes this.
  4. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    In order to get it to work with URP or LWRP you could just split the triple pass shader into separate shaders. Then you can put these three materials on the intersection object. Or you can setup a custom renderer and define RenderObjects feature to get the intersection layer render multiple times.