Shader "UI/AvatarCutout" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" { }
_Mask ("Culling Mask", 2D) = "white" { }
_Cutoff ("Alpha cutoff", Range(0.000000,1.000000)) = 0.100000
}
SubShader {
Tags { "QUEUE"="Transparent" }
Pass {
Tags { "QUEUE"="Transparent" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#pragma multi_compile_fog
#define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
// uniforms
float4 _Mask_ST;
float4 _MainTex_ST;
// vertex shader input data
struct appdata {
float3 pos : POSITION;
float3 uv0 : TEXCOORD0;
};
// vertex-to-fragment interpolators
struct v2f {
fixed4 color : COLOR0;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if USING_FOG
fixed fog : TEXCOORD2;
#endif
float4 pos : SV_POSITION;
};
// vertex shader
v2f vert (appdata IN) {
v2f o;
half4 color = half4(0,0,0,1.1);
float3 eyePos = mul (UNITY_MATRIX_MV, float4(IN.pos,1)).xyz;
half3 viewDir = 0.0;
o.color = saturate(color);
// compute texture coordinates
o.uv0 = IN.uv0.xy * _Mask_ST.xy + _Mask_ST.zw;
o.uv1 = IN.uv0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
// fog
#if USING_FOG
float fogCoord = length(eyePos.xyz); // radial fog distance
UNITY_CALC_FOG_FACTOR(fogCoord);
o.fog = saturate(unityFogFactor);
#endif
// transform position
o.pos = UnityObjectToClipPos(IN.pos);
return o;
}
// textures
sampler2D _Mask;
sampler2D _MainTex;
fixed _Cutoff;
// fragment shader
fixed4 frag (v2f IN) : SV_Target {
fixed4 col;
fixed4 tex, tmp0, tmp1, tmp2;
// SetTexture #0
tex = tex2D (_Mask, IN.uv0.xy);
col = tex;
// SetTexture #1
tex = tex2D (_MainTex, IN.uv1.xy);
col.rgb = tex;
col.a = col.a;
// alpha test
if (col.a < _Cutoff) clip(-1);
// fog
#if USING_FOG
col.rgb = lerp (unity_FogColor.rgb, col.rgb, IN.fog);
#endif
return col;
}
// texenvs
//! TexEnv0: 01010000 01010000 [_Mask]
//! TexEnv1: 01010000 01040004 [_MainTex]
ENDCG
}
}
}