summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-03-09 08:50:52 +0100
committerskal <pascal.massimino@gmail.com>2026-03-09 08:50:52 +0100
commit7e7615075b666bfaec5f07f727da85c724b64399 (patch)
treee5c64a729ad8b8b9f15647153b191f43005c682d /src
parentfef418c8e839ae689aacb14264b0e9e3c3d1071d (diff)
refactor: mv get_border_col() to color_c64.wgsl as get_border_c64()
Diffstat (limited to 'src')
-rw-r--r--src/effects/ntsc.wgsl10
-rw-r--r--src/shaders/math/color_c64.wgsl15
2 files changed, 13 insertions, 12 deletions
diff --git a/src/effects/ntsc.wgsl b/src/effects/ntsc.wgsl
index 9901c88..a701a25 100644
--- a/src/effects/ntsc.wgsl
+++ b/src/effects/ntsc.wgsl
@@ -78,14 +78,6 @@ fn randomized_f32(p: vec2f, t: f32) -> f32 {
}
-fn get_border_col(uv: vec2f) -> vec4f {
- let t = uniforms.beat_time;
- let offset = uv.x + YSIZE * uv.y / 8.;
- let phase = 3. * round(hash_1f(t * 533.) * 24.);
- let id = round(hash_1f(round(sin(t * 1.6) + offset + phase)) * 8.);
- let border_col = vec4f(C64Colors[u32(id)], 1.);
- return border_col;
-}
@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f {
let t = uniforms.time;
@@ -141,7 +133,7 @@ fn get_border_col(uv: vec2f) -> vec4f {
var col = yiqa_to_rgba(signal);
col = Dither(col, uv, XSIZE, YSIZE);
- let border_col = get_border_col(uv);
+ let border_col = get_border_c64(uv, uniforms.beat_time, YSIZE);
let v_strength = vignette(uv);
let scanl = 0.82 + 0.5 * sin(PI * uv.y * uniforms.resolution.y / 2.);
diff --git a/src/shaders/math/color_c64.wgsl b/src/shaders/math/color_c64.wgsl
index ef8f073..e1b142e 100644
--- a/src/shaders/math/color_c64.wgsl
+++ b/src/shaders/math/color_c64.wgsl
@@ -1,6 +1,6 @@
-// C64 palette and ordered-dither quantization.
-// Provides Dither() to snap any RGBA color to the nearest C64 color pair
-// via 8x8 Bayer threshold, suitable for NTSC and retro post-process effects.
+// C64 palette, ordered-dither quantization, and border color animation.
+// Provides Dither() and get_border_c64() for NTSC and retro post-process effects.
+#include "math/noise"
const NUM_COLORS : u32 = 16;
const C64Colors = array<vec3f, NUM_COLORS>(
@@ -81,3 +81,12 @@ fn Dither(col: vec4f, uv: vec2f, xsize: f32, ysize: f32) -> vec4f {
color = mix(c1, c2, f32(frac > thresh));
return sqrt(color);
}
+
+// Animated C64 border color: cycles through palette driven by beat_time.
+// ysize: virtual scanline count (e.g. 33.*8.), matching the pixel grid.
+fn get_border_c64(uv: vec2f, beat_time: f32, ysize: f32) -> vec4f {
+ let offset = uv.x + ysize * uv.y / 8.;
+ let phase = 3. * round(hash_1f(beat_time * 533.) * 24.);
+ let id = round(hash_1f(round(sin(beat_time * 1.6) + offset + phase)) * 8.);
+ return vec4f(C64Colors[u32(id)], 1.);
+}