tonynogo

Demo 30 - Picture in picture

Jul 6th, 2017
2,898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/PictureInPicture" {
  2.     Properties {
  3.         _MainTex ("Base (RGB)", 2D) = "white" {}
  4.         _SecondaryTex ("Secondary Texture", 2D) = "white" {}
  5.         _GreenThreshold ("GreenThreshold", Range(0, 1.0)) = 0
  6.         _BlueThreshold ("BlueThreshold", Range(0, 1.0)) = 0
  7.         _RedThreshold ("RedThreshold", Range(0, 1.0)) = 0
  8.     }
  9.     SubShader {
  10.         Pass {
  11.             Tags { "RenderType"="Opaque" }
  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.                 float2 uv2 : TEXCOORD1;
  22.             };
  23.  
  24.             sampler2D _MainTex;
  25.             float4 _MainTex_ST;
  26.             sampler2D _SecondaryTex;
  27.             float4 _SecondaryTex_ST;
  28.  
  29.             v2f vert(appdata_base v) {
  30.                 v2f o;
  31.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  32.                 o.uv1 = TRANSFORM_TEX(v.texcoord, _MainTex);
  33.                 o.uv2 = TRANSFORM_TEX(v.texcoord, _SecondaryTex);
  34.                 return o;
  35.             }
  36.  
  37.             float _GreenThreshold;
  38.             float _BlueThreshold;
  39.             float _RedThreshold;
  40.            
  41.             fixed4 frag(v2f i) : COLOR {
  42.                 fixed4 col1 = tex2D(_MainTex, i.uv1);
  43.                 fixed4 col2 = tex2D(_SecondaryTex, i.uv2);
  44.                 fixed val = floor(1 - saturate(col1.r - _RedThreshold))
  45.                 * floor(1 - saturate(col1.b - _BlueThreshold))
  46.                 * saturate(col1.g + _GreenThreshold);
  47.                 return lerp(col1, col2, val);
  48.             }
  49.  
  50.             ENDCG
  51.         }
  52.     }
  53.     FallBack "Diffuse"
  54. }
Advertisement
Add Comment
Please, Sign In to add comment