Gizmo shader

I’m writing some debug extensions and I want to mimic the look of Unity’s default Gizmos (in particular the way they are partially attenuated by solid geometry).

I can’t find the shader in the builtin_shaders.zip file, and I can’t work out how to get a reference to it.

Does anyone know how to either get a reference to it or what it’s contents are so that I can mimic it?

For want of a better solution I reverse en-guess-ineered the shader and came up with the following, which is pretty close visually:

Shader "Hidden/Debug/WireShader" {
    SubShader {
        Pass {

            Tags { "RenderType"="Transparent" "Queue"="Transparent"  }
            LOD 200
            Blend SrcAlpha OneMinusSrcAlpha
            Lighting Off
            Cull Back
            ZWrite Off
            ZTest LEqual
            Offset -1, -1
             
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag


            struct appdata {
                float4 vertex : POSITION;
                fixed4 color : COLOR;
            };

            struct v2f {
                float4 pos : SV_POSITION;
                fixed4 color : COLOR;
            };

            v2f vert(appdata v) {
                v2f o;
                o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                o.color = v.color;
                return o;

            }

            fixed4 frag(v2f i) : SV_Target {
                return i.color;
            }
            ENDCG
        }
        Pass {

            Tags { "RenderType"="Transparent" "Queue"="Transparent"  }
            LOD 200
            Blend SrcAlpha OneMinusSrcAlpha
            Lighting Off
            Cull Back
            ZWrite Off
            ZTest Greater
            Offset -1, -1
             
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag


            struct appdata {
                float4 vertex : POSITION;
                fixed4 color : COLOR;
            };

            struct v2f {
                float4 pos : SV_POSITION;
                fixed4 color : COLOR;
            };

            v2f vert(appdata v) {
                v2f o;
                o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                o.color = v.color;
                o.color.a *= 0.1;
                return o;

            }

            fixed4 frag(v2f i) : SV_Target {
                return i.color;
            }
            ENDCG
        }
    }
    FallBack "Off"
}
1 Like