Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Gizmo shader

Discussion in 'Shaders' started by tmcsweeney, Jul 16, 2015.

  1. tmcsweeney

    tmcsweeney

    Joined:
    May 24, 2011
    Posts:
    20
    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?
     
  2. tmcsweeney

    tmcsweeney

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

    Code (csharp):
    1. Shader "Hidden/Debug/WireShader" {
    2.     SubShader {
    3.         Pass {
    4.  
    5.             Tags { "RenderType"="Transparent" "Queue"="Transparent"  }
    6.             LOD 200
    7.             Blend SrcAlpha OneMinusSrcAlpha
    8.             Lighting Off
    9.             Cull Back
    10.             ZWrite Off
    11.             ZTest LEqual
    12.             Offset -1, -1
    13.              
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.  
    18.  
    19.             struct appdata {
    20.                 float4 vertex : POSITION;
    21.                 fixed4 color : COLOR;
    22.             };
    23.  
    24.             struct v2f {
    25.                 float4 pos : SV_POSITION;
    26.                 fixed4 color : COLOR;
    27.             };
    28.  
    29.             v2f vert(appdata v) {
    30.                 v2f o;
    31.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    32.                 o.color = v.color;
    33.                 return o;
    34.  
    35.             }
    36.  
    37.             fixed4 frag(v2f i) : SV_Target {
    38.                 return i.color;
    39.             }
    40.             ENDCG
    41.         }
    42.         Pass {
    43.  
    44.             Tags { "RenderType"="Transparent" "Queue"="Transparent"  }
    45.             LOD 200
    46.             Blend SrcAlpha OneMinusSrcAlpha
    47.             Lighting Off
    48.             Cull Back
    49.             ZWrite Off
    50.             ZTest Greater
    51.             Offset -1, -1
    52.              
    53.             CGPROGRAM
    54.             #pragma vertex vert
    55.             #pragma fragment frag
    56.  
    57.  
    58.             struct appdata {
    59.                 float4 vertex : POSITION;
    60.                 fixed4 color : COLOR;
    61.             };
    62.  
    63.             struct v2f {
    64.                 float4 pos : SV_POSITION;
    65.                 fixed4 color : COLOR;
    66.             };
    67.  
    68.             v2f vert(appdata v) {
    69.                 v2f o;
    70.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    71.                 o.color = v.color;
    72.                 o.color.a *= 0.1;
    73.                 return o;
    74.  
    75.             }
    76.  
    77.             fixed4 frag(v2f i) : SV_Target {
    78.                 return i.color;
    79.             }
    80.             ENDCG
    81.         }
    82.     }
    83.     FallBack "Off"
    84. }
    85.  
     
    Last edited: Jul 20, 2015
unityunity