@kassoulet/cathode 0.0.0-stage → 0.1.1
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.
- package/CHANGELOG.md +18 -0
- package/LICENSE +25 -0
- package/README.md +134 -2
- package/assets/crt/CRT Masks/Aperture Grille.png +0 -0
- package/assets/crt/CRT Masks/SX-64.png +0 -0
- package/assets/crt/CRT Masks/Shadow Mask EDP.png +0 -0
- package/assets/crt/CRT Masks/Shadow Mask.png +0 -0
- package/assets/crt/CRT Masks/Slot Mask.png +0 -0
- package/assets/crt/LICENSE +121 -0
- package/assets/crt/Presets/C64 Ultimate HDMI.yml +28 -0
- package/assets/crt/Presets/Cheap and broken TV.yml +27 -0
- package/assets/crt/Presets/Default.yml +28 -0
- package/assets/crt/Presets/SX-64.yml +27 -0
- package/assets/crt/Presets/VICE.yml +28 -0
- package/assets/crt/README.md +3 -0
- package/assets/crt/Shaders/2d-texture.glsl +4 -0
- package/assets/crt/Shaders/crt-adjacent-excitation.glsl +29 -0
- package/assets/crt/Shaders/crt-bezel-reflections.glsl +101 -0
- package/assets/crt/Shaders/crt-calc-bloom.glsl +24 -0
- package/assets/crt/Shaders/crt-curved.glsl +225 -0
- package/assets/crt/Shaders/crt-halation.glsl +35 -0
- package/assets/crt/Shaders/crt-simulation.glsl +175 -0
- package/assets/crt/Shaders/decoder-ntsc.glsl +105 -0
- package/assets/crt/Shaders/decoder-pal.glsl +83 -0
- package/assets/crt/Shaders/decoder-yiq.glsl +25 -0
- package/assets/crt/Shaders/decoder-yuv.glsl +25 -0
- package/assets/crt/Shaders/encoder-c64.glsl +26 -0
- package/assets/crt/Shaders/encoder-raw.glsl +19 -0
- package/assets/crt/Shaders/includes/colorGrade.glsl +25 -0
- package/assets/crt/Shaders/includes/colorSpaces.glsl +63 -0
- package/assets/crt/Shaders/includes/common.glsl +157 -0
- package/assets/crt/Shaders/includes/getMipMapColor.glsl +31 -0
- package/assets/crt/Shaders/includes/getSignal.glsl +95 -0
- package/assets/crt/Shaders/includes/grain.glsl +19 -0
- package/assets/crt/Shaders/includes/jailbars.glsl +11 -0
- package/assets/crt/Shaders/includes/mathDefines.glsl +6 -0
- package/assets/crt/Shaders/includes/overscan.glsl +18 -0
- package/assets/crt/Shaders/includes/verticalRoll.glsl +46 -0
- package/assets/crt/Shaders/lights.glsl +16 -0
- package/assets/crt/Shaders/overlay-dust-layer.glsl +27 -0
- package/assets/crt/Shaders/overlay-dust-particle.glsl +100 -0
- package/assets/crt/Shaders/overlay.glsl +73 -0
- package/assets/crt/Shaders/raw-overscan.glsl +9 -0
- package/assets/crt/reflections.png +0 -0
- package/package.json +64 -4
- package/src/cathode/backends/fast.js +95 -0
- package/src/cathode/backends/gl.js +35 -0
- package/src/cathode/cathode.js +123 -0
- package/src/cathode/presets.js +62 -0
- package/src/cathode/settings.js +56 -0
- package/src/crt.js +583 -0
- package/src/gl.js +313 -0
- package/src/index.d.ts +84 -0
- package/src/index.js +121 -0
- package/src/presets.js +293 -0
- package/src/shaders.js +130 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#include "includes/mathDefines.glsl"
|
|
2
|
+
#include "includes/common.glsl"
|
|
3
|
+
#include "includes/colorSpaces.glsl"
|
|
4
|
+
|
|
5
|
+
//-----------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
uniform float crtDistortion = 0.3;
|
|
8
|
+
|
|
9
|
+
//-----------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
vec2 glassDistortion ( vec2 uv, float k1, float xRatio )
|
|
12
|
+
{
|
|
13
|
+
vec2 zoom = vec2 ( 1.0 / ( k1 + 1.0 ), 1.0 / ( k1 + 1.0 ) );
|
|
14
|
+
|
|
15
|
+
// 0 to 1 -> -1 to +1
|
|
16
|
+
vec2 cuv = ( uv * 2.0 - 1.0 ) * zoom;
|
|
17
|
+
|
|
18
|
+
// Barrel distortion
|
|
19
|
+
cuv *= 1.0 + k1 * ( cuv.x * cuv.x + cuv.y * cuv.y );
|
|
20
|
+
|
|
21
|
+
// Add unevenness to glass surface
|
|
22
|
+
cuv += sin ( cuv * PI * 2.5 + PI ) * vec2 ( 0.006, 0.012 ) * k1;// * sin ( iTime ) * 50.0;
|
|
23
|
+
|
|
24
|
+
cuv.x *= xRatio;
|
|
25
|
+
|
|
26
|
+
// -1 to + 1 -> 0 to 1
|
|
27
|
+
cuv = cuv * 0.5 + 0.5;
|
|
28
|
+
|
|
29
|
+
return cuv;
|
|
30
|
+
}
|
|
31
|
+
//-----------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
uniform float crtVignette = 0.15;
|
|
34
|
+
|
|
35
|
+
float vignette ( vec2 uv )
|
|
36
|
+
{
|
|
37
|
+
// Zoom in a tiny bit to hide hard-edges
|
|
38
|
+
uv -= 0.5;
|
|
39
|
+
uv *= 0.995;
|
|
40
|
+
uv += 0.5;
|
|
41
|
+
|
|
42
|
+
float bias = 1.0 + dot ( uv - 0.5, vec2 ( 0.65, 0.40 ) * crtVignette );
|
|
43
|
+
|
|
44
|
+
uv *= 1.0 - uv;
|
|
45
|
+
|
|
46
|
+
return 1.0 - clamp ( pow ( uv.x * uv.y * 512.0, crtVignette * bias * 0.5 ), 0.0, 1.0 );
|
|
47
|
+
}
|
|
48
|
+
//-----------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
vec3 screen ( vec3 base, vec3 blend )
|
|
51
|
+
{
|
|
52
|
+
return 1.0 - ( 1.0 - base) * ( 1.0 - blend );
|
|
53
|
+
}
|
|
54
|
+
//-----------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
vec3 add ( vec3 base, vec3 blend )
|
|
57
|
+
{
|
|
58
|
+
return base + blend;
|
|
59
|
+
}
|
|
60
|
+
//-----------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
uniform bool crtSource = true;
|
|
63
|
+
uniform float crtReflection = 0.25;
|
|
64
|
+
uniform float crtRflCorrection = 1.0;
|
|
65
|
+
uniform float crtRotation = 0.0;
|
|
66
|
+
uniform float crtAspect = 1.0; // Quad w/h; iResolution is the viewport, not the quad
|
|
67
|
+
|
|
68
|
+
// The quad rotates with the tube; reflections sample counter-rotated so the
|
|
69
|
+
// reflected room stays level
|
|
70
|
+
vec2 counterRotate ( vec2 uv )
|
|
71
|
+
{
|
|
72
|
+
vec2 p = ( uv - 0.5 ) * vec2 ( crtAspect, 1.0 );
|
|
73
|
+
|
|
74
|
+
float sinR = sin ( crtRotation );
|
|
75
|
+
float cosR = cos ( crtRotation );
|
|
76
|
+
|
|
77
|
+
p = vec2 ( p.x * cosR + p.y * sinR, p.y * cosR - p.x * sinR );
|
|
78
|
+
|
|
79
|
+
return p / vec2 ( crtAspect, 1.0 ) + 0.5;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
uniform vec3 backCol = vec3 ( 0.0, 0.0, 0.0 );
|
|
83
|
+
|
|
84
|
+
uniform vec3 camBrightnessContrastSaturation = vec3 ( 1.0, 1.0, 1.0 );
|
|
85
|
+
uniform float camZoom = 1.0;
|
|
86
|
+
uniform int crtWebcamFormat = 0;
|
|
87
|
+
|
|
88
|
+
uniform vec3 yuvCol0;
|
|
89
|
+
uniform vec3 yuvCol1;
|
|
90
|
+
uniform vec3 yuvCol2;
|
|
91
|
+
uniform vec3 yuvBias;
|
|
92
|
+
|
|
93
|
+
//-----------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
/*vec2 getCurveWithBloom ( vec2 uv, float level )
|
|
96
|
+
{
|
|
97
|
+
const vec2 bloomFactor = vec2 ( 0.03, 0.03 / 1.4 );
|
|
98
|
+
|
|
99
|
+
// Get interpolated current level
|
|
100
|
+
float frameCurrent = texelFetch ( iChannel1, ivec2 ( 0 ), 0 ).r;
|
|
101
|
+
vec2 bloomedCoord = ( uv - 0.5 ) * ( 1.0 - ( frameCurrent * bloomFactor * crtBloomExpansion ) ) + 0.5;
|
|
102
|
+
|
|
103
|
+
vec2 cRaw = ( uv - 0.5) * 2.0;
|
|
104
|
+
vec2 cBloom = ( bloomedCoord - 0.5 ) * 2.0;
|
|
105
|
+
|
|
106
|
+
vec2 distortionStrength = abs ( cRaw.yx ) / vec2 ( 5.0, 4.0 );
|
|
107
|
+
vec2 distortionFactor = 1.0 + distortionStrength * distortionStrength;
|
|
108
|
+
|
|
109
|
+
cBloom *= distortionFactor;
|
|
110
|
+
|
|
111
|
+
vec2 finalWarpedUV = cBloom / 2.0 + 0.5;
|
|
112
|
+
|
|
113
|
+
return mix ( bloomedCoord, finalWarpedUV, level );
|
|
114
|
+
}
|
|
115
|
+
*/
|
|
116
|
+
//-----------------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
vec3 gausBlurWebcam ( sampler2D textY, sampler2D textUV, vec2 uv, float radius )
|
|
119
|
+
{
|
|
120
|
+
float lod = log2 ( max ( 1.0, radius * 5.0 ) );
|
|
121
|
+
|
|
122
|
+
vec2 currentTexSize = vec2 ( textureSize ( textY, int ( lod ) ) );
|
|
123
|
+
vec2 texelSize = 1.0 / vec2 ( currentTexSize );
|
|
124
|
+
float fractionalRadius = fract ( lod ) + 1.0;
|
|
125
|
+
vec2 scale = texelSize * fractionalRadius;
|
|
126
|
+
|
|
127
|
+
vec3 accumYUV = vec3 ( 0.0 );
|
|
128
|
+
float accumWeight = 0.0;
|
|
129
|
+
|
|
130
|
+
const float samples = 8.0;
|
|
131
|
+
for ( float i = -samples; i <= samples; i++ )
|
|
132
|
+
{
|
|
133
|
+
float weight = exp ( -0.5 * ( i * i ) / ( samples * samples ) );
|
|
134
|
+
vec2 offset = vec2 ( i / samples ) * scale;
|
|
135
|
+
|
|
136
|
+
// --- HORIZONTAL PASS ---
|
|
137
|
+
vec2 uvH = uv + vec2 ( offset.x, 0.0 );
|
|
138
|
+
float yH = textureLod ( textY, uvH, lod ).r;
|
|
139
|
+
vec4 cH = textureLod ( textUV, uvH, max(0.0, lod - 1.0) );
|
|
140
|
+
vec2 uv2H = crtWebcamFormat == 1 ? cH.ga : cH.rg;
|
|
141
|
+
|
|
142
|
+
// --- VERTICAL PASS ---
|
|
143
|
+
vec2 uvV = uv + vec2 ( 0.0, offset.y );
|
|
144
|
+
float yV = textureLod ( textY, uvV, lod ).r;
|
|
145
|
+
vec4 cV = textureLod ( textUV, uvV, max(0.0, lod - 1.0) );
|
|
146
|
+
vec2 uv2V = crtWebcamFormat == 1 ? cV.ga : cV.rg;
|
|
147
|
+
|
|
148
|
+
// Accumulate raw YUV channels directly [1]
|
|
149
|
+
accumYUV += vec3(yH, uv2H) * weight;
|
|
150
|
+
accumYUV += vec3(yV, uv2V) * weight;
|
|
151
|
+
|
|
152
|
+
accumWeight += weight * 2.0; // Two samples per step
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return accumYUV / accumWeight;
|
|
156
|
+
}
|
|
157
|
+
//-----------------------------------------------------------------------------
|
|
158
|
+
|
|
159
|
+
uniform float crtAmbient = 0.5;
|
|
160
|
+
|
|
161
|
+
vec3 ambient ( vec3 col )
|
|
162
|
+
{
|
|
163
|
+
vec3 ambientCol = mix ( vec3 ( 1.0, 0.890, 1.118 ), vec3 ( 1.0, 0.787, 1.376 ), crtAmbient );
|
|
164
|
+
return max ( col, crtAmbient * 0.02 * ambientCol );
|
|
165
|
+
}
|
|
166
|
+
//-----------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
void main ()
|
|
169
|
+
{
|
|
170
|
+
// Get CRT curvature
|
|
171
|
+
vec2 cuv = curve ( fragCoord, crtCurve );
|
|
172
|
+
vec3 col = texture ( iChannel0, cuv ).rgb;
|
|
173
|
+
|
|
174
|
+
// Add vignette
|
|
175
|
+
col = mix ( col, ambient ( vec3 ( 0.0 ) ), vignette ( cuv ) );
|
|
176
|
+
|
|
177
|
+
// Phosphor has its own color
|
|
178
|
+
col = ambient ( col );
|
|
179
|
+
|
|
180
|
+
// Reflection in glass
|
|
181
|
+
const vec3 glassTint = vec3 ( 0.8, 0.9, 1.0 );
|
|
182
|
+
|
|
183
|
+
vec3 rfl = vec3 ( 0.0 );
|
|
184
|
+
|
|
185
|
+
if ( crtSource )
|
|
186
|
+
{
|
|
187
|
+
// Glass distortion
|
|
188
|
+
vec2 camCoord = glassDistortion ( vec2 ( 1.0 ) - counterRotate ( fragCoord ), crtDistortion, crtRflCorrection );
|
|
189
|
+
|
|
190
|
+
// Zoom shrinks the sample window around center, the distortion shape
|
|
191
|
+
// stays that of the full glass
|
|
192
|
+
camCoord = ( camCoord - 0.5 ) / camZoom + 0.5;
|
|
193
|
+
// vec3 yuv = gausBlurWebcam ( iChannel2, iChannel3, camCoord, 2.0 );
|
|
194
|
+
|
|
195
|
+
// Webcam planes: NV12 = Y in iChannel2.r, UV in iChannel3.rg; YUY2 = the
|
|
196
|
+
// packed rows twice, Y in iChannel2.r, U/V in iChannel3.ga
|
|
197
|
+
vec4 camC = texture ( iChannel3, camCoord );
|
|
198
|
+
vec3 yuv = vec3 ( texture ( iChannel2, camCoord ).r, crtWebcamFormat == 1 ? camC.ga : camC.rg );
|
|
199
|
+
|
|
200
|
+
mat3 yuvMat = mat3 ( yuvCol0, yuvCol1, yuvCol2 );
|
|
201
|
+
rfl = clamp ( yuvMat * yuv + yuvBias, 0.0, 1.0 );
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
{
|
|
205
|
+
// Glass reflection texture
|
|
206
|
+
rfl = texture ( iChannel1, glassDistortion ( counterRotate ( fragCoord ), crtDistortion * 0.1, 1.0 ) ).rgb;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
vec3 rflLin = srgbToLinear ( rfl );
|
|
210
|
+
vec3 blend = ( rflLin * rflLin * rflLin ) * 0.125 * crtReflection * glassTint;
|
|
211
|
+
|
|
212
|
+
vec3 outLin = screen ( col, blend );
|
|
213
|
+
|
|
214
|
+
col = linearToSrgb ( outLin );
|
|
215
|
+
// col = rfl;
|
|
216
|
+
|
|
217
|
+
// Mask out corners, no CRT has 90 degree angles
|
|
218
|
+
float mask = roundedMask ( cuv * iResolution.xy, iResolution.xy, iResolution.x * 0.03 );
|
|
219
|
+
|
|
220
|
+
// Apply mask
|
|
221
|
+
col = mix ( backCol, col, mask );
|
|
222
|
+
|
|
223
|
+
fragColor = vec4 ( col, 1.0 );
|
|
224
|
+
}
|
|
225
|
+
//-----------------------------------------------------------------------------
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#include "includes/colorSpaces.glsl"
|
|
2
|
+
#include "includes/getMipMapColor.glsl"
|
|
3
|
+
|
|
4
|
+
uniform float crtHalation = 1.0;
|
|
5
|
+
|
|
6
|
+
//-----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
vec3 halation ( sampler2D tex, vec3 col, vec2 uv )
|
|
9
|
+
{
|
|
10
|
+
// wide diffuse halo: weights sum to 1.0, biased toward widest mip
|
|
11
|
+
vec3 halCol;
|
|
12
|
+
float lod = lodForRadius ( tex, 0.06 );
|
|
13
|
+
halCol = getMipMapColorJittered ( tex, uv, lod ) * 0.2;
|
|
14
|
+
halCol += getMipMapColorJittered ( tex, uv, lod - 1.0 ) * 0.3;
|
|
15
|
+
halCol += getMipMapColorJittered ( tex, uv, lod - 2.0 ) * 0.5;
|
|
16
|
+
|
|
17
|
+
// scatter mixes neighboring phosphors -> slight desaturation
|
|
18
|
+
float luma = getLinearLuma ( halCol );
|
|
19
|
+
halCol = mix ( halCol, vec3 ( luma ), 0.1 );
|
|
20
|
+
|
|
21
|
+
float kHal = crtHalation * crtHalation * 0.15;
|
|
22
|
+
|
|
23
|
+
return mix ( col, halCol, kHal );
|
|
24
|
+
}
|
|
25
|
+
//-----------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
void main ()
|
|
28
|
+
{
|
|
29
|
+
vec3 col = texture ( iChannel0, fragCoord ).rgb;
|
|
30
|
+
|
|
31
|
+
col = halation ( iChannel0, col, fragCoord );
|
|
32
|
+
|
|
33
|
+
fragColor = vec4 ( col, 1.0 );
|
|
34
|
+
}
|
|
35
|
+
//-----------------------------------------------------------------------------
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#include "includes/mathDefines.glsl"
|
|
2
|
+
#include "includes/overscan.glsl"
|
|
3
|
+
#include "includes/common.glsl"
|
|
4
|
+
#include "includes/colorSpaces.glsl"
|
|
5
|
+
|
|
6
|
+
uniform float crtBleed;
|
|
7
|
+
uniform vec2 crtRedOffset = vec2 ( 0.0, 0.0 );
|
|
8
|
+
uniform vec2 crtGreenOffset = vec2 ( 0.0, 0.0 );
|
|
9
|
+
uniform vec2 crtBlueOffset = vec2 ( 0.0, 0.0 );
|
|
10
|
+
uniform float crtHoffset;
|
|
11
|
+
uniform float crtGlow;
|
|
12
|
+
uniform float crtAmbient = 0.5;
|
|
13
|
+
uniform float crtConvergence = 1.0;
|
|
14
|
+
|
|
15
|
+
//-----------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
vec3 bleed ( vec2 uv )
|
|
18
|
+
{
|
|
19
|
+
// H-wave
|
|
20
|
+
float x = sin ( 0.1 * iTime + uv.y * 13.0 ) * sin ( 0.23 * iTime + uv.y * 19.0 ) * sin ( 0.3 + 0.11 * iTime + uv.y * 23.0 ) * 0.0012;
|
|
21
|
+
float o = sin ( fragCoord.y / 2.0 ) / 500.0;
|
|
22
|
+
vec2 xOff = vec2 ( ( x + o * 0.5 ) * crtHoffset, 0.0 );
|
|
23
|
+
vec2 str = vec2 ( -0.005, 0.005 );
|
|
24
|
+
|
|
25
|
+
// Radial Misconvergence
|
|
26
|
+
vec2 coord = uv * 2.0 - 1.0;
|
|
27
|
+
float radius2 = dot ( coord, coord );
|
|
28
|
+
float k = 0.005 * ( crtConvergence * crtConvergence );
|
|
29
|
+
vec2 r_distortion = coord * radius2 * k;
|
|
30
|
+
vec2 b_distortion = coord * radius2 * -k;
|
|
31
|
+
|
|
32
|
+
// Separation
|
|
33
|
+
vec3 col = vec3 ( texture ( iChannel0, uv + crtRedOffset * crtBleed * str + xOff + r_distortion ).r,
|
|
34
|
+
texture ( iChannel0, uv + crtGreenOffset * crtBleed * str + xOff ).g,
|
|
35
|
+
texture ( iChannel0, uv + crtBlueOffset * crtBleed * str + xOff + b_distortion ).b );
|
|
36
|
+
|
|
37
|
+
return col;
|
|
38
|
+
}
|
|
39
|
+
//-----------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
vec3 ambient ( vec3 col )
|
|
42
|
+
{
|
|
43
|
+
vec3 ambientCol = mix ( vec3 ( 1.0, 0.95, 1.05 ), vec3 ( 1.0, 0.9, 1.15 ), crtAmbient );
|
|
44
|
+
return max ( col, crtAmbient * 0.015 * ambientCol );
|
|
45
|
+
}
|
|
46
|
+
//-----------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
uniform float crtScanlines = 0.5;
|
|
49
|
+
uniform float crtLinePixels = 5.0; // Physical on-screen pixels per source line
|
|
50
|
+
|
|
51
|
+
// A small or distant screen blends the fine patterns away before the eye,
|
|
52
|
+
// and a small render target could only alias them, so they fade out early.
|
|
53
|
+
// featureScale: how much larger than the reference the pattern renders
|
|
54
|
+
float detailFade ( float featureScale )
|
|
55
|
+
{
|
|
56
|
+
return smoothstep ( 2.0, 5.0, crtLinePixels * featureScale );
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// y in source lines: the beam lights each line's center, the gap between
|
|
60
|
+
// lines is what reads as scanlines
|
|
61
|
+
vec3 scanlines ( vec3 col, float y )
|
|
62
|
+
{
|
|
63
|
+
float luma = getLinearLuma ( col );
|
|
64
|
+
|
|
65
|
+
// Distance from the line's center, 0.5 = the boundary to the neighbor
|
|
66
|
+
float dist = abs ( fract ( y ) - 0.5 );
|
|
67
|
+
|
|
68
|
+
// A brighter beam widens the lit core
|
|
69
|
+
float width = mix ( 0.2, 0.35, luma );
|
|
70
|
+
|
|
71
|
+
float line = 1.0 - smoothstep ( width - 0.25, width + 0.25, dist );
|
|
72
|
+
|
|
73
|
+
// Normalize so the pattern's mean stays 1.0
|
|
74
|
+
line /= 2.0 * width;
|
|
75
|
+
|
|
76
|
+
return col * mix ( 1.0, line, crtScanlines * detailFade ( 1.0 ) );
|
|
77
|
+
}
|
|
78
|
+
//-----------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
uniform float crtMask = 0.5;
|
|
81
|
+
|
|
82
|
+
// Mask tiles across the quad (x, y). 0 = legacy fixed density. A host passes
|
|
83
|
+
// sourceSize * texelsPerPixel / maskSize to size the mask relative to the
|
|
84
|
+
// source pixels instead.
|
|
85
|
+
uniform vec2 crtMaskRepeats = vec2 ( 0.0 );
|
|
86
|
+
|
|
87
|
+
vec3 shadowMask ( vec3 col, vec2 uv )
|
|
88
|
+
{
|
|
89
|
+
// 64px is the reference mask size, a larger bitmap renders proportionally
|
|
90
|
+
// larger slots (the SX-64 look)
|
|
91
|
+
const vec2 refSize = vec2 ( 64.0 * 64.0 * 0.75 );
|
|
92
|
+
|
|
93
|
+
vec2 texSize = vec2 ( textureSize ( iChannel1, 0 ).xy );
|
|
94
|
+
vec2 repeats = crtMaskRepeats.x > 0.0 ? crtMaskRepeats : refSize / texSize;
|
|
95
|
+
vec3 mask = texture ( iChannel1, uv * repeats ).rgb;
|
|
96
|
+
mask = srgbToLinear ( mask );
|
|
97
|
+
|
|
98
|
+
// per-channel mean of the tinted mask = top mip level
|
|
99
|
+
vec3 avg = srgbToLinear ( textureLod ( iChannel1, vec2 ( 0.5 ), 16.0 ).rgb );
|
|
100
|
+
|
|
101
|
+
// normalize so the blended mask averages to 1.0 per channel
|
|
102
|
+
mask /= max ( avg, vec3 ( 0.001 ) );
|
|
103
|
+
|
|
104
|
+
// A coarser mask stays resolvable on smaller screens
|
|
105
|
+
mask = mix ( vec3 ( 1.0 ), mask, crtMask * detailFade ( texSize.x / 64.0 ) );
|
|
106
|
+
|
|
107
|
+
return mask * col;
|
|
108
|
+
}
|
|
109
|
+
//-----------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
uniform float crtHum = 0.0; // AC hum: slow-rolling dark bands (beat between mains and refresh rate)
|
|
112
|
+
|
|
113
|
+
vec3 humBar ( vec3 col )
|
|
114
|
+
{
|
|
115
|
+
float band = 0.5 + 0.5 * sin ( 2.0 * PI * ( fragCoord.y * 1.5 - iTime * 0.15 ) );
|
|
116
|
+
return col * ( 1.0 - crtHum * 0.4 * band );
|
|
117
|
+
}
|
|
118
|
+
//-----------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
uniform float u_deltaTime = 0.016;
|
|
121
|
+
uniform vec3 u_decayFactor = vec3 ( 18.0, 10.0, 20.0 );
|
|
122
|
+
uniform float u_phosphorFlicker = 0.0;
|
|
123
|
+
|
|
124
|
+
vec3 phosphorDecay ( vec3 col )
|
|
125
|
+
{
|
|
126
|
+
col *= abs ( sin ( iTime * crtRefreshRate * PI + fragCoord.y * PI ) * u_phosphorFlicker + ( 1.0 - u_phosphorFlicker ) );
|
|
127
|
+
|
|
128
|
+
vec3 prev = texture ( iChannel2, fragCoord ).rgb * u_decayFactor;
|
|
129
|
+
|
|
130
|
+
return max ( col, prev );
|
|
131
|
+
}
|
|
132
|
+
//-----------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
uniform float crtBloomExpansion = 1.0;
|
|
135
|
+
|
|
136
|
+
vec2 bloomExpansion ( vec2 uv )
|
|
137
|
+
{
|
|
138
|
+
const vec2 bloomFactor = vec2 ( 0.03, 0.03 / 1.4 );
|
|
139
|
+
|
|
140
|
+
// Get interpolated current level
|
|
141
|
+
float frameCurrent = texelFetch ( iChannel3, ivec2 ( 0 ), 0 ).r;
|
|
142
|
+
vec2 bloomedCoord = ( uv - 0.5 ) * ( 1.0 - ( frameCurrent * bloomFactor * crtBloomExpansion ) ) + 0.5;
|
|
143
|
+
|
|
144
|
+
return bloomedCoord;
|
|
145
|
+
}
|
|
146
|
+
//-----------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
vec3 reduceBlue ( vec3 col )
|
|
149
|
+
{
|
|
150
|
+
// Bloom expansion also reduces blue level
|
|
151
|
+
col.b = col.b / ( 1.0 + crtBloomExpansion * 0.2 * col.b );
|
|
152
|
+
|
|
153
|
+
return col;
|
|
154
|
+
}
|
|
155
|
+
//-----------------------------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
void main ()
|
|
158
|
+
{
|
|
159
|
+
vec3 col;
|
|
160
|
+
vec2 uv = overscan ( fragCoord );
|
|
161
|
+
|
|
162
|
+
uv = bloomExpansion ( uv );
|
|
163
|
+
|
|
164
|
+
// CRT-style post FX
|
|
165
|
+
col = bleed ( uv );
|
|
166
|
+
col = srgbToLinear ( col );
|
|
167
|
+
col = reduceBlue ( col );
|
|
168
|
+
col = scanlines ( col, uv.y * float ( textureSize ( iChannel0, 0 ).y ) );
|
|
169
|
+
col = shadowMask ( col, fragCoord );
|
|
170
|
+
col = humBar ( col );
|
|
171
|
+
col = phosphorDecay ( col );
|
|
172
|
+
|
|
173
|
+
fragColor = vec4 ( col, 1.0 );
|
|
174
|
+
}
|
|
175
|
+
//-----------------------------------------------------------------------------
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#include "includes/mathDefines.glsl"
|
|
2
|
+
#include "includes/common.glsl"
|
|
3
|
+
#include "includes/grain.glsl"
|
|
4
|
+
#include "includes/colorSpaces.glsl"
|
|
5
|
+
|
|
6
|
+
//-----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
uniform float decCrosstalk = 0.25;
|
|
9
|
+
uniform float decCrossColor = 1.0; // 0 = clean (comb), 1 = heavy rainbowing (cheap notch)
|
|
10
|
+
uniform float decDrift = 1.0;
|
|
11
|
+
uniform float decNoise = 0.1; // 0 = perfect, 1 = total breakup
|
|
12
|
+
|
|
13
|
+
#define CC_TAPS 8 // taps across one subcarrier period
|
|
14
|
+
|
|
15
|
+
//
|
|
16
|
+
// NTSC cross-talk:
|
|
17
|
+
// - dot crawl : chroma leaks into luma; per-line half-cycle stagger + per-frame advance = diagonal upward crawl
|
|
18
|
+
// - cross-color : luma energy at the subcarrier frequency is demodulated into false chroma (rainbowing)
|
|
19
|
+
// Both share ONE subcarrier oscillator, so the artifacts are physically coherent.
|
|
20
|
+
//
|
|
21
|
+
vec3 decGetCrosstalk ( vec3 signal, vec2 uv, sampler2D tex )
|
|
22
|
+
{
|
|
23
|
+
float texH = float ( textureSize ( tex, 0 ).y );
|
|
24
|
+
|
|
25
|
+
// dot-crawl phase (per-line sign -0.5 -> correct upward diagonal crawl)
|
|
26
|
+
float chroma_phase = iTime * crtRefreshRate * 0.5 * PI;
|
|
27
|
+
float mod_phase = chroma_phase + ( uv.x + uv.y * -0.5 ) * ( 0.5 * PI ) * texH * 2.0;
|
|
28
|
+
float i_mod = cos ( mod_phase );
|
|
29
|
+
float q_mod = sin ( mod_phase );
|
|
30
|
+
|
|
31
|
+
// dot crawl: residual modulated chroma leaks into luma (additive)
|
|
32
|
+
float modChroma = signal.y * i_mod + signal.z * q_mod; // I·cos + Q·sin
|
|
33
|
+
signal.x += decCrosstalk * modChroma * 0.25;
|
|
34
|
+
|
|
35
|
+
// cross-color: demodulate clean luma against the SAME subcarrier
|
|
36
|
+
if ( decCrossColor > 0.0 )
|
|
37
|
+
{
|
|
38
|
+
// horizontal freq = (0.5*PI)*texH*2.0 = PI*texH radians per unit uv.x
|
|
39
|
+
// => cycles per unit uv.x = texH*0.5 ; period = 1/(texH*0.5)
|
|
40
|
+
float period = 1.0 / ( texH * 0.5 );
|
|
41
|
+
float stepUV = period / float ( CC_TAPS );
|
|
42
|
+
|
|
43
|
+
float sumI = 0.0;
|
|
44
|
+
float sumQ = 0.0;
|
|
45
|
+
|
|
46
|
+
for ( int t = 0; t < CC_TAPS; t++ )
|
|
47
|
+
{
|
|
48
|
+
float o = ( float ( t ) - float ( CC_TAPS ) * 0.5 + 0.5 ) * stepUV;
|
|
49
|
+
float luma = texture ( tex, uv + vec2 ( o, 0.0 ) ).r;
|
|
50
|
+
float phase = mod_phase + o * ( PI * texH );
|
|
51
|
+
|
|
52
|
+
sumI += luma * cos ( phase );
|
|
53
|
+
sumQ += luma * sin ( phase );
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
sumI /= float ( CC_TAPS );
|
|
57
|
+
sumQ /= float ( CC_TAPS );
|
|
58
|
+
|
|
59
|
+
// factor 3.0 baked in: uniform 0..1 maps to clean..worst-case
|
|
60
|
+
signal.y += sumI * decCrossColor * 3.0;
|
|
61
|
+
signal.z += sumQ * decCrossColor * 3.0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return signal;
|
|
65
|
+
}
|
|
66
|
+
//-----------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
float getAnalogDefects ( int texH )
|
|
69
|
+
{
|
|
70
|
+
// Apply hue offset with "live" jitter and drift
|
|
71
|
+
|
|
72
|
+
// Tint drift: very slow thermal wander (minutes)
|
|
73
|
+
float slowDrift = sin ( iTime * 0.04 ) * decDrift * 10.0;
|
|
74
|
+
|
|
75
|
+
// Tiny fast component from signal instability
|
|
76
|
+
float srcLine = floor ( fragCoord.y * float ( texH ) );
|
|
77
|
+
float microJitter = ( decRandom_v2_f ( vec2 ( 0.0, srcLine ), iTime ) - 0.5 ) * decDrift * 10.0;
|
|
78
|
+
|
|
79
|
+
return radians ( slowDrift + microJitter );
|
|
80
|
+
}
|
|
81
|
+
//-----------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
#include "includes/verticalRoll.glsl"
|
|
84
|
+
#include "includes/getSignal.glsl"
|
|
85
|
+
|
|
86
|
+
void main ()
|
|
87
|
+
{
|
|
88
|
+
int texH = textureSize ( iChannel0, 0 ).y;
|
|
89
|
+
|
|
90
|
+
// Get Y-offset for roll emulation
|
|
91
|
+
float rollOffset = vRollOffset ();
|
|
92
|
+
|
|
93
|
+
// Get phase-defect inherent to analog signals
|
|
94
|
+
float angle = getAnalogDefects ( texH );
|
|
95
|
+
|
|
96
|
+
// Complete signal for this line
|
|
97
|
+
vec3 yiq = getSignal ( fragCoord, angle, rollOffset );
|
|
98
|
+
|
|
99
|
+
// Apply brightness, contrast, and saturation
|
|
100
|
+
yiq = encApplyBriConSat ( yiq );
|
|
101
|
+
|
|
102
|
+
// Convert YIQ to RGB
|
|
103
|
+
fragColor = vec4 ( encApplyTint ( yiq2rgb ( yiq ) ), 0.0 );
|
|
104
|
+
}
|
|
105
|
+
//-----------------------------------------------------------------------------
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#include "includes/mathDefines.glsl"
|
|
2
|
+
#include "includes/common.glsl"
|
|
3
|
+
#include "includes/grain.glsl"
|
|
4
|
+
#include "includes/colorSpaces.glsl"
|
|
5
|
+
|
|
6
|
+
//-----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
uniform float decCrosstalk = 0.25;
|
|
9
|
+
uniform float decPhase = 22.5; // V-switch alternation angle in degrees
|
|
10
|
+
uniform float decPALDelayLine = 1.0;
|
|
11
|
+
uniform float decDrift = 0.0;
|
|
12
|
+
uniform float decNoise = 0.1; // 0 = perfect, 1 = total breakup
|
|
13
|
+
|
|
14
|
+
vec3 decGetCrosstalk ( vec3 signal, vec2 uv, sampler2D tex )
|
|
15
|
+
{
|
|
16
|
+
float texH = float ( textureSize ( tex, 0 ).y );
|
|
17
|
+
|
|
18
|
+
float drift = ( decRandom_v2_f ( vec2 ( 0.0 ), iTime * 0.1 ) - 0.5 );
|
|
19
|
+
float chroma_phase = iTime * crtRefreshRate * 0.5 * PI + drift;
|
|
20
|
+
float mod_phase = chroma_phase + ( uv.x + uv.y * -0.5 ) * ( 0.5 * PI ) * texH * 2.0;
|
|
21
|
+
float i_mod = cos ( mod_phase );
|
|
22
|
+
float q_mod = sin ( mod_phase );
|
|
23
|
+
|
|
24
|
+
// PAL: V (signal.z) phase alternates every line -> dot crawl partially
|
|
25
|
+
// self-cancels between line pairs (finer/weaker than NTSC)
|
|
26
|
+
float palSign = ( mod ( floor ( uv.y * texH ), 2.0 ) < 1.0 ) ? 1.0 : -1.0;
|
|
27
|
+
|
|
28
|
+
// dot crawl: residual modulated chroma leaks into luma (additive)
|
|
29
|
+
float modChroma = signal.y * i_mod + palSign * signal.z * q_mod;
|
|
30
|
+
signal.x += decCrosstalk * 0.25 * modChroma;
|
|
31
|
+
|
|
32
|
+
return signal;
|
|
33
|
+
}
|
|
34
|
+
//-----------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
#include "includes/verticalRoll.glsl"
|
|
37
|
+
#include "includes/getSignal.glsl"
|
|
38
|
+
|
|
39
|
+
float getAnalogDefects ( int texH )
|
|
40
|
+
{
|
|
41
|
+
// Apply phase offset with "live" jitter and drift
|
|
42
|
+
float srcLine = floor ( fragCoord.y * float ( texH ) );
|
|
43
|
+
float lineSign = ( mod ( srcLine, 2.0 ) < 1.0 ) ? 1.0 : -1.0;
|
|
44
|
+
|
|
45
|
+
float drift = sin ( iTime * 1.5 + srcLine * 0.3 ) * decDrift * 6.0;
|
|
46
|
+
float jitter = ( decRandom_v2_f ( vec2 ( 0.0, srcLine ), iTime ) - 0.5 ) * decDrift * 8.0;
|
|
47
|
+
|
|
48
|
+
return lineSign * radians ( decPhase + drift + jitter );
|
|
49
|
+
}
|
|
50
|
+
//-----------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
//
|
|
53
|
+
// PAL decoder
|
|
54
|
+
// Signal chain -> delay-line cancellation -> receiver/display stage
|
|
55
|
+
//
|
|
56
|
+
void main ()
|
|
57
|
+
{
|
|
58
|
+
int texH = textureSize ( iChannel0, 0 ).y;
|
|
59
|
+
|
|
60
|
+
// Get Y-offset for roll emulation
|
|
61
|
+
float rollOffset = vRollOffset ();
|
|
62
|
+
|
|
63
|
+
// Get phase-defect inherent to analog signals
|
|
64
|
+
float angle = getAnalogDefects ( texH );
|
|
65
|
+
|
|
66
|
+
// Two complete, independent signal lines
|
|
67
|
+
vec3 here = getSignal ( fragCoord, angle, rollOffset );
|
|
68
|
+
vec3 prev = getSignal ( fragCoord - vec2 ( 0.0, 1.0 / float ( texH ) ), -angle, rollOffset );
|
|
69
|
+
|
|
70
|
+
// PAL delay-line: average adjacent lines' rotated chroma. The +/-22.5°
|
|
71
|
+
// rotations cancel back to true hue. Full average = clean; none = Hanover
|
|
72
|
+
// bars. Differing interference jitter makes lines cancel imperfectly.
|
|
73
|
+
vec3 yuv = here;
|
|
74
|
+
vec2 avg = ( here.gb + prev.gb ) * 0.5;
|
|
75
|
+
yuv.gb = mix ( here.gb, avg, decPALDelayLine );
|
|
76
|
+
|
|
77
|
+
// Apply brightness, contrast, and saturation
|
|
78
|
+
yuv = encApplyBriConSat ( yuv );
|
|
79
|
+
|
|
80
|
+
// Convert YUV to RGB
|
|
81
|
+
fragColor = vec4 ( encApplyTint ( yuv2rgb ( yuv ) ), 0.0 );
|
|
82
|
+
}
|
|
83
|
+
//-----------------------------------------------------------------------------
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#include "includes/mathDefines.glsl"
|
|
2
|
+
#include "includes/common.glsl"
|
|
3
|
+
#include "includes/colorSpaces.glsl"
|
|
4
|
+
|
|
5
|
+
//-----------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
// NTSC decoder
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
void main ()
|
|
12
|
+
{
|
|
13
|
+
// Get YIQ color
|
|
14
|
+
vec3 yiq = texture ( iChannel0, fragCoord ).rgb;
|
|
15
|
+
|
|
16
|
+
// Textures can't store negative values, we have to transpose
|
|
17
|
+
yiq.yz -= 0.5;
|
|
18
|
+
|
|
19
|
+
// Apply brightness, constrast, and saturation
|
|
20
|
+
yiq = encApplyBriConSat ( yiq );
|
|
21
|
+
|
|
22
|
+
// Convert YIQ to RGB
|
|
23
|
+
fragColor = vec4 ( encApplyTint ( yiq2rgb ( yiq ) ), 0.0 );
|
|
24
|
+
}
|
|
25
|
+
//-----------------------------------------------------------------------------
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#include "includes/mathDefines.glsl"
|
|
2
|
+
#include "includes/common.glsl"
|
|
3
|
+
#include "includes/colorSpaces.glsl"
|
|
4
|
+
|
|
5
|
+
//-----------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
// PAL decoder
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
void main ()
|
|
12
|
+
{
|
|
13
|
+
// Get YUV color
|
|
14
|
+
vec3 yuv = texture ( iChannel0, fragCoord ).rgb;
|
|
15
|
+
|
|
16
|
+
// Textures can't store negative values, we have to transpose
|
|
17
|
+
yuv.yz -= 0.5;
|
|
18
|
+
|
|
19
|
+
// Apply brightness, constrast, and saturation
|
|
20
|
+
yuv = encApplyBriConSat ( yuv );
|
|
21
|
+
|
|
22
|
+
// Convert YUV to RGB
|
|
23
|
+
fragColor = vec4 ( encApplyTint ( yuv2rgb ( yuv ) ), 0.0 );
|
|
24
|
+
}
|
|
25
|
+
//-----------------------------------------------------------------------------
|