summaryrefslogtreecommitdiff
path: root/src/gpu/effects/flash_cube_effect.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-11 11:34:08 +0100
committerskal <pascal.massimino@gmail.com>2026-02-11 11:34:08 +0100
commitd378da77eec4d506bc01e4c08c38644d72969cc7 (patch)
tree5cc38517320ba3aefb46a2f9c939c9fdc8ed5fae /src/gpu/effects/flash_cube_effect.cc
parent4da0a3a5369142078fd7c681e3f0f1817bd6e2f3 (diff)
refactor: Simplify effect render API and fix uniform initialization
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
Diffstat (limited to 'src/gpu/effects/flash_cube_effect.cc')
-rw-r--r--src/gpu/effects/flash_cube_effect.cc14
1 files changed, 7 insertions, 7 deletions
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);
}