From 7ca40818e3d0401f97efae6fe876038df4f5bd00 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 10 Mar 2026 09:33:41 +0100 Subject: rotating_cube: use VSOut, and store to yiq --- src/effects/ntsc.wgsl | 2 +- src/effects/rotating_cube.wgsl | 11 ++++++++--- src/shaders/math/color_c64.wgsl | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/effects/ntsc.wgsl b/src/effects/ntsc.wgsl index e0182f3..3ee02bc 100644 --- a/src/effects/ntsc.wgsl +++ b/src/effects/ntsc.wgsl @@ -140,7 +140,7 @@ fn randomized_f32(p: vec2f, t: f32) -> f32 { var col = yiqa_to_rgba(signal); // Slight NTSC warm tint (boost red/green, attenuate blue) col *= vec4f(1.04, 1.01, .94, 1.); -// col = Dither(col, uv, XSIZE, YSIZE); +// col = dither_c64(col, uv, XSIZE, YSIZE); let border_col = get_border_c64(uv, uniforms.beat_time, YSIZE); diff --git a/src/effects/rotating_cube.wgsl b/src/effects/rotating_cube.wgsl index 0c75a13..abd584c 100644 --- a/src/effects/rotating_cube.wgsl +++ b/src/effects/rotating_cube.wgsl @@ -1,4 +1,8 @@ // Rotating cube shader v2 (simplified, no masking) +// output to YIQ color space + +#include "math/color" +#include "math/color_c64" struct Uniforms { view_proj: mat4x4f, @@ -76,8 +80,9 @@ fn get_cube_normal(vid: u32) -> vec3f { return VSOut(clip_pos, world_pos.xyz, world_normal); } -@fragment fn fs_main(@location(0) world_pos: vec3f, @location(1) normal: vec3f) -> @location(0) vec4f { - let N = normalize(normal); +@fragment fn fs_main(in: VSOut) -> @location(0) vec4f { + let screen_uv = in.pos.xy / uniforms.resolution; + let N = in.normal; // not re-normalized: cube faces are flat, no drift let light_dir = normalize(vec3f(1.0, 1.0, 1.0)); let diffuse = max(dot(N, light_dir), 0.0); @@ -85,5 +90,5 @@ fn get_cube_normal(vid: u32) -> vec3f { let lighting = ambient + diffuse * 0.7; let color = object.color.rgb * lighting; - return vec4f(color, 1.0); + return rgba_to_luma_chroma_phase(vec4f(color, 1.0), screen_uv.y, 264.); } diff --git a/src/shaders/math/color_c64.wgsl b/src/shaders/math/color_c64.wgsl index e1b142e..60fde28 100644 --- a/src/shaders/math/color_c64.wgsl +++ b/src/shaders/math/color_c64.wgsl @@ -1,5 +1,5 @@ // C64 palette, ordered-dither quantization, and border color animation. -// Provides Dither() and get_border_c64() for NTSC and retro post-process effects. +// Provides dither_c64() and get_border_c64() for NTSC and retro post-process effects. #include "math/noise" const NUM_COLORS : u32 = 16; @@ -45,7 +45,7 @@ fn colorDistance(color: vec4f, c1: vec4f, c2: vec4f, frac: f32) -> f32 { // Quantize col to the nearest C64 color pair using 8x8 Bayer dithering. // xsize/ysize: virtual pixel grid dimensions (e.g. 54.*8., 33.*8.). -fn Dither(col: vec4f, uv: vec2f, xsize: f32, ysize: f32) -> vec4f { +fn dither_c64(col: vec4f, uv: vec2f, xsize: f32, ysize: f32) -> vec4f { let ix = u32(floor(uv.x * xsize / 2.)) % 8; let iy = u32(floor(uv.y * ysize / 2.)) % 8; let thresh = f32(BAYER_8X8[ix + 8 * iy]) / 64.; -- cgit v1.2.3