Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "ShaderMan/VHS2"
- {
- Properties{
- _MainTex ("MainTex", 2D) = "white" {}
- }
- SubShader
- {
- Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
- Pass
- {
- ZWrite Off
- Blend SrcAlpha OneMinusSrcAlpha
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- struct VertexInput {
- float4 vertex : POSITION;
- float2 uv:TEXCOORD0;
- float4 tangent : TANGENT;
- float3 normal : NORMAL;
- //VertexInput
- };
- struct VertexOutput {
- float4 pos : SV_POSITION;
- float2 uv:TEXCOORD0;
- //VertexOutput
- };
- //Variables
- sampler2D _MainTex;
- #define time _Time.y
- #define resolution ( 1 )
- #define _MainTex _MainTex
- #define gl_FragColor fragColor
- #define PI 3.14159265
- float3 tex2D( sampler2D _tex, float2 _p ){
- float3 col = tex2D( _tex, _p ).xyz;
- if ( 0.5 < abs( _p.x - 0.5 ) ) {
- col = float3( 0.1 , 0.1 , 0.1 );
- }
- return col;
- }
- float hash( float2 _v ){
- return frac( sin( dot( _v, float2( 89.44, 19.36 ) ) ) * 22189.22 );
- }
- float iHash( float2 _v, float2 _r ){
- float h00 = hash( float2( floor( _v * _r + float2( 0.0, 0.0 ) ) / _r ) );
- float h10 = hash( float2( floor( _v * _r + float2( 1.0, 0.0 ) ) / _r ) );
- float h01 = hash( float2( floor( _v * _r + float2( 0.0, 1.0 ) ) / _r ) );
- float h11 = hash( float2( floor( _v * _r + float2( 1.0, 1.0 ) ) / _r ) );
- float2 ip = float2( smoothstep( float2( 0.0, 0.0 ), float2( 1.0, 1.0 ), fmod( _v*_r, 1. ) ) );
- return ( h00 * ( 1. - ip.x ) + h10 * ip.x ) * ( 1. - ip.y ) + ( h01 * ( 1. - ip.x ) + h11 * ip.x ) * ip.y;
- }
- float noise( float2 _v ){
- float sum = 0.0;
- [unroll(100)]
- for( int i=1; i<9; i++ )
- {
- sum += iHash(_v + float2(i, i), float2(2.0 * pow(2., float(i)), i)) / pow(2.0, float(i));
- }
- return sum;
- }
- VertexOutput vert (VertexInput v)
- {
- VertexOutput o;
- o.pos = UnityObjectToClipPos (v.vertex);
- o.uv = v.uv;
- //VertexFactory
- return o;
- }
- float4 frag(VertexOutput i) : SV_Target
- {
- float2 uv = i.pos.xy / resolution;
- float2 uvn = uv;
- float3 col = float3( 0.0 , 0.0 , 0.0 );
- float4 outCol = float4(0.0, 0.0, 0.0, 0.0);
- // tape wave
- uvn.x += ( noise( float2( uvn.y, time ) ) - 0.5 )* 0.005;
- uvn.x += ( noise( float2( uvn.y * 100.0, time * 10.0 ) ) - 0.5 ) * 0.01;
- // tape crease
- float tcPhase = clamp( ( sin( uvn.y * 8.0 - time * PI * 1.2 ) - 0.92 ) * noise( float2( time , time ) ), 0.0, 0.01 ) * 10.0;
- float tcNoise = max( noise( float2( uvn.y * 100.0, time * 10.0 ) ) - 0.5, 0.0 );
- uvn.x = uvn.x - tcNoise * tcPhase;
- // switching noise
- float snPhase = smoothstep( 0.03, 0.0, uvn.y );
- uvn.y += snPhase * 0.3;
- uvn.x += snPhase * ( ( noise( float2( uv.y * 100.0, time * 10.0 ) ) - 0.5 ) * 0.2 );
- col = tex2D( _MainTex, uvn );
- col *= 1.0 - tcPhase;
- col = lerp(
- col,
- col.yzx,
- snPhase
- );
- // bloom
- [unroll(100)]
- for( float x = -4.0; x < 2.5; x += 1.0 ){
- col.xyz += float3(
- tex2D( _MainTex, uvn + float2( x - 0.0, 0.0 ) * 7E-3 ).x,
- tex2D( _MainTex, uvn + float2( x - 2.0, 0.0 ) * 7E-3 ).y,
- tex2D( _MainTex, uvn + float2( x - 4.0, 0.0 ) * 7E-3 ).z
- ) * 0.1;
- outCol = float4(col, 1.0);
- return outCol;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement