-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathretro.frag
69 lines (52 loc) · 1.63 KB
/
retro.frag
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
precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;
uniform float time;
void main() {
vec2 tc = vec2(v_texcoord.x, v_texcoord.y);
// Distance from the center
float dx = abs(0.5 - tc.x);
float dy = abs(0.5 - tc.y);
// Square it to smooth the edges
dx *= dx;
dy *= dy;
tc.x -= 0.5;
tc.x *= 1.0 + (dy * 0.03);
tc.x += 0.5;
tc.y -= 0.5;
tc.y *= 1.0 + (dx * 0.03);
tc.y += 0.5;
// Add RGB offset for retro color separation effect
vec2 r_tc = tc + vec2(0.001, 0.0);
vec2 g_tc = tc;
vec2 b_tc = tc - vec2(0.001, 0.0);
vec4 color;
color.r = texture2D(tex, r_tc).r;
color.g = texture2D(tex, g_tc).g;
color.b = texture2D(tex, b_tc).b;
color.a = 1.0;
// Add scanlines
float scanline = sin(tc.y * 1500.0) * 0.05;
color.rgb += scanline;
// Add noise
float noise = (fract(sin(dot(tc.xy + vec2(time), vec2(12.9898, 78.233))) * 43758.5453) - 0.5) * 0.04;
color.rgb += noise;
// Apply vignette effect
float vignette = smoothstep(0.8, 0.2, dx + dy);
color.rgb *= vignette;
// Vertical CRT lines with reduced intensity
float lines = sin((tc.y + time * 0.1) * 40.0) * 0.02;
color.rgb *= 1.0 - lines;
// Apply retro orange color transformation
vec3 retroColor = vec3(
color.r * 1.2, // Boost the red channel
color.g * 1.0, // Keep the green channel as is
color.b * 0.8 // Reduce the blue channel
);
color.rgb = retroColor;
// Cutoff
if (tc.y > 1.0 || tc.x < 0.0 || tc.x > 1.0 || tc.y < 0.0)
color = vec4(0.0);
// Apply
gl_FragColor = color;
}