Search Unity

Question Color intersect shader

Discussion in 'Shader Graph' started by WakeZero, Feb 12, 2020.

  1. WakeZero

    WakeZero

    Joined:
    Dec 18, 2014
    Posts:
    7
    I use a shader for the builtin pipeline that colors only the intersections of an object like so:

    ColorIntersectBRP.png

    Is this possible to do with the URP, and if so how? Here is the current shader:

    Code (CSharp):
    1. Shader "Custom/ColorIntersect" {
    2.     Properties {
    3.         _Color("Color", Color) = (1, 0, 0, 0.5)
    4.     }
    5.     SubShader {
    6.         Tags {"RenderType"="Opaque" "Queue"="Overlay"}
    7.         LOD 100
    8.         ZWrite Off
    9.        
    10.         Pass {
    11.             Cull Back
    12.             ZTest Greater
    13.             ColorMask 0
    14.             Stencil {
    15.                 Ref 1
    16.                 Comp Always
    17.                 Pass Replace
    18.             }
    19.         }
    20.        
    21.         Pass {
    22.             Cull Off
    23.             ZTest Greater
    24.             Blend SrcAlpha OneMinusSrcAlpha
    25.             Stencil {
    26.                 Ref 0
    27.                 Comp Equal
    28.                 Pass IncrSat
    29.                 Fail IncrSat
    30.             }
    31.             CGPROGRAM
    32.             #pragma vertex vert
    33.             #pragma fragment frag
    34.             #include "UnityCG.cginc"
    35.             struct appdata {
    36.                 float4 vertex : POSITION;
    37.             };
    38.             struct v2f {
    39.                 float4 vertex : SV_POSITION;
    40.             };
    41.             fixed4 _Color;
    42.             v2f vert (appdata v) {
    43.                 v2f o;
    44.                 o.vertex = UnityObjectToClipPos(v.vertex);
    45.                 return o;
    46.             }
    47.             fixed4 frag (v2f i) : SV_Target {
    48.                 return _Color;
    49.             }
    50.             ENDCG
    51.         }
    52.  
    53.         Pass {
    54.             ZTest Greater
    55.             ColorMask 0
    56.             Stencil {
    57.                 Ref 0
    58.                 Comp Always
    59.                 Pass Zero
    60.             }
    61.         }
    62.     }
    63. }
    Any help is appreciated, thank you!