Advertisement
tonynogo

Demo 40 - Video in video green chromaKey

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