@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
package/src/presets.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Settings defaults, the preset YAML subset and asset/mask resolution.
|
|
2
|
+
//
|
|
3
|
+
// The numbers mirror the `crt:` section of the presets shipped in
|
|
4
|
+
// Toddler-Boy/CRTEmulation-Data (0..100 sliders) and Lime's host defaults.
|
|
5
|
+
|
|
6
|
+
export const PRESET_NAMES = [
|
|
7
|
+
"Default",
|
|
8
|
+
"SX-64",
|
|
9
|
+
"VICE",
|
|
10
|
+
"Cheap and broken TV",
|
|
11
|
+
"C64 Ultimate HDMI",
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export const MASKS = [
|
|
15
|
+
"Slot Mask",
|
|
16
|
+
"Shadow Mask",
|
|
17
|
+
"Shadow Mask EDP",
|
|
18
|
+
"Aperture Grille",
|
|
19
|
+
"SX-64",
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/** Defaults from lime_CRTEmulation.h, expressed as 0..1 like the rest. */
|
|
23
|
+
export const DEFAULT_SETTINGS = {
|
|
24
|
+
// analogue signal (decoder)
|
|
25
|
+
jailbars: 0.5,
|
|
26
|
+
noise: 0.15,
|
|
27
|
+
sharpening: 0.3,
|
|
28
|
+
lumaBlur: 0.5,
|
|
29
|
+
chromaBlur: 0.5,
|
|
30
|
+
crosstalk: 0.2,
|
|
31
|
+
phase: 22.5,
|
|
32
|
+
hannover: 0.9,
|
|
33
|
+
rainbowing: 0.5,
|
|
34
|
+
drift: 0.2,
|
|
35
|
+
|
|
36
|
+
// CRT render
|
|
37
|
+
curve: 0.2,
|
|
38
|
+
rotation: 0,
|
|
39
|
+
bleed: 0.2,
|
|
40
|
+
bleedRed: [0.5, -0.1],
|
|
41
|
+
bleedGreen: [0.5, -0.1],
|
|
42
|
+
bleedBlue: [0.5, -0.1],
|
|
43
|
+
convergence: 0.2,
|
|
44
|
+
hWave: 0.5,
|
|
45
|
+
expansion: 1,
|
|
46
|
+
scanlines: 0.25,
|
|
47
|
+
mask: 0.25,
|
|
48
|
+
maskBitmap: "Slot Mask",
|
|
49
|
+
phosphorDecay: 0.6,
|
|
50
|
+
vignette: 0.6,
|
|
51
|
+
adjacent: 0.5,
|
|
52
|
+
halation: 0.5,
|
|
53
|
+
ambient: 0.6,
|
|
54
|
+
|
|
55
|
+
// not in the YAML presets, but exposed by the module
|
|
56
|
+
reflections: 0.25,
|
|
57
|
+
overscan: 0,
|
|
58
|
+
hum: 0,
|
|
59
|
+
brightness: 0.5,
|
|
60
|
+
contrast: 0.8,
|
|
61
|
+
saturation: 0.5,
|
|
62
|
+
tint: 0,
|
|
63
|
+
|
|
64
|
+
// renderer side
|
|
65
|
+
lines: 270,
|
|
66
|
+
analog: "off",
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const KEY_MAP = {
|
|
70
|
+
jailbars: "jailbars",
|
|
71
|
+
noise: "noise",
|
|
72
|
+
sharpening: "sharpening",
|
|
73
|
+
"luma-blur": "lumaBlur",
|
|
74
|
+
"chroma-blur": "chromaBlur",
|
|
75
|
+
crosstalk: "crosstalk",
|
|
76
|
+
phase: "phase",
|
|
77
|
+
hannover: "hannover",
|
|
78
|
+
rainbowing: "rainbowing",
|
|
79
|
+
drift: "drift",
|
|
80
|
+
curve: "curve",
|
|
81
|
+
rotation: "rotation",
|
|
82
|
+
bleed: "bleed",
|
|
83
|
+
"bleed-red": "bleedRed",
|
|
84
|
+
"bleed-green": "bleedGreen",
|
|
85
|
+
"bleed-blue": "bleedBlue",
|
|
86
|
+
convergence: "convergence",
|
|
87
|
+
"h-wave": "hWave",
|
|
88
|
+
expansion: "expansion",
|
|
89
|
+
scanlines: "scanlines",
|
|
90
|
+
mask: "mask",
|
|
91
|
+
"mask-bitmap": "maskBitmap",
|
|
92
|
+
"phosphor-decay": "phosphorDecay",
|
|
93
|
+
vignette: "vignette",
|
|
94
|
+
adjacent: "adjacent",
|
|
95
|
+
halation: "halation",
|
|
96
|
+
ambient: "ambient",
|
|
97
|
+
reflections: "reflections",
|
|
98
|
+
overscan: "overscan",
|
|
99
|
+
brightness: "brightness",
|
|
100
|
+
contrast: "contrast",
|
|
101
|
+
saturation: "saturation",
|
|
102
|
+
tint: "tint",
|
|
103
|
+
lines: "lines",
|
|
104
|
+
"scanlines-count": "lines",
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const PAIR_KEYS = new Set(["bleedRed", "bleedGreen", "bleedBlue"]);
|
|
108
|
+
const RAW_KEYS = new Set(["phase", "rotation"]);
|
|
109
|
+
const INT_KEYS = new Set(["lines"]);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Parse the tiny YAML subset used by the data repository: a top-level
|
|
113
|
+
* `crt:` mapping of `key: scalar-or-pair`.
|
|
114
|
+
*/
|
|
115
|
+
export function parsePresetYaml(text) {
|
|
116
|
+
const out = {};
|
|
117
|
+
for (const rawLine of text.split("\n")) {
|
|
118
|
+
const line = rawLine.trim();
|
|
119
|
+
if (!line || line.startsWith("#") || line === "crt:") continue;
|
|
120
|
+
|
|
121
|
+
const colon = line.indexOf(":");
|
|
122
|
+
if (colon < 0) continue;
|
|
123
|
+
const key = line.slice(0, colon).trim().toLowerCase();
|
|
124
|
+
const value = line.slice(colon + 1).trim();
|
|
125
|
+
const name = KEY_MAP[key];
|
|
126
|
+
if (!name) continue;
|
|
127
|
+
|
|
128
|
+
if (name === "maskBitmap") {
|
|
129
|
+
out.maskBitmap = value.replace(/^\$DATA\$\//, "");
|
|
130
|
+
} else if (PAIR_KEYS.has(name)) {
|
|
131
|
+
const [a, b] = value.split(",");
|
|
132
|
+
out[name] = [toPercent(a), toPercent(b)];
|
|
133
|
+
} else if (RAW_KEYS.has(name)) {
|
|
134
|
+
out[name] = Number(value);
|
|
135
|
+
} else if (INT_KEYS.has(name)) {
|
|
136
|
+
out[name] = Math.round(Number(value));
|
|
137
|
+
} else if (value === "true" || value === "false") {
|
|
138
|
+
out[name] = value === "true";
|
|
139
|
+
} else {
|
|
140
|
+
out[name] = toPercent(value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function toPercent(value) {
|
|
147
|
+
return Number(value) / 100;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function normalizeAnalog(value) {
|
|
151
|
+
switch (String(value ?? "off").toLowerCase()) {
|
|
152
|
+
case "off":
|
|
153
|
+
case "none":
|
|
154
|
+
case "rgb":
|
|
155
|
+
return "off";
|
|
156
|
+
case "pal":
|
|
157
|
+
return "pal";
|
|
158
|
+
case "ntsc":
|
|
159
|
+
case "yiq":
|
|
160
|
+
return "ntsc";
|
|
161
|
+
default:
|
|
162
|
+
throw new Error(`cathode: analog must be off, pal or ntsc (got ${value})`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Directory holding `Shaders/`, `CRT Masks/`, `Presets/` and `reflections.png`. */
|
|
167
|
+
export function resolveDataUrl(dataUrl) {
|
|
168
|
+
if (dataUrl) {
|
|
169
|
+
return new URL(dataUrl, document.baseURI).href;
|
|
170
|
+
}
|
|
171
|
+
// js/src -> repository root -> assets/crt
|
|
172
|
+
return new URL("../../assets/crt/", import.meta.url).href;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Locate the data directory. In the monorepo it lives at `assets/crt`; the
|
|
177
|
+
* published package carries a copy at `js/assets/crt`.
|
|
178
|
+
*/
|
|
179
|
+
export async function detectDataUrl(dataUrl) {
|
|
180
|
+
if (dataUrl) return resolveDataUrl(dataUrl);
|
|
181
|
+
const candidates = [
|
|
182
|
+
new URL("../assets/crt/", import.meta.url),
|
|
183
|
+
new URL("../../assets/crt/", import.meta.url),
|
|
184
|
+
];
|
|
185
|
+
for (const candidate of candidates) {
|
|
186
|
+
try {
|
|
187
|
+
const response = await fetch(
|
|
188
|
+
new URL("Shaders/crt-simulation.glsl", candidate),
|
|
189
|
+
{ method: "HEAD" },
|
|
190
|
+
);
|
|
191
|
+
if (response.ok) return candidate.href;
|
|
192
|
+
} catch {
|
|
193
|
+
// Try the next candidate.
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return candidates[candidates.length - 1].href;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function loadPreset(dataUrl, name) {
|
|
200
|
+
const url = new URL(`Presets/${encodeURIComponent(name)}.yml`, dataUrl);
|
|
201
|
+
const response = await fetch(url);
|
|
202
|
+
if (!response.ok) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`cathode: unknown preset '${name}' (HTTP ${response.status}); ` +
|
|
205
|
+
`available: ${PRESET_NAMES.join(", ")}`,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return parsePresetYaml(await response.text());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Build the effective settings from a preset name and option overrides.
|
|
213
|
+
* Overrides use the camelCase keys of DEFAULT_SETTINGS; kebab-case preset keys
|
|
214
|
+
* are accepted too, and percentage values are given as 0..1.
|
|
215
|
+
*/
|
|
216
|
+
export async function resolveSettings(dataUrl, options = {}) {
|
|
217
|
+
const settings = { ...DEFAULT_SETTINGS };
|
|
218
|
+
|
|
219
|
+
const preset = options.preset ?? "Default";
|
|
220
|
+
if (preset && typeof preset === "object") {
|
|
221
|
+
for (const [key, value] of Object.entries(preset)) {
|
|
222
|
+
applySetting(settings, key, value);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
Object.assign(settings, await loadPreset(dataUrl, String(preset)));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
for (const [key, value] of Object.entries(options.overrides ?? {})) {
|
|
229
|
+
applySetting(settings, key, value);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
for (const key of Object.keys(DEFAULT_SETTINGS)) {
|
|
233
|
+
if (!(key in options) || key === "analog") continue;
|
|
234
|
+
if (key === "mask" && typeof options.mask === "string") continue;
|
|
235
|
+
if (options[key] === undefined) continue;
|
|
236
|
+
applySetting(settings, key, options[key]);
|
|
237
|
+
}
|
|
238
|
+
if (typeof options.mask === "string") {
|
|
239
|
+
settings.maskBitmap = options.mask;
|
|
240
|
+
}
|
|
241
|
+
if ("analog" in options) {
|
|
242
|
+
settings.analog = normalizeAnalog(options.analog);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return settings;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function applySetting(settings, key, value) {
|
|
249
|
+
let name;
|
|
250
|
+
if (key in DEFAULT_SETTINGS) {
|
|
251
|
+
name = key;
|
|
252
|
+
} else {
|
|
253
|
+
const normalized = String(key).replace(/_/g, "-").toLowerCase();
|
|
254
|
+
name = KEY_MAP[normalized] ?? normalized;
|
|
255
|
+
}
|
|
256
|
+
if (!(name in DEFAULT_SETTINGS)) {
|
|
257
|
+
throw new Error(`cathode: unknown setting '${key}'`);
|
|
258
|
+
}
|
|
259
|
+
if (name === "analog") {
|
|
260
|
+
settings.analog = normalizeAnalog(value);
|
|
261
|
+
} else if (name === "maskBitmap") {
|
|
262
|
+
settings.maskBitmap = String(value);
|
|
263
|
+
} else if (name === "lines") {
|
|
264
|
+
settings.lines = Math.max(60, Math.min(1080, Math.round(Number(value))));
|
|
265
|
+
} else if (PAIR_KEYS.has(name)) {
|
|
266
|
+
if (!Array.isArray(value) || value.length !== 2) {
|
|
267
|
+
throw new Error(`cathode: ${key} expects [x, y]`);
|
|
268
|
+
}
|
|
269
|
+
settings[name] = [Number(value[0]), Number(value[1])];
|
|
270
|
+
} else if (RAW_KEYS.has(name)) {
|
|
271
|
+
settings[name] = Number(value);
|
|
272
|
+
} else {
|
|
273
|
+
settings[name] = Number(value);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Resolve a mask name (or alias) to the PNG filename shipped by the data repo. */
|
|
278
|
+
export function maskFileName(name) {
|
|
279
|
+
const wanted = String(name).trim().toLowerCase().replace(/_/g, " ");
|
|
280
|
+
const aliases = {
|
|
281
|
+
"aperture-grille": "Aperture Grille",
|
|
282
|
+
"shadow-mask": "Shadow Mask",
|
|
283
|
+
"shadow-mask-edp": "Shadow Mask EDP",
|
|
284
|
+
"slot-mask": "Slot Mask",
|
|
285
|
+
sx64: "SX-64",
|
|
286
|
+
};
|
|
287
|
+
const canonical = MASKS.find((mask) => mask.toLowerCase() === wanted);
|
|
288
|
+
if (canonical) return `${canonical}.png`;
|
|
289
|
+
if (aliases[wanted]) return `${aliases[wanted]}.png`;
|
|
290
|
+
throw new Error(
|
|
291
|
+
`cathode: CRT mask '${name}' not found (have: ${MASKS.join(", ")})`,
|
|
292
|
+
);
|
|
293
|
+
}
|
package/src/shaders.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Shader loading and GLSL ES 3.00 adaptation for the CRTEmulation-Data files.
|
|
2
|
+
|
|
3
|
+
const INCLUDE_RE = /^[ \t]*#include[ \t]+"([^"]+)"[ \t]*$/;
|
|
4
|
+
// GLSL ES 3.00 does not allow initializers on uniform declarations. The data
|
|
5
|
+
// repo relies on desktop GLSL defaults, so strip them and set the values from
|
|
6
|
+
// JavaScript instead.
|
|
7
|
+
const UNIFORM_INIT_RE =
|
|
8
|
+
/^([ \t]*)uniform([ \t]+)([A-Za-z_]\w*)([ \t]+)([A-Za-z_]\w*)[ \t]*=[^;]*;/gm;
|
|
9
|
+
|
|
10
|
+
const FRAGMENT_PRELUDE = `#version 300 es
|
|
11
|
+
precision highp float;
|
|
12
|
+
precision highp int;
|
|
13
|
+
uniform vec2 iResolution;
|
|
14
|
+
uniform float iTime;
|
|
15
|
+
uniform sampler2D iChannel0;
|
|
16
|
+
uniform sampler2D iChannel1;
|
|
17
|
+
uniform sampler2D iChannel2;
|
|
18
|
+
uniform sampler2D iChannel3;
|
|
19
|
+
in vec2 fragCoord;
|
|
20
|
+
out vec4 fragColor;
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export const VERTEX = `#version 300 es
|
|
24
|
+
layout(location = 0) in vec2 aPos;
|
|
25
|
+
out vec2 fragCoord;
|
|
26
|
+
void main() {
|
|
27
|
+
fragCoord = aPos * 0.5 + 0.5;
|
|
28
|
+
gl_Position = vec4(aPos, 0.0, 1.0);
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
/** Final pass: the tube quad is rotated by a fraction of a degree. */
|
|
33
|
+
export const VERTEX_ROTATED = `#version 300 es
|
|
34
|
+
layout(location = 0) in vec2 aPos;
|
|
35
|
+
uniform vec2 uScale;
|
|
36
|
+
uniform float uWindowAspect;
|
|
37
|
+
uniform mat2 uRot;
|
|
38
|
+
out vec2 fragCoord;
|
|
39
|
+
void main() {
|
|
40
|
+
vec2 p = aPos * uScale;
|
|
41
|
+
vec2 q = p * vec2(uWindowAspect, 1.0);
|
|
42
|
+
q = uRot * q;
|
|
43
|
+
p = q / vec2(uWindowAspect, 1.0);
|
|
44
|
+
fragCoord = aPos * 0.5 + 0.5;
|
|
45
|
+
gl_Position = vec4(p, 0.0, 1.0);
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Resolve `#include "..."` recursively against `baseUrl`.
|
|
51
|
+
* Returns the expanded GLSL source.
|
|
52
|
+
*/
|
|
53
|
+
export async function loadShader(baseUrl, name, cache = new Map()) {
|
|
54
|
+
if (cache.has(name)) return cache.get(name);
|
|
55
|
+
|
|
56
|
+
const pending = (async () => {
|
|
57
|
+
const url = new URL(name, baseUrl);
|
|
58
|
+
const response = await fetch(url);
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`cathode: cannot load shader ${url} (HTTP ${response.status})`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
let text = await response.text();
|
|
65
|
+
text = text.replace(/^[ \t]*#version[^\n]*\n?/gm, "");
|
|
66
|
+
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const line of text.split("\n")) {
|
|
69
|
+
const match = line.match(INCLUDE_RE);
|
|
70
|
+
if (match) {
|
|
71
|
+
out.push(await loadShader(baseUrl, match[1], cache));
|
|
72
|
+
} else {
|
|
73
|
+
out.push(line);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return out.join("\n");
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
cache.set(name, pending);
|
|
80
|
+
return pending;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Turn a raw data-repo shader body into a WebGL2 fragment shader. */
|
|
84
|
+
export function fragmentShader(body) {
|
|
85
|
+
const adapted = body.replace(UNIFORM_INIT_RE, "$1uniform$2$3$4$5;");
|
|
86
|
+
return FRAGMENT_PRELUDE + adapted;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const SHADER_FILES = {
|
|
90
|
+
simulation: "crt-simulation.glsl",
|
|
91
|
+
curved: "crt-curved.glsl",
|
|
92
|
+
adjacent: "crt-adjacent-excitation.glsl",
|
|
93
|
+
halation: "crt-halation.glsl",
|
|
94
|
+
bloom: "crt-calc-bloom.glsl",
|
|
95
|
+
decoderPal: "decoder-pal.glsl",
|
|
96
|
+
decoderNtsc: "decoder-ntsc.glsl",
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** RGB (sRGB) -> YUV/YIQ with the +0.5 chroma bias the decoders expect. */
|
|
100
|
+
export const ENCODER_SHADER = `#version 300 es
|
|
101
|
+
precision highp float;
|
|
102
|
+
uniform vec2 iResolution;
|
|
103
|
+
uniform float iTime;
|
|
104
|
+
uniform sampler2D iChannel0;
|
|
105
|
+
uniform sampler2D iChannel1;
|
|
106
|
+
uniform sampler2D iChannel2;
|
|
107
|
+
uniform sampler2D iChannel3;
|
|
108
|
+
uniform int uYiq;
|
|
109
|
+
in vec2 fragCoord;
|
|
110
|
+
out vec4 fragColor;
|
|
111
|
+
|
|
112
|
+
void main() {
|
|
113
|
+
vec3 rgb = clamp(texture(iChannel0, fragCoord).rgb, 0.0, 1.0);
|
|
114
|
+
rgb = pow(rgb, vec3(2.2 / 2.8));
|
|
115
|
+
|
|
116
|
+
float y;
|
|
117
|
+
vec2 c;
|
|
118
|
+
if (uYiq == 1) {
|
|
119
|
+
y = dot(rgb, vec3(0.23485876, 0.63350074, 0.13164050));
|
|
120
|
+
c = vec2(dot(rgb, vec3(0.44095948, -0.27984363, -0.16111585)),
|
|
121
|
+
dot(rgb, vec3(0.14630060, -0.55948148, 0.41318088)));
|
|
122
|
+
} else {
|
|
123
|
+
y = dot(rgb, vec3(0.29914638, 0.58687783, 0.11397579));
|
|
124
|
+
c = vec2(dot(rgb, vec3(-0.14720974, -0.28880220, 0.43601193)),
|
|
125
|
+
dot(rgb, vec3(0.61487557, -0.51488190, -0.09999367)));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fragColor = vec4(y, c + 0.5, 1.0);
|
|
129
|
+
}
|
|
130
|
+
`;
|