Advertisement
tonynogo

Demo 38 - VHS Tape effect

Jul 6th, 2017
11,958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/VHSeffect"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _SecondaryTex ("Secondary Texture", 2D) = "white" {}
  7.         _OffsetNoiseX ("Offset Noise X", float) = 0.0
  8.         _OffsetNoiseY ("Offset Noise Y", float) = 0.0
  9.         _OffsetPosY ("Offset position Y", float) = 0.0
  10.         _OffsetColor ("Offset Color", Range(0.005, 0.1)) = 0
  11.         _OffsetDistortion ("Offset Distortion", float) = 500
  12.         _Intensity ("Mask Intensity", Range(0.0, 1)) = 1.0
  13.     }
  14.     SubShader
  15.     {
  16.         Pass
  17.         {
  18.             CGPROGRAM
  19.             #pragma vertex vert
  20.             #pragma fragment frag
  21.             #include "UnityCG.cginc"
  22.  
  23.             struct v2f
  24.             {
  25.                 float4 pos : SV_POSITION;
  26.                 float2 uv : TEXCOORD0;
  27.                 float2 uv2 : TEXCOORD1;
  28.             };
  29.  
  30.             half _OffsetNoiseX;
  31.             half _OffsetNoiseY;
  32.  
  33.             v2f vert (appdata_base v)
  34.             {
  35.                 v2f o;
  36.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  37.                 o.uv = v.texcoord;
  38.                 o.uv2 = v.texcoord + float2(_OffsetNoiseX - 0.2f, _OffsetNoiseY);
  39.                 return o;
  40.             }
  41.            
  42.             sampler2D _MainTex;
  43.             sampler2D _SecondaryTex;
  44.  
  45.             fixed _Intensity;
  46.             float _OffsetColor;
  47.             half _OffsetPosY;
  48.             half _OffsetDistortion;
  49.  
  50.             fixed4 frag (v2f i) : SV_Target
  51.             {
  52.                 i.uv = float2(frac(i.uv.x + cos((i.uv.y + _CosTime.y) * 100) / _OffsetDistortion), frac(i.uv.y + _OffsetPosY));
  53.                
  54.                 fixed4 col = tex2D(_MainTex, i.uv);
  55.                 col.g = tex2D(_MainTex, i.uv + float2(_OffsetColor, _OffsetColor)).g;
  56.                 col.b = tex2D(_MainTex, i.uv + float2(-_OffsetColor, -_OffsetColor)).b;
  57.  
  58.                 fixed4 col2 = tex2D(_SecondaryTex, i.uv2);
  59.  
  60.                 return lerp(col, col2, ceil(col2.r - _Intensity)) * (1 - ceil(saturate(abs(i.uv.y - 0.5) - 0.49)));
  61.             }
  62.             ENDCG
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement