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/rotating_cube_effect.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/gpu/effects/rotating_cube_effect.cc') diff --git a/src/gpu/effects/rotating_cube_effect.cc b/src/gpu/effects/rotating_cube_effect.cc index da973e5..79a540b 100644 --- a/src/gpu/effects/rotating_cube_effect.cc +++ b/src/gpu/effects/rotating_cube_effect.cc @@ -182,9 +182,8 @@ void RotatingCubeEffect::init(MainSequence* demo) { wgpuBindGroupLayoutRelease(bgl_1); } -void RotatingCubeEffect::render(WGPURenderPassEncoder pass, float time, - float beat, float intensity, - float aspect_ratio) { +void RotatingCubeEffect::render(WGPURenderPassEncoder pass, + const CommonPostProcessUniforms& u) { rotation_ += 0.016f * 1.5f; const vec3 camera_pos = vec3(0, 0, 5); @@ -193,7 +192,7 @@ void RotatingCubeEffect::render(WGPURenderPassEncoder pass, float time, const mat4 view = mat4::look_at(camera_pos, target, up); const float fov = 60.0f * 3.14159f / 180.0f; - const mat4 proj = mat4::perspective(fov, aspect_ratio, 0.1f, 100.0f); + const mat4 proj = mat4::perspective(fov, u.aspect_ratio, 0.1f, 100.0f); const mat4 view_proj = proj * view; const quat rot = quat::from_axis(vec3(0.3f, 1.0f, 0.2f), rotation_); @@ -206,7 +205,7 @@ void RotatingCubeEffect::render(WGPURenderPassEncoder pass, float time, const Uniforms uniforms = { .view_proj = view_proj, .inv_view_proj = view_proj.inverse(), - .camera_pos_time = vec4(camera_pos.x, camera_pos.y, camera_pos.z, time), + .camera_pos_time = vec4(camera_pos.x, camera_pos.y, camera_pos.z, u.time), .params = vec4(1.0f, 0.0f, 0.0f, 0.0f), .resolution = vec2(1280.0f, 720.0f), }; -- cgit v1.2.3