Character Shader 含半透明及受击效果

 
//Character Shader With Hurt Flare and FlareColor
//Author  yellowcrayon@163.com
Shader "DreamFaction/Characters/CharacterV3" {
    Properties {
        [MaterialToggle] _Flare ("Flare", Float ) = 0
        _FlareColor ("FlareColor", Color) = (0.5,0.5,0.5,1)
        _Cutoff ("Alpha Cutoff", Range (0,.9)) = .5   
        _MainTex ("MainTex", 2D) = "white" {}
     
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="AlphaTest"
            "RenderType"="TransparentCutout"
        }
        
        
        Pass {
            Name "ForwardBase"
            Tags{
                "LightMode" = "ForwardBase"
            }

            Lighting off
            Cull off       
            LOD 200

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            uniform sampler2D _MainTex; 
            uniform fixed4 _MainTex_ST;
            uniform fixed _Flare;
            uniform fixed4 _FlareColor;
            uniform fixed _Cutoff;
            
            struct VertexInput 
            {
                fixed4 vertex : POSITION;
                fixed3 normal : NORMAL;
                fixed2 texcoord0 : TEXCOORD0;
            };
            
            struct VertexOutput 
            {
                fixed4 pos : SV_POSITION;
                fixed2 uv0 : TEXCOORD0;
                fixed4 posWorld : TEXCOORD1;
                fixed3 normalDir : TEXCOORD2;
            };
            
            VertexOutput vert (VertexInput v) 
            {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.normalDir = mul(_Object2World, float4(v.normal,0)).xyz;
                o.posWorld = mul(_Object2World, v.vertex);
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                return o;
            }
            
            fixed4 frag(VertexOutput i) : Color 
            {
                i.normalDir = normalize(i.normalDir);
                
                /// Vectors:
                float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
                float3 normalDirection = i.normalDir;

                // Reverse normal if this is a backface
                float nSign = sign( dot( viewDirection, i.normalDir ) ); 
                i.normalDir *= nSign;
                normalDirection *= nSign;
                
// Lighting:
                fixed4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
                
                fixed if_leA = step(_Flare, _MainTex_var.rgb);   //_Flare > _MainTex_var.rgb return 0 else 1
                
                fixed if_leB = step(_MainTex_var.rgb, _Flare);
                
                fixed3 if_blend = (_MainTex_var.rgb  + ( pow(1.0 - max(0,dot(i.normalDir, viewDirection)),2.0) * _FlareColor.rgb*3.0) );          
                
                fixed3 finalColor = (if_leA * _MainTex_var.rgb ) + (if_leB * if_blend);             

                clip(_MainTex_var.a - _Cutoff);
                
                return fixed4(finalColor,_MainTex_var.a);                
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}

转载于:https://www.cnblogs.com/JimmyCode/p/4810716.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值