Skip to content

Instantly share code, notes, and snippets.

@thallippoli
Created January 31, 2013 11:23
Show Gist options
  • Save thallippoli/4682218 to your computer and use it in GitHub Desktop.
Save thallippoli/4682218 to your computer and use it in GitHub Desktop.
Simple parameter based blink shader in Unity
Shader "Custom/Blink" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Blink ( "Blink", Float ) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float _Blink;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex );
if( _Blink == 1.0f )
c *= ( 0.5f + abs( sin( _Time.w ) ) );
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
@metars
Copy link

metars commented Aug 2, 2016

i added simple code for tint color and no alpha

Shader "Custom/Blink" {
Properties {
_MainTex ("Particle Texture", 2D) = "red" {}
_Blink ( "Blink", Float ) = 0
_Color("Color", Color) = (1,1,1)
}

SubShader {
     Tags {"RenderType"="Transparent" "Queue"="Transparent"}
    Blend SrcAlpha One

    CGPROGRAM
    #pragma surface surf Lambert

    sampler2D _MainTex;
    float _Blink;
    float3 _Color;

    struct Input {
        float2 uv_MainTex;
    };

    void surf (Input IN, inout SurfaceOutput o) {
        half4 c = tex2D (_MainTex, IN.uv_MainTex );
        if( _Blink == 1.0f ) 
            c *=  ( 0.5f + abs( sin( _Time.w ) ) );
        o.Albedo    = c.rgb*_Color;
        o.Alpha     = c.a;
    }
    ENDCG
} 
FallBack "Diffuse"

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment