Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Shader "ShaderMan/VHS2"
  3.     {
  4.  
  5.     Properties{
  6.     _MainTex ("MainTex", 2D) = "white" {}
  7.     }
  8.  
  9.     SubShader
  10.     {
  11.     Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
  12.  
  13.     Pass
  14.     {
  15.     ZWrite Off
  16.     Blend SrcAlpha OneMinusSrcAlpha
  17.  
  18.     CGPROGRAM
  19.     #pragma vertex vert
  20.     #pragma fragment frag
  21.     #include "UnityCG.cginc"
  22.  
  23.     struct VertexInput {
  24.     float4 vertex : POSITION;
  25.     float2 uv:TEXCOORD0;
  26.     float4 tangent : TANGENT;
  27.     float3 normal : NORMAL;
  28.     //VertexInput
  29.     };
  30.  
  31.  
  32.     struct VertexOutput {
  33.     float4 pos : SV_POSITION;
  34.     float2 uv:TEXCOORD0;
  35.     //VertexOutput
  36.     };
  37.  
  38.     //Variables
  39. sampler2D _MainTex;
  40.  
  41.     #define time _Time.y
  42. #define resolution ( 1 )
  43. #define _MainTex _MainTex
  44. #define gl_FragColor fragColor
  45.  
  46. #define PI 3.14159265
  47.  
  48. float3 tex2D( sampler2D _tex, float2 _p ){
  49.   float3 col = tex2D( _tex, _p ).xyz;
  50.   if ( 0.5 < abs( _p.x - 0.5 ) ) {
  51.     col = float3( 0.1 , 0.1 , 0.1 );
  52.   }
  53.   return col;
  54. }
  55.  
  56. float hash( float2 _v ){
  57.   return frac( sin( dot( _v, float2( 89.44, 19.36 ) ) ) * 22189.22 );
  58. }
  59.  
  60. float iHash( float2 _v, float2 _r ){
  61.   float h00 = hash( float2( floor( _v * _r + float2( 0.0, 0.0 ) ) / _r ) );
  62.   float h10 = hash( float2( floor( _v * _r + float2( 1.0, 0.0 ) ) / _r ) );
  63.   float h01 = hash( float2( floor( _v * _r + float2( 0.0, 1.0 ) ) / _r ) );
  64.   float h11 = hash( float2( floor( _v * _r + float2( 1.0, 1.0 ) ) / _r ) );
  65.   float2 ip = float2( smoothstep( float2( 0.0, 0.0 ), float2( 1.0, 1.0 ), fmod( _v*_r, 1. ) ) );
  66.   return ( h00 * ( 1. - ip.x ) + h10 * ip.x ) * ( 1. - ip.y ) + ( h01 * ( 1. - ip.x ) + h11 * ip.x ) * ip.y;
  67. }
  68.  
  69. float noise( float2 _v ){
  70.   float sum = 0.0;
  71.   [unroll(100)]
  72. for( int i=1; i<9; i++ )
  73.   {
  74.     sum += iHash(_v + float2(i, i), float2(2.0 * pow(2., float(i)), i)) / pow(2.0, float(i));
  75.   }
  76.   return sum;
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.     VertexOutput vert (VertexInput v)
  84.     {
  85.     VertexOutput o;
  86.     o.pos = UnityObjectToClipPos (v.vertex);
  87.     o.uv = v.uv;
  88.     //VertexFactory
  89.     return o;
  90.     }
  91.  
  92.     float4 frag(VertexOutput i) : SV_Target
  93.     {
  94.         float2 uv = i.pos.xy / resolution;
  95.         float2 uvn = uv;
  96.         float3 col = float3( 0.0 , 0.0 , 0.0 );
  97.         float4 outCol = float4(0.0, 0.0, 0.0, 0.0);
  98.           // tape wave
  99.           uvn.x += ( noise( float2( uvn.y, time ) ) - 0.5 )* 0.005;
  100.           uvn.x += ( noise( float2( uvn.y * 100.0, time * 10.0 ) ) - 0.5 ) * 0.01;
  101.  
  102.           // tape crease
  103.           float tcPhase = clamp( ( sin( uvn.y * 8.0 - time * PI * 1.2 ) - 0.92 ) * noise( float2( time , time ) ), 0.0, 0.01 ) * 10.0;
  104.           float tcNoise = max( noise( float2( uvn.y * 100.0, time * 10.0 ) ) - 0.5, 0.0 );
  105.           uvn.x = uvn.x - tcNoise * tcPhase;
  106.  
  107.           // switching noise
  108.           float snPhase = smoothstep( 0.03, 0.0, uvn.y );
  109.           uvn.y += snPhase * 0.3;
  110.           uvn.x += snPhase * ( ( noise( float2( uv.y * 100.0, time * 10.0 ) ) - 0.5 ) * 0.2 );
  111.    
  112.           col = tex2D( _MainTex, uvn );
  113.           col *= 1.0 - tcPhase;
  114.           col = lerp(
  115.             col,
  116.             col.yzx,
  117.             snPhase
  118.           );
  119.  
  120.           // bloom
  121.           [unroll(100)]
  122.         for( float x = -4.0; x < 2.5; x += 1.0 ){
  123.             col.xyz += float3(
  124.               tex2D( _MainTex, uvn + float2( x - 0.0, 0.0 ) * 7E-3 ).x,
  125.               tex2D( _MainTex, uvn + float2( x - 2.0, 0.0 ) * 7E-3 ).y,
  126.               tex2D( _MainTex, uvn + float2( x - 4.0, 0.0 ) * 7E-3 ).z
  127.             ) * 0.1;
  128.  
  129.         outCol = float4(col, 1.0);
  130.         return outCol;
  131.  
  132.     }
  133.  
  134.     ENDCG
  135.     }
  136.   }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement