From d378da77eec4d506bc01e4c08c38644d72969cc7 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 11 Feb 2026 11:34:08 +0100 Subject: refactor: Simplify effect render API and fix uniform initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: Uniform buffers created but not initialized before bind group creation, causing undefined UV coordinates in circle_mask_compute.wgsl. Changes: - Add get_common_uniforms() helper to Effect base class - Refactor render()/compute() signatures: 5 params → CommonPostProcessUniforms& - Fix uninitialized uniforms in CircleMaskEffect and CNNEffect - Update all 19 effect implementations and headers - Fix WGSL syntax error in FlashEffect (u.audio_intensity → audio_intensity) - Update test files (test_sequence.cc) Benefits: - Cleaner API: construct uniforms once per frame, reuse across effects - More maintainable: CommonPostProcessUniforms changes need no call site updates - Fixes UV coordinate bug in circle_mask_compute.wgsl All 36 tests passing (100%) handoff(Claude): Effect API refactor complete --- src/gpu/effects/flash_cube_effect.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/gpu/effects/flash_cube_effect.cc') diff --git a/src/gpu/effects/flash_cube_effect.cc b/src/gpu/effects/flash_cube_effect.cc index f01bbd1..ee25408 100644 --- a/src/gpu/effects/flash_cube_effect.cc +++ b/src/gpu/effects/flash_cube_effect.cc @@ -48,11 +48,11 @@ void FlashCubeEffect::init(MainSequence* demo) { scene_.add_object(cube); } -void FlashCubeEffect::render(WGPURenderPassEncoder pass, float time, float beat, - float intensity, float aspect_ratio) { +void FlashCubeEffect::render(WGPURenderPassEncoder pass, + const CommonPostProcessUniforms& uniforms) { // Detect beat changes for flash trigger (using intensity as proxy for beat // hits) Intensity spikes on beats, so we can use it to trigger flashes - if (intensity > 0.5f && + if (uniforms.audio_intensity > 0.5f && flash_intensity_ < 0.3f) { // High intensity + flash cooled down flash_intensity_ = 1.0f; // Trigger full flash } @@ -73,12 +73,12 @@ void FlashCubeEffect::render(WGPURenderPassEncoder pass, float time, float beat, // Slowly rotate the cube for visual interest scene_.objects[0].rotation = - quat::from_axis(vec3(0.3f, 1, 0.2f), time * 0.05f); + quat::from_axis(vec3(0.3f, 1, 0.2f), uniforms.time * 0.05f); // Position camera OUTSIDE the cube looking at it from a distance // This way we see the cube as a background element float cam_distance = 150.0f; // Much farther to ensure it's behind everything - float orbit_angle = time * 0.1f; + float orbit_angle = uniforms.time * 0.1f; camera_.set_look_at( vec3(std::sin(orbit_angle) * cam_distance, @@ -87,11 +87,11 @@ void FlashCubeEffect::render(WGPURenderPassEncoder pass, float time, float beat, vec3(0, 0, 0), // Look at cube center vec3(0, 1, 0)); - camera_.aspect_ratio = aspect_ratio; + camera_.aspect_ratio = uniforms.aspect_ratio; // Extend far plane to accommodate distant camera position (150 units + cube // size) camera_.far_plane = 300.0f; // Draw the cube - renderer_.draw(pass, scene_, camera_, time); + renderer_.draw(pass, scene_, camera_, uniforms.time); } -- cgit v1.2.3