• 为角色添加遮挡X-Ray显示


    Shader "Characters/CharactersV6"  
    {    
        Properties 
        {
            [MaterialToggle] _Flare ("Flare", Float ) = 0
            _Flarecolor ("Flarecolor", Color) = (0.5,0.32,0.11,1)
    
            _MainTex ("Main (RGB)", 2D) = "white" {}
            _MatCap("Mat (RGB)", 2D) = "white" {}
    
            _BlendTex ("Blend Texture", 2D) = "white" {}
            _Blend ("Texture Blend", Range (0, 1)) = 0 
    
            _RimTex ("Rim (RGB)", 2D) = "white" {}
            _RimColor ("RimColor (RGB)", Color) = (0.5,0.32,0.11,1) 
    
            _Cutoff ("Alpha Cutoff", Range (0,.9)) = .5 
    
            _Hue ("Hue", Float) = 0
            _Saturation ("Saturation", Float) = 0
            _Value ("Value", Float) = 0         
        }
    
        SubShader 
        {
             Tags { "Queue" = "Geometry+500" "RenderType"="Opaque" }
    
            Pass                   //遮挡层pass
            {            
                blend one one      //相加
                ztest greater      //绘制那些深度小于自己的物体
                zwrite off         //关闭像素的深度写入深度缓存
                cull off
    
                CGPROGRAM
    
                #pragma vertex vert
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest
                #include "UnityCG.cginc"
    
                uniform float4 _RimColor;
                uniform sampler2D _RimTex;
    
                struct v2f
                {
                    float4 pos    : SV_POSITION;   //用来标识经过顶点着色器变换之后的顶点坐标
                    float2 cap    : TEXCOORD0;     //用于从顶点程序向片段程序之间传递数据
                };
    
                v2f vert (appdata_base v)
                {
                    v2f o;
                    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    
                    half2 capCoord;
                    capCoord.x = dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal);
                    capCoord.y = dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal);
                    o.cap = capCoord * 0.5 + 0.5;
                    return o;
                }
    
    
                float4 frag (v2f i) : COLOR
                {
                    float4 mc = tex2D(_RimTex, i.cap);
    
                    return _RimColor * mc * 2.0;
                }
    
                ENDCG
            }
            //end pass
    
            Pass //未遮挡层pass 正常显示
            {
                cull off
                 Name "ForwardBase"
                Tags 
                {
                    "IgnoreProjector"="false"
                    "LightMode"="ForwardBase"
                }            
    
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #define UNITY_PASS_FORWARDBASE
                #include "UnityCG.cginc"
                #pragma multi_compile_fwdbase_fullshadows
                #pragma exclude_renderers xbox360 ps3 flash d3d11_9x 
                #pragma target 3.0
    
                uniform sampler2D _MainTex; 
                uniform sampler2D _BlendTex;
                uniform float _Blend;
                uniform float4 _MainTex_ST;
                uniform float4 _BlendTex_ST;
                uniform fixed _Flare;
                uniform float4 _Flarecolor;
                uniform sampler2D _MatCap;
                uniform float _Hue;
                uniform float _Saturation;
                uniform float _Value;
                uniform fixed _Cutoff;
    
                float3 RGB2HSV( float3 RGB )
                {
                    float4 k = float4(0.0, -1.0/3.0, 2.0/3.0, -1.0);
                    float4 p = RGB.g < RGB.b ? float4(RGB.b, RGB.g, k.w, k.z) : float4(RGB.gb, k.xy);
                    float4 q = RGB.r < p.x   ? float4(p.x, p.y, p.w, RGB.r)   : float4(RGB.r , p.yzx);
                    float  d = q.x - min(q.w, q.y);
                    float  e = 1.0e-10;
                    return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
                }
    
                float3 HSV2RGB( float3 HSV )
                {            
                    float4 k = float4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
                    float3 p = abs(frac(HSV.xxx + k.xyz) * 6.0 - k.www);
                    return HSV.z * lerp(k.xxx, clamp(p - k.xxx, 0.0, 1.0), HSV.y);
                }
    
                struct Input 
                {
                    float2 uv_MainTex;
                };
    
                struct VertexInput {
                    float4 vertex : POSITION;
                    float3 normal : NORMAL;
                    float2 texcoord0 : TEXCOORD0;
                };
    
                struct VertexOutput {
                    float4 pos : SV_POSITION;
                    float2 uv0 : TEXCOORD0;
                    float4 posWorld : TEXCOORD1;
                    float3 normalDir : TEXCOORD2;
                    float4 screenPos : TEXCOORD3;
                    float2 cap : TEXCOORD4;
                };
    
                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);
                    o.screenPos = o.pos;
    
                    half2 capCoord;
                    capCoord.x = dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal);
                    capCoord.y = dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal);
                    o.cap = capCoord * 0.5 + 0.5;
    
                    return o;
                }
    
                fixed4 frag(VertexOutput i) : COLOR {
                    #if UNITY_UV_STARTS_AT_TOP
                        float grabSign = -_ProjectionParams.x;
                    #else
                        float grabSign = _ProjectionParams.x;
                    #endif
                    i.normalDir = normalize(i.normalDir);
                    i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
                    i.screenPos.y *= _ProjectionParams.x;
                    float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5 + 0.5;
                    /////// Vectors:
                    float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
                    float3 normalDirection = i.normalDir;
                    ////// Lighting:
    
                    float4 mainTex = tex2D(_MainTex, TRANSFORM_TEX(i.uv0, _MainTex));
                    float4 blendTex = tex2D(_BlendTex, TRANSFORM_TEX(i.uv0, _BlendTex));
    
    
                    //float4 finalTexture = lerp(mainTex, blendTex, _Blend);
                    float4 _MainTex_var = lerp(mainTex, blendTex, _Blend);
    
    
                    float3 node_3262 = RGB2HSV( _MainTex_var.rgb ).rgb;
                    float3 node_9090 = HSV2RGB( float3(float2((_Hue+node_3262.r),(_Saturation+node_3262.g)),(_Value+node_3262.b)) );
                    float  node_3209_if_leA = step(_Flare,node_9090);
                    float  node_3209_if_leB = step(node_9090,_Flare);
                    float3 node_3205 = (node_9090+(pow(1.0-max(0,dot(i.normalDir, viewDirection)),2.0)*_Flarecolor.rgb*3.0));
                    float3 finalColor = lerp( (node_3209_if_leA*node_9090) + (node_3209_if_leB*node_3205) ,node_3205,node_3209_if_leA*node_3209_if_leB);
    
                    fixed4 mc = tex2D(_MatCap, i.cap);
    
                    clip(_MainTex_var.a - _Cutoff);
                    //return saturate (fixed4(finalColor,1) * mc * 1.6);
                    return fixed4(finalColor,_MainTex_var.a) * mc * 1.6;
                }
                ENDCG
            }
            //end pass
    
        }
        //end SubShader
    
        Fallback "Diffuse"   
    }  
  • 相关阅读:
    bug终结者 团队作业第二周
    dropdownlist绑定数据
    virtual与vmware
    后台控制输出table(有数据库)
    label 绑定数据
    flash不能显示中文
    dataset 多表查询
    MVC3 Razor视图引擎基础语法 [转]
    CreateAlias()与setFetchMode() [转 李丽芬]
    Linq Like [转 韩天伟]
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/6727144.html
Copyright © 2020-2023  润新知