扣绿幕Shader(可自选颜色)

Shader "Custom/ChromaKey" {

    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _thresh ("Threshold", Range (0, 16)) = 0.8
        _slope ("Slope", Range (0, 1)) = 0.2
        _keyingColor ("Key Colour", Color) = (1,1,1,1)
    }
    
    SubShader {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
        LOD 100
        
        Lighting Off
        ZWrite Off
        AlphaTest Off
        Blend SrcAlpha OneMinusSrcAlpha 
        
        Pass {
            CGPROGRAM
                #pragma vertex vert_img
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest

                sampler2D _MainTex;
                float3 _keyingColor;
                float _thresh; // 0.8
                float _slope; // 0.2

                #include "UnityCG.cginc"

               float4 frag(v2f_img i) : COLOR{
              float3 input_color = tex2D(_MainTex,i.uv).rgb;
              float d = abs(length(abs(_keyingColor.rgb - input_color.rgb)));
              float edge0 = _thresh*(1 - _slope);
              float alpha = smoothstep(edge0,_thresh,d);
              return float4(input_color,alpha);
              
            
              } 
              
            ENDCG
        }
    } 
    
     FallBack "Unlit/Texture"
}

 

posted @ 2017-12-15 11:15  西湖盗月  阅读(872)  评论(0编辑  收藏  举报