Unity3d《Shader篇》Logo闪光特效

Shader "Custom/Flash" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Color("Diffuse Material Color", Color) = (1,1,1,1)
        _Width("Width", Float) = 0.2
        _Speed("Speed", Float) = 10.0
        _Angle("Angle", Float) = 0.1
    }
    
    SubShader {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
        Blend SrcAlpha OneMinusSrcAlpha
        //AlphaTest Greater 0.1
        
        
        Pass
        {
            CGPROGRAM
// Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members uv)
#pragma exclude_renderers d3d11 xbox360
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"

            sampler2D _MainTex;
            float4 _Color;
            float _Width;
            float _Speed;
            float _Angle;
            
            struct v2f {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
            };

            v2f vert(appdata_base v)
            {
                v2f o;
                o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
                o.uv = v.texcoord;
                return o;
            }
            
            float4 frag(v2f i):COLOR
            {
                float width = _Width*0.5;
                float4 col = tex2D(_MainTex,i.uv);
                
                float pivot = _Time.y*_Speed;
                //pivot = pivot+i.uv.y*tan(_Angle);
                pivot = pivot-floor(pivot);
                
                float diff = i.uv.x-pivot;
                
                float4 flashCol = _Color;
                if(0==col.w)
                {
                    flashCol.w = 0;
                }
                
                if(abs(diff)<width)
                {
                    if(diff<0)
                    {
                        col = lerp(col,flashCol,(width+diff)/width);
                    }
                    else if(diff>=0 )
                    {
                        col = lerp(flashCol,col,diff/width);
                    }
                }
                return col;
            }
            
            ENDCG
        }

    } 
    FallBack "Diffuse"
}
原文地址:https://www.cnblogs.com/mrblue/p/4597633.html