zoukankan      html  css  js  c++  java
  • 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"
    }
  • 相关阅读:
    开发中学习英语
    eclipse 常用快捷键
    eclipse 查看快捷键
    沟通的方式——大道至简第四章读后感
    java练习题——类与对象
    团队与管理方法——大道至简第三章读后感
    java程序——两数的加减乘除
    java练习题
    java程序——从命令行接收多个数字,求和之后输出结果
    李冰烧山——大道至简第二章读后感
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/4810716.html
Copyright © 2011-2022 走看看