Search Unity

Fading a basic shader

Discussion in 'Shaders' started by eco_bach, Apr 2, 2017.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Using a customised version of a 'x-ray' shader from the excellent 'Makin Stuff Look Good' series

    I need to simply fade or mask it out(would prefer to fade) thru code.

    Can any shader gurus help?

    Code (csharp):
    1.  
    2. Shader "XRay Shaders/Diffuse-XRay-Replaceable"
    3. {
    4.     Properties
    5.     {
    6.         _Color("Main Color", Color) = (1,1,1,1)
    7.         _EdgeColor("XRay Edge Color", Color) = (0,0,0,0)
    8.         _MainTex("Base (RGB)", 2D) = "white" {}
    9.     }
    10.  
    11.     SubShader
    12.     {
    13.         Tags
    14.         {
    15.             "Queue" = "Geometry-1"
    16.             "RenderType" = "Opaque"
    17.             "XRay" = "ColoredOutline"
    18.         }
    19.         LOD 200
    20.         //ADDED
    21.         Stencil
    22.     {
    23.         Ref 1
    24.         Comp Always
    25.         Pass Replace
    26.         //ZFail Keep
    27.         ZFail Replace
    28.     }
    29.         //END CHANGE
    30.  
    31.         CGPROGRAM
    32.         #pragma surface surf Lambert
    33.  
    34.         sampler2D _MainTex;
    35.         fixed4 _Color;
    36.  
    37.         struct Input {
    38.             float2 uv_MainTex;
    39.         };
    40.  
    41.         void surf(Input IN, inout SurfaceOutput o)
    42.         {
    43.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    44.             o.Albedo = c.rgb;
    45.             o.Alpha = c.a;
    46.         }
    47.         ENDCG
    48.     }
    49.    
    50.     Fallback "Legacy Shaders/VertexLit"
    51. }
    52.  
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
  3. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Awesome, thanks!