Advertisement
tonynogo

Demo 91 - Chroma key to transparency

Jul 6th, 2017
8,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/GreenToTransparent"
  2. {
  3.     Properties {
  4.         _MainTex ("Base", 2D) = "white" {}
  5.         _Threshold ("Threshold", Range(0, 1)) = 0
  6.     }
  7.     SubShader {
  8.         Pass {
  9.             Tags { "Queue"="Transparent" "RenderType"="Transparent" }
  10.             Blend SrcAlpha OneMinusSrcAlpha
  11.             Cull Off
  12.  
  13.             CGPROGRAM
  14.             #pragma vertex vert
  15.             #pragma fragment frag
  16.             #include "UnityCG.cginc"
  17.  
  18.             struct v2f {
  19.                 float4 pos : SV_POSITION;
  20.                 float2 uv1 : TEXCOORD0;
  21.             };
  22.  
  23.             sampler2D _MainTex;
  24.             float4 _MainTex_ST;
  25.  
  26.             v2f vert(appdata_base v) {
  27.                 v2f o;
  28.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  29.                 o.uv1 = TRANSFORM_TEX(v.texcoord, _MainTex);
  30.                 return o;
  31.             }
  32.  
  33.             float _Threshold;
  34.            
  35.             fixed4 frag(v2f i) : COLOR {
  36.                 fixed4 col1 = tex2D(_MainTex, i.uv1);
  37.                 fixed4 val = ceil(saturate(col1.g - col1.r - _Threshold)) * ceil(saturate(col1.g - col1.b - _Threshold));
  38.                 return lerp(col1, fixed4(0., 0., 0., 0.), val);
  39.             }
  40.  
  41.             ENDCG
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement