@kassoulet/cathode 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +25 -0
  3. package/README.md +134 -2
  4. package/assets/crt/CRT Masks/Aperture Grille.png +0 -0
  5. package/assets/crt/CRT Masks/SX-64.png +0 -0
  6. package/assets/crt/CRT Masks/Shadow Mask EDP.png +0 -0
  7. package/assets/crt/CRT Masks/Shadow Mask.png +0 -0
  8. package/assets/crt/CRT Masks/Slot Mask.png +0 -0
  9. package/assets/crt/LICENSE +121 -0
  10. package/assets/crt/Presets/C64 Ultimate HDMI.yml +28 -0
  11. package/assets/crt/Presets/Cheap and broken TV.yml +27 -0
  12. package/assets/crt/Presets/Default.yml +27 -0
  13. package/assets/crt/Presets/SX-64.yml +27 -0
  14. package/assets/crt/Presets/VICE.yml +28 -0
  15. package/assets/crt/README.md +3 -0
  16. package/assets/crt/Shaders/2d-texture.glsl +4 -0
  17. package/assets/crt/Shaders/crt-adjacent-excitation.glsl +29 -0
  18. package/assets/crt/Shaders/crt-bezel-reflections.glsl +101 -0
  19. package/assets/crt/Shaders/crt-calc-bloom.glsl +24 -0
  20. package/assets/crt/Shaders/crt-curved.glsl +225 -0
  21. package/assets/crt/Shaders/crt-halation.glsl +35 -0
  22. package/assets/crt/Shaders/crt-simulation.glsl +175 -0
  23. package/assets/crt/Shaders/decoder-ntsc.glsl +105 -0
  24. package/assets/crt/Shaders/decoder-pal.glsl +83 -0
  25. package/assets/crt/Shaders/decoder-yiq.glsl +25 -0
  26. package/assets/crt/Shaders/decoder-yuv.glsl +25 -0
  27. package/assets/crt/Shaders/encoder-c64.glsl +26 -0
  28. package/assets/crt/Shaders/encoder-raw.glsl +19 -0
  29. package/assets/crt/Shaders/includes/colorGrade.glsl +25 -0
  30. package/assets/crt/Shaders/includes/colorSpaces.glsl +63 -0
  31. package/assets/crt/Shaders/includes/common.glsl +157 -0
  32. package/assets/crt/Shaders/includes/getMipMapColor.glsl +31 -0
  33. package/assets/crt/Shaders/includes/getSignal.glsl +95 -0
  34. package/assets/crt/Shaders/includes/grain.glsl +19 -0
  35. package/assets/crt/Shaders/includes/jailbars.glsl +11 -0
  36. package/assets/crt/Shaders/includes/mathDefines.glsl +6 -0
  37. package/assets/crt/Shaders/includes/overscan.glsl +18 -0
  38. package/assets/crt/Shaders/includes/verticalRoll.glsl +46 -0
  39. package/assets/crt/Shaders/lights.glsl +16 -0
  40. package/assets/crt/Shaders/overlay-dust-layer.glsl +27 -0
  41. package/assets/crt/Shaders/overlay-dust-particle.glsl +100 -0
  42. package/assets/crt/Shaders/overlay.glsl +73 -0
  43. package/assets/crt/Shaders/raw-overscan.glsl +9 -0
  44. package/assets/crt/reflections.png +0 -0
  45. package/package.json +64 -4
  46. package/src/cathode/backends/fast.js +95 -0
  47. package/src/cathode/backends/gl.js +35 -0
  48. package/src/cathode/cathode.js +123 -0
  49. package/src/cathode/presets.js +62 -0
  50. package/src/cathode/settings.js +56 -0
  51. package/src/crt.js +583 -0
  52. package/src/gl.js +313 -0
  53. package/src/index.d.ts +84 -0
  54. package/src/index.js +121 -0
  55. package/src/presets.js +293 -0
  56. package/src/shaders.js +130 -0
@@ -0,0 +1,26 @@
1
+ #include "includes/jailbars.glsl"
2
+
3
+ //-----------------------------------------------------------------------------
4
+
5
+ //
6
+ // C64 YUV/YIQ encoder
7
+ //
8
+
9
+ uniform float encPaletteY = 0.0;
10
+
11
+ void main ()
12
+ {
13
+ // Convert index to YUV
14
+ uint index = texture ( iChannel0, vec2 ( fragCoord.x, 1 - fragCoord.y ) ).r;
15
+ float x = 1.0 / textureSize ( iChannel1, 0 ).x;
16
+ vec3 col = texture ( iChannel1, vec2 ( index * x, encPaletteY ) ).rgb;
17
+
18
+ // Add jailbars
19
+ col.r += getJailbars ( vec2 ( fragCoord.x / 8.0, iResolution.x ) );
20
+
21
+ // Textures can't store negative values, we have to transpose
22
+ col.yz += 0.5;
23
+
24
+ fragColor = vec4 ( col, 0.0 );
25
+ }
26
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,19 @@
1
+ //
2
+ // YUV/YIQ encoder
3
+ //
4
+
5
+ uniform float encPaletteY = 0.0;
6
+
7
+ void main ()
8
+ {
9
+ // Convert index to YUV
10
+ uint index = texture ( iChannel0, vec2 ( fragCoord.x, 1 - fragCoord.y ) ).r;
11
+ float x = 1.0 / textureSize ( iChannel1, 0 ).x;
12
+ vec3 col = texture ( iChannel1, vec2 ( index * x, encPaletteY ) ).rgb;
13
+
14
+ // Textures can't store negative values, we have to transpose
15
+ col.yz += 0.5;
16
+
17
+ fragColor = vec4 ( col, 0.0 );
18
+ }
19
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,25 @@
1
+ //-----------------------------------------------------------------------------
2
+
3
+ vec3 getLutColor ( sampler3D lut, vec3 color )
4
+ {
5
+ vec3 lutSize = vec3 ( textureSize ( lut, 0 ) );
6
+ vec3 scale = ( lutSize - 1.0 ) / lutSize;
7
+ vec3 offset = 1.0 / ( 2.0 * lutSize );
8
+
9
+ return texture ( lut, scale * color + offset ).rgb;
10
+ }
11
+ //-----------------------------------------------------------------------------
12
+
13
+ uniform float lutBlend;
14
+
15
+ vec3 colorGrade ( vec3 pix, sampler3D duskLUT, sampler3D nightLUT )
16
+ {
17
+ float dusk = ( 0.5 - abs ( lutBlend - 0.5 ) ) * 3.0;
18
+ float night = max ( 0.0, ( lutBlend * 2.0 ) - 1.0 );
19
+
20
+ pix = mix ( pix, getLutColor ( duskLUT, pix ), dusk );
21
+ pix = mix ( pix, getLutColor ( nightLUT, pix ), night );
22
+
23
+ return pix;
24
+ }
25
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,63 @@
1
+ //
2
+ // Color space conversions
3
+ //
4
+ const vec3 luma601 = vec3 ( 0.299, 0.587, 0.114 );
5
+ const vec3 luma709 = vec3 ( 0.2126, 0.7152, 0.0722 );
6
+
7
+ const mat3 yuv2rgb_mat = mat3 ( 1.0, 1.0, 1.0,
8
+ 0.0, -0.39465, 2.03211,
9
+ 1.13983, -0.581, 0.0 );
10
+ //-----------------------------------------------------------------------------
11
+
12
+ vec3 palGamma ( vec3 rgb )
13
+ {
14
+ const float sRGBGamma = 2.2;
15
+ const float PALgamma = 2.8;
16
+
17
+ // Apply gamma correction (2.8 to 2.2). Out-of-gamut YUV can decode to
18
+ // negative RGB, and pow() of a negative value is NaN, which would poison
19
+ // the whole mip chain; clamp the base first.
20
+ return pow ( max ( rgb, vec3 ( 0.0 ) ), vec3 ( 1.0 / sRGBGamma * PALgamma ) );
21
+ }
22
+ //-----------------------------------------------------------------------------
23
+
24
+ vec3 yuv2rgb ( vec3 yuv )
25
+ {
26
+ return palGamma ( yuv2rgb_mat * yuv );
27
+ }
28
+ //-----------------------------------------------------------------------------
29
+
30
+ const mat3 yiq2rgb_mat = mat3 ( 1.0, 1.0, 1.0,
31
+ 1.63, -0.378, -1.089,
32
+ 0.317, -0.466, 1.677 );
33
+ //-----------------------------------------------------------------------------
34
+
35
+ vec3 yiq2rgb ( vec3 yiq )
36
+ {
37
+ return yiq2rgb_mat * yiq;
38
+ }
39
+ //-----------------------------------------------------------------------------
40
+
41
+ vec3 srgbToLinear ( vec3 col )
42
+ {
43
+ return mix ( col / 12.92, pow ( ( col + 0.055 ) / 1.055, vec3 ( 2.4 ) ), step ( 0.04045, col ) );
44
+ }
45
+ //-----------------------------------------------------------------------------
46
+
47
+ vec3 linearToSrgb ( vec3 col )
48
+ {
49
+ return mix ( col * 12.92, 1.055 * pow ( col, vec3 ( 1.0 / 2.4 ) ) - 0.055, step ( 0.0031308, col ) );
50
+ }
51
+ //-----------------------------------------------------------------------------
52
+
53
+ float getsRGBLuma ( vec3 col )
54
+ {
55
+ return dot ( col, luma601 );
56
+ }
57
+ //-----------------------------------------------------------------------------
58
+
59
+ float getLinearLuma ( vec3 col )
60
+ {
61
+ return dot ( col, luma709 );
62
+ }
63
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,157 @@
1
+ //
2
+ // This file contains helpers used by shaders
3
+ //
4
+ uniform float crtRefreshRate = 50.125; // 50.125 for PAL, 59.826 for NTSC
5
+
6
+ //
7
+ // Encoder uniforms
8
+ //
9
+ uniform vec3 encBrightnessContrastSaturation = vec3 ( 0.5, 1.0, 0.5 );
10
+
11
+ vec3 encApplyBriConSat ( vec3 lumChrChr )
12
+ {
13
+ lumChrChr.yz *= encBrightnessContrastSaturation.z;
14
+ lumChrChr *= encBrightnessContrastSaturation.y;
15
+ lumChrChr.x += encBrightnessContrastSaturation.x;
16
+
17
+ return lumChrChr;
18
+ }
19
+ //-----------------------------------------------------------------------------
20
+
21
+ // Warm/cold white point, per-channel gains come luma-normalized from the host
22
+ uniform vec3 encTintGains = vec3 ( 1.0 );
23
+
24
+ vec3 encApplyTint ( vec3 rgb )
25
+ {
26
+ return rgb * encTintGains;
27
+ }
28
+ //-----------------------------------------------------------------------------
29
+
30
+ //
31
+ // Decoder uniforms
32
+ //
33
+ float decHash12_v2 ( vec2 p )
34
+ {
35
+ vec3 p3 = fract ( vec3 ( p.xyx ) * 0.1031 );
36
+ p3 += dot ( p3, p3.yzx + 33.33 );
37
+ return fract ( ( p3.x + p3.y ) * p3.z );
38
+ }
39
+ //-----------------------------------------------------------------------------
40
+
41
+ float decRandom_v2_f ( vec2 p, float t )
42
+ {
43
+ return decHash12_v2 ( p * 0.152 + t * 1500.0 + 50.0 );
44
+ }
45
+ //-----------------------------------------------------------------------------
46
+
47
+ vec2 decCreateInterference ( vec2 uv, float qinter )
48
+ {
49
+ float interference = pow ( qinter, 1.3 );
50
+ float line = round ( uv.y * 272.0 );
51
+
52
+ // Divide screen into bands; each band MAY contain one tear trigger.
53
+ const float bandSize = 40.0;
54
+
55
+ float bandId = floor ( line / bandSize );
56
+ float bandPos = line - bandId * bandSize;
57
+
58
+ // Per-band: does it tear, and where does the trigger line sit?
59
+ float tt = floor ( iTime * crtRefreshRate * 0.25 );
60
+ float rTrigger = decRandom_v2_f ( vec2 ( 0.0, bandId + tt * 100.0 ), 1.0 );
61
+ float rWhere = decRandom_v2_f ( vec2 ( 1.0, bandId ), iTime );
62
+ float rDir = decRandom_v2_f ( vec2 ( 2.0, bandId ), iTime );
63
+
64
+ // only some bands tear, rarer at low interference
65
+ float tears = step ( 0.97 - interference * 0.15, rTrigger );
66
+
67
+ // trigger line within the band
68
+ float triggerPos = rWhere * bandSize;
69
+
70
+ // distance below the trigger (0 above it, grows below)
71
+ float below = max ( 0.0, bandPos - triggerPos );
72
+
73
+ // exponential decay: big at the trigger, fading down
74
+ float decay = exp ( -below * 0.1 );
75
+
76
+ // displacement: pull to the right, scaled by decay
77
+ float shift = tears * decay * 0.05 * interference;
78
+
79
+ uv.x -= shift; // positive = pull right
80
+
81
+ return uv;
82
+ }
83
+ //-----------------------------------------------------------------------------
84
+
85
+ uniform float decSharpening = 0.1;
86
+ uniform float decLumablur = 0.5;
87
+ uniform float decChromablur = 1.0;
88
+
89
+ #define DEC_FILTER_KERNEL 25
90
+ const float decLumaFilter[DEC_FILTER_KERNEL] = float[DEC_FILTER_KERNEL](0.0105,0.0134,0.0057,-0.0242,-0.0824,-0.1562,-0.2078,-0.185,-0.0546,0.1626,0.3852,0.5095,0.5163,0.4678,0.2844,0.0515,-0.1308,-0.2082,-0.1891,-0.1206,-0.0511,-0.0065,0.0114,0.0127,0.008);
91
+ const float decChromaFilter[DEC_FILTER_KERNEL] = float[DEC_FILTER_KERNEL](0.001,0.001,0.0001,0.0002,-0.0003,0.0062,0.012,-0.0079,0.0978,0.1059,-0.0394,0.2732,0.2941,0.1529,-0.021,0.1347,0.0415,-0.0032,0.0115,0.002,-0.0001,0.0002,0.001,0.001,0.001);
92
+
93
+ vec3 decGetBlurredSignal ( vec2 uv, sampler2D tex )
94
+ {
95
+ // chroma sub-sampling
96
+ vec4 lumaChromaDelta = vec4 ( 1.0 / float ( textureSize ( tex, 0 ).x ) ) * vec4 ( decSharpening, decLumablur, decChromablur, decChromablur );
97
+
98
+ vec3 lumaChroma = vec3 ( 0.0 );
99
+ for ( int i = 0; i < DEC_FILTER_KERNEL; i++ )
100
+ {
101
+ vec4 lumaChromaOffset = vec4 ( i - DEC_FILTER_KERNEL / 2 ) * lumaChromaDelta;
102
+
103
+ float sumLuma = texture ( tex, uv + vec2 ( lumaChromaOffset.x, 0.0 ) ).x;
104
+ float sumLuma2 = texture ( tex, uv + vec2 ( lumaChromaOffset.y, 0.0 ) ).x;
105
+ float sumChroma = texture ( tex, uv + vec2 ( lumaChromaOffset.z, 0.0 ) ).y - 0.5;
106
+ float sumChroma2 = texture ( tex, uv + vec2 ( lumaChromaOffset.w, 0.0 ) ).z - 0.5;
107
+
108
+ lumaChroma.x += sumLuma * decLumaFilter[ i ] + sumLuma2 * decChromaFilter[ i ];
109
+ lumaChroma.y += sumChroma * decChromaFilter[ i ];
110
+ lumaChroma.z += sumChroma2 * decChromaFilter[ i ];
111
+ }
112
+
113
+ return lumaChroma * vec3 ( 0.5, 1.0, 1.0 );
114
+ }
115
+ //-----------------------------------------------------------------------------
116
+
117
+ uniform float crtCurve = 0.4;
118
+
119
+ vec2 curve ( vec2 uv, float level )
120
+ {
121
+ // 0 to 1 -> -1 to +1
122
+ vec2 cuv = ( uv - 0.5 ) * 2.0;
123
+
124
+ // shape
125
+ vec2 auv = abs ( cuv.yx ) / vec2 ( 5.0, 4.0 );
126
+ cuv *= 1.0 + auv * auv;
127
+
128
+ // -1 to + 1 -> 0 to 1
129
+ cuv = ( cuv / 2.0 ) + 0.5;
130
+
131
+ return mix ( uv, cuv, level );
132
+ }
133
+ //-----------------------------------------------------------------------------
134
+
135
+ vec3 checkerboard ( vec2 uv, float num )
136
+ {
137
+ vec2 pos = floor ( uv * num );
138
+ float mask = mod ( pos.x + mod ( pos.y, 2.0 ), 2.0 );
139
+
140
+ return vec3 ( mask );
141
+ }
142
+ //-----------------------------------------------------------------------------
143
+
144
+ float udRoundBox ( vec2 p, vec2 b, float radius )
145
+ {
146
+ return length ( max ( abs ( p ) - b + radius, 0.0 ) ) - radius;
147
+ }
148
+ //-----------------------------------------------------------------------------
149
+
150
+ float roundedMask ( vec2 uv, vec2 res, float radius )
151
+ {
152
+ vec2 p = 2.0 * uv - res;
153
+ float f = udRoundBox ( p, res, radius );
154
+
155
+ return smoothstep ( 4.0, 0.0, f );
156
+ }
157
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,31 @@
1
+ //-----------------------------------------------------------------------------
2
+
3
+ float lodForRadius ( sampler2D tex, float frac )
4
+ {
5
+ return log2 ( frac * float ( textureSize ( tex, 0 ).y ) );
6
+ }
7
+ //-----------------------------------------------------------------------------
8
+
9
+ vec4 getMipMapColor ( sampler2D tex, vec2 uv, float lod )
10
+ {
11
+ float bias = 0.5 / lod;
12
+ vec2 offset = ( bias / vec2 ( textureSize ( tex, int ( lod ) ) ) );
13
+ vec4 pix = textureLod ( tex, uv + offset, lod );
14
+
15
+ return pix;
16
+ }
17
+ //-----------------------------------------------------------------------------
18
+
19
+ vec3 getMipMapColorJittered ( sampler2D tex, vec2 uv, float lod )
20
+ {
21
+ vec2 texel = exp2 ( lod ) / vec2 ( textureSize ( tex, 0 ) );
22
+
23
+ vec3 s;
24
+ s = textureLod ( tex, uv + texel * vec2 ( -0.4, -0.4 ), lod ).rgb;
25
+ s += textureLod ( tex, uv + texel * vec2 ( 0.4, -0.4 ), lod ).rgb;
26
+ s += textureLod ( tex, uv + texel * vec2 ( -0.4, 0.4 ), lod ).rgb;
27
+ s += textureLod ( tex, uv + texel * vec2 ( 0.4, 0.4 ), lod ).rgb;
28
+
29
+ return s * 0.25;
30
+ }
31
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,95 @@
1
+ //-----------------------------------------------------------------------------
2
+
3
+ vec3 getSignal ( vec2 fragPos, float angle, float rollOffset )
4
+ {
5
+ // --- single quality slider -> staggered per-effect amounts ---
6
+ float n = decNoise * decNoise;
7
+
8
+ const float NOISE_RES_X = 1280.0;
9
+ const float NOISE_RES_Y = 272.0;
10
+ const float BLACK_LEVEL = 0.05;
11
+
12
+ // Interference: this line's own horizontal jitter
13
+ vec2 uv = decCreateInterference ( fragPos, n );
14
+
15
+ // roll applies ONLY to the picture content lookup
16
+ float barH = 0.05;
17
+ float rolling = smoothstep ( 0.0, 0.05, rollOffset ) * smoothstep ( 1.0, 0.95, rollOffset );
18
+ float effBarH = barH * rolling;
19
+ float y = fract ( uv.y + rollOffset );
20
+ vec2 rolledUV = uv;
21
+ rolledUV.y = ( y - effBarH ) / ( 1.0 - effBarH );
22
+
23
+ // Bandwidth limit (luma full, chroma reduced)
24
+ vec3 sig = vec3 ( 0.0 );
25
+ if ( uv.x >= 0.0 && uv.x <= 1.0 && rolledUV.y >= 0.0 && rolledUV.y <= 1.0 )
26
+ sig = decGetBlurredSignal ( rolledUV, iChannel0 );
27
+
28
+ // Phase shift chroma
29
+ vec2 sc = vec2 ( cos ( angle ), sin ( angle ) );
30
+ sig.yz = mat2 ( sc, -sc.y, sc.x ) * sig.yz;
31
+
32
+ // Signal pedestal: lift black off zero so noise has symmetric headroom
33
+ sig.x = sig.x * ( 1.0 - BLACK_LEVEL ) + BLACK_LEVEL;
34
+
35
+ // --- Transmission noise: fine grain + impulsive spikes -------------------
36
+ // One combined system driven by decNoise. Grain gives constant texture;
37
+ // spikes punch through the rails so snow stays visible in black AND white.
38
+
39
+ float noiseAmt = n;
40
+
41
+ // (a) Fine grain — line-coherent, additive
42
+ vec2 noiseCoord = vec2 ( fragPos.x * NOISE_RES_X, floor ( fragPos.y * NOISE_RES_Y ) );
43
+ vec3 noise = grnHash3 ( uint ( noiseCoord.x ) + uint ( NOISE_RES_X ) * uint ( noiseCoord.y )
44
+ + uint ( NOISE_RES_X ) * uint ( NOISE_RES_Y ) * uint ( iTime * crtRefreshRate ) );
45
+ sig += ( noise - 0.5 ) * noiseAmt * 2.5;
46
+
47
+ // (b) Impulsive spikes — per-pixel, per-frame, full-amplitude.
48
+ // These REPLACE luma rather than add, so they survive at the rails:
49
+ // a white spike shows on black, a black spike shows on white.
50
+ float spikeHash = grnHash3 ( uint ( fragPos.x * NOISE_RES_X ) * 7u + 3u
51
+ + uint ( NOISE_RES_X ) * uint ( fragPos.y * NOISE_RES_Y ) * 13u
52
+ + uint ( NOISE_RES_X ) * uint ( NOISE_RES_Y )
53
+ * uint ( iTime * crtRefreshRate ) * 17u ).x;
54
+
55
+ float spikeRate = smoothstep ( 0.1, 1.0, noiseAmt ) * 0.15;
56
+ if ( spikeHash > 1.0 - spikeRate )
57
+ {
58
+ float pol = step ( 0.5, fract ( spikeHash * 91.7 ) ); // 0 = black, 1 = white
59
+ sig.x = pol; // hard replace -> punches rails
60
+
61
+ // faint chroma fringe on some spikes (not all, not full-amplitude)
62
+ float cHash = fract ( spikeHash * 47.3 );
63
+ sig.yz += vec2 ( cHash, fract ( cHash * 7.0 ) ) - 0.5; // small colored fringe
64
+ }
65
+
66
+ // Chroma dropout: color dies before luma as signal weakens.
67
+ // Global desaturation + blotchy per-region loss.
68
+ float chromaLoss = smoothstep ( 0.1, 0.7, noiseAmt );
69
+ if ( chromaLoss > 0.0 )
70
+ {
71
+ vec2 bc = vec2 ( fragPos.x * 8.0, fragPos.y * 6.0 );
72
+ vec2 bf = smoothstep ( 0.0, 1.0, fract ( bc ) );
73
+ vec2 bi = floor ( bc );
74
+
75
+ uint bx = uint ( bi.x );
76
+ uint by = uint ( bi.y );
77
+ uint time_offset = 4096u * uint ( floor ( iTime * crtRefreshRate * 0.3 ) );
78
+
79
+ float h00 = grnHash3 ( bx + 64u * by + time_offset ).x;
80
+ float h10 = grnHash3 ( ( bx + 1u ) + 64u * by + time_offset ).x;
81
+ float h01 = grnHash3 ( bx + 64u * ( by + 1u ) + time_offset ).x;
82
+ float h11 = grnHash3 ( (bx + 1u ) + 64u * ( by + 1u ) + time_offset ).x;
83
+
84
+ float blotch = mix ( mix ( h00, h10, bf.x ), mix ( h01, h11, bf.x ), bf.y );
85
+ float keep = ( 1.0 - chromaLoss ) * mix ( 1.0, blotch, chromaLoss );
86
+
87
+ sig.yz *= keep;
88
+ }
89
+
90
+ // Receiver Y/C separation failure acts on the already-noisy signal
91
+ sig = decGetCrosstalk ( sig, rolledUV, iChannel0 );
92
+
93
+ return sig;
94
+ }
95
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,19 @@
1
+ //-----------------------------------------------------------------------------
2
+
3
+ vec3 grnHash3 ( uint n )
4
+ {
5
+ // integer hash copied from Hugo Elias
6
+ n = ( n << 13U ) ^ n;
7
+ n = n * (n * n * 15731U + 789221U) + 1376312589U;
8
+ uvec3 k = n * uvec3 ( n, n * 16807U, n * 48271U );
9
+ return vec3 ( k & uvec3 ( 0x7fffffffU ) ) / float ( 0x7fffffff );
10
+ }
11
+ //-----------------------------------------------------------------------------
12
+
13
+ vec3 grnGrain ( uvec2 uv, float level )
14
+ {
15
+ vec3 grain = grnHash3 ( uv.x + uint ( iResolution.x ) * uv.y + ( uint ( iResolution.x ) * uint ( iResolution.y ) ) * uint ( iTime * 30.0 ) );
16
+
17
+ return grain * level * 0.8 + ( 1.0 - ( level * 0.4 ) );
18
+ }
19
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,11 @@
1
+ uniform float decJailbars = 1.0;
2
+
3
+ float getJailbars ( vec2 uv )
4
+ {
5
+ float tri = fract ( uv.x * uv.y + 0.4 );
6
+
7
+ tri = smoothstep ( 0.8, 1.0, tri );
8
+
9
+ return ( tri * tri ) * pow ( decJailbars, 3.8 ) * 0.09;
10
+ }
11
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,6 @@
1
+ //-----------------------------------------------------------------------------
2
+
3
+ #define PI 3.1415926535897932384626433832795
4
+ #define TAU ( 2.0 * PI )
5
+
6
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,18 @@
1
+ //-----------------------------------------------------------------------------
2
+
3
+ uniform vec2 crtOverscan = vec2 ( 1.0 );
4
+
5
+ vec2 overscan ( vec2 uv )
6
+ {
7
+ // 0 to 1 -> -1 to +1
8
+ vec2 ouv = ( uv - 0.5 ) * 2.0;
9
+
10
+ // Scale
11
+ ouv *= crtOverscan;
12
+
13
+ // -1 to + 1 -> 0 to 1
14
+ ouv = ( ouv / 2.0 ) + 0.5;
15
+
16
+ return ouv;
17
+ }
18
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,46 @@
1
+ //-----------------------------------------------------------------------------
2
+
3
+ float vRollOffset ()
4
+ {
5
+ // V-sync roll offset (content only; passed into getSignal)
6
+ float n = decNoise * decNoise;
7
+ float amount = smoothstep ( 0.2, 1.0, n );
8
+ if ( amount <= 0.0 )
9
+ return 0.0;
10
+
11
+ float t = iTime;
12
+
13
+ // Divide time into episodes (~1.5s each). Each episode independently
14
+ // decides: stay locked, roll through, or roll-and-stall.
15
+ float ep = floor ( t * 0.66 ); // episode index (~1.5s)
16
+ float epLocal = fract ( t * 0.66 ); // 0..1 within episode
17
+
18
+ // per-episode random traits
19
+ float rType = decRandom_v2_f ( vec2 ( 0.0, ep ), 1.0 ); // decides lock vs roll
20
+ float rSpeed = decRandom_v2_f ( vec2 ( 1.0, ep ), 1.0 ); // roll-through count
21
+ float rStall = decRandom_v2_f ( vec2 ( 2.0, ep ), 1.0 ); // stall point
22
+
23
+ // is this episode a rolling one? higher amount -> more episodes roll
24
+ float rolls = step ( 1.0 - amount, rType );
25
+ if ( rolls < 0.5 )
26
+ return 0.0; // locked episode -> no roll
27
+
28
+ // rolling episode: sweep through, with a stall partway
29
+ float cycles = 1.0 + floor ( rSpeed * 2.0 ); // 1..3 roll-throughs
30
+ float stallAt = 0.3 + rStall * 0.4; // stall somewhere mid-episode
31
+
32
+ // ease: progress normally, but pause near stallAt (flatten the curve there)
33
+ float prog = epLocal;
34
+ float stallZone = smoothstep ( stallAt - 0.08, stallAt, prog )
35
+ * ( 1.0 - smoothstep ( stallAt, stallAt + 0.12, prog ) );
36
+ prog -= stallZone * 0.12; // flatten -> bar parks briefly
37
+
38
+ float erratic = fract ( prog * cycles );
39
+
40
+ // at high amount, blend toward pure fast continuous roll (total sync loss)
41
+ float freeRun = fract ( t * 4.0 ); // fast constant tumble
42
+ float chaos = smoothstep ( 0.8, 1.0, amount ); // kicks in only near max
43
+
44
+ return mix ( erratic, freeRun, chaos );
45
+ }
46
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,16 @@
1
+ #include "includes/getMipMapColor.glsl"
2
+
3
+ uniform float ovlBloom = 1.0;
4
+
5
+ //-----------------------------------------------------------------------------
6
+
7
+ void main ()
8
+ {
9
+ vec4 bloom = getMipMapColor ( iChannel0, fragCoord, 1.0 );
10
+ bloom += getMipMapColor ( iChannel0, fragCoord, 2.0 );
11
+ bloom += getMipMapColor ( iChannel0, fragCoord, 3.0 );
12
+ bloom *= ovlBloom;
13
+
14
+ fragColor = bloom + texture ( iChannel0, fragCoord );
15
+ }
16
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,27 @@
1
+ #include "includes/getMipMapColor.glsl"
2
+ #include "includes/colorGrade.glsl"
3
+
4
+ uniform float ovlDust = 1.0;
5
+ uniform float ovlBloom = 1.0;
6
+
7
+ //-----------------------------------------------------------------------------
8
+
9
+ void main ()
10
+ {
11
+ float scaleFactor = clamp ( textureSize ( iChannel0, 0 ).x / 3840.0, 0.3, 1.0 );
12
+
13
+ vec4 dust = texture ( iChannel0, fragCoord ) * ovlDust * scaleFactor;
14
+ vec4 mask = getMipMapColor ( iChannel1, ( fragCoord - 0.5 ) * 0.8 + 0.5, 5.5 );
15
+
16
+ vec4 bloom = getMipMapColor ( iChannel1, fragCoord, 3.0 );
17
+ bloom += getMipMapColor ( iChannel1, fragCoord, 4.0 );
18
+ bloom += getMipMapColor ( iChannel1, fragCoord, 5.5 );
19
+ bloom += getMipMapColor ( iChannel1, fragCoord, 6.5 );
20
+ bloom += getMipMapColor ( iChannel1, fragCoord, 7.5 );
21
+ bloom *= 0.25;
22
+ bloom.rgb = colorGrade ( bloom.rgb, iChannel2, iChannel3 );
23
+ bloom = bloom * bloom * bloom * ovlBloom;
24
+
25
+ fragColor = bloom + ( dust * mix ( 0.2, 1.0, mask.a ) );
26
+ }
27
+ //-----------------------------------------------------------------------------
@@ -0,0 +1,100 @@
1
+ #version 410 core
2
+
3
+ #ifdef UPDATE
4
+
5
+ layout (location = 0) in vec3 inPos;
6
+ layout (location = 1) in vec3 inVel;
7
+
8
+ out vec3 outPos;
9
+ out vec3 outVel;
10
+
11
+ uniform float deltaTime = 0.016666;
12
+ uniform float iTime = 0;
13
+
14
+ float hash ( vec3 p )
15
+ {
16
+ return fract (sin (dot (p, vec3 ( 12.9898, 78.233, 45.164 ) ) ) * 43758.5453 );
17
+ }
18
+
19
+ // Generate a random vector for a specific point in space
20
+ vec3 getWindVector ( vec3 p )
21
+ {
22
+ // We scale iTime down (0.2) so the "air currents" don't vibrate too fast
23
+ vec3 seed = p + ( iTime * 0.2 );
24
+
25
+ float x = hash ( seed.xyz ) * 2.0 - 1.0;
26
+ float y = hash ( seed.yzx ) * 2.0 - 1.025; // Slightly more downward bias for dust
27
+ float z = hash ( seed.zxy ) * 2.0 - 1.0;
28
+
29
+ return vec3 ( x, y, z );
30
+ }
31
+
32
+ // Helper to normalize Z into a 0.0 -> 1.0 range
33
+ float getZFactor ( float z )
34
+ {
35
+ return (z + 1.0) * 0.5;
36
+ }
37
+
38
+ void main ()
39
+ {
40
+ const float jitterStrength = 1.1;
41
+ const float drag = 0.99;
42
+
43
+ vec3 windCurrent = getWindVector ( inPos * 0.5 );
44
+
45
+ vec3 vel = inVel + windCurrent * jitterStrength * deltaTime;
46
+ vel *= drag;
47
+
48
+ float zNext = clamp ( inPos.z + vel.z, -1.0, 1.0 );
49
+ float zFactor = getZFactor ( zNext );
50
+
51
+ // Square the zFactor to make the speed difference between front and back more dramatic
52
+ float speedMultiplier = mix ( 0.00005, 0.003, zFactor * zFactor );
53
+
54
+ vec3 pos = inPos + ( vel * speedMultiplier );
55
+
56
+ pos.xy = mod ( pos.xy + 1.0, 2.0 ) - 1.0;
57
+ pos.z = clamp ( pos.z, -1.0, 1.0 );
58
+
59
+ outPos = pos;
60
+ outVel = vel;
61
+ }
62
+ //-----------------------------------------------------------------------------
63
+ #endif
64
+
65
+ #ifdef VERTEX
66
+
67
+ layout (location = 0) in vec3 aInstance;
68
+
69
+ out float vOpacity;
70
+
71
+ void main ()
72
+ {
73
+ vOpacity = pow ( 2.0, 2.5 * ( 1.0 - ( aInstance.z + 1.0 ) * 0.5 ) );
74
+
75
+ gl_Position = vec4 ( aInstance.xy, 0.0, 1.0 );
76
+ gl_PointSize = 5.0;
77
+ }
78
+ //-----------------------------------------------------------------------------
79
+ #endif
80
+
81
+
82
+ #ifdef FRAGMENT
83
+
84
+ in float vOpacity;
85
+ out vec4 fragColor;
86
+
87
+ void main ()
88
+ {
89
+ float dist = 1.0 - length ( gl_PointCoord - 0.5 );
90
+
91
+ // Disc with soft-edge
92
+ dist = smoothstep ( 0.5 - 0.2, 0.5, dist * 0.5 ) ;
93
+
94
+ // Bright kernal with glow
95
+ // dist = pow ( min ( dist * 1.2, 1.0 ), 7.0 );
96
+
97
+ fragColor = vec4 ( dist / vOpacity );
98
+ }
99
+ //-----------------------------------------------------------------------------
100
+ #endif