-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVHSEffect.shader
More file actions
106 lines (93 loc) · 3.57 KB
/
Copy pathVHSEffect.shader
File metadata and controls
106 lines (93 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Shader "Custom/VHSEffect"
{
Properties
{
_MainTex ("Render Texture", 2D) = "white" {}
_ScanlineIntensity ("Scanline Intensity", Range(0,4)) = 0.5
_NoiseIntensity ("Noise Intensity", Range(0,2)) = 0.2
_ColorBleed ("Color Bleed", Range(0,10)) = 0.02
_Distortion ("Distortion", Range(0,10)) = 0.05
_WobbleFrequency ("Wobble Frequency", Range(0,110)) = 40
_WobbleSpeed ("Wobble Speed", Range(0,20)) = 1
_TimeParam ("Time", Float) = 0
_ScanlineCount ("Scanline Count", Float) = 300.0
}
SubShader
{
Tags
{
"RenderType"="Opaque"
}
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _ScanlineIntensity;
float _NoiseIntensity;
float _ColorBleed;
float _Distortion;
float _WobbleFrequency;
float _WobbleSpeed;
float _TimeParam;
float _ScanlineCount;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
// Helper: Simple random noise
float rand(float2 co)
{
return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453);
}
fixed4 frag(v2f i) : SV_Target
{
float2 uv = i.uv;
fixed4 col = tex2D(_MainTex, uv);
// 1. Scanlines
float scanline = sin(uv.y * _ScanlineCount * 3.14159);
float scanlineMask = lerp(1.0, 0.7, (scanline * 0.5 + 0.5) * _ScanlineIntensity);
col.rgb *= scanlineMask;
// 2. Basic Color Grading (slight desaturation and blue tint)
float gray = dot(col.rgb, float3(0.3, 0.59, 0.11));
col.rgb = lerp(col.rgb, float3(gray, gray, gray), 0.15); // Slight desaturation
col.rgb = lerp(col.rgb, float3(0.9, 0.95, 1.1), 0.08); // Subtle blue tint
// 3. Color Bleed/Chromatic Aberration
float brightness = dot(col.rgb, float3(0.3, 0.59, 0.11));
float blendAmount = _ColorBleed * smoothstep(0.05, 0.2, brightness);
float2 offset = float2(_ColorBleed / _ScreenParams.x, 0);
float r = tex2D(_MainTex, uv + offset).r;
float g = col.g;
float b = tex2D(_MainTex, uv - offset).b;
float3 aberrated = float3(r, g, b);
col.rgb = lerp(col.rgb, aberrated, blendAmount);
// 4. Noise/Static
float noise = (rand(uv * _TimeParam * 0.5 + _TimeParam) - 0.5) * _NoiseIntensity;
col.rgb += noise;
// 5. Distortion/Wobble
float wobble = sin(uv.y * _WobbleFrequency + _TimeParam * _WobbleSpeed) * _Distortion * 0.02;
float2 distortedUV = uv + float2(wobble, 0);
col.rgb = lerp(col.rgb, tex2D(_MainTex, distortedUV).rgb, _Distortion);
return col;
}
ENDCG
}
}
}