summaryrefslogtreecommitdiff
path: root/src/gpu/effects/flash_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_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_effect.cc')
-rw-r--r--src/gpu/effects/flash_effect.cc20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/gpu/effects/flash_effect.cc b/src/gpu/effects/flash_effect.cc
index 57c1d73..4357c34 100644
--- a/src/gpu/effects/flash_effect.cc
+++ b/src/gpu/effects/flash_effect.cc
@@ -1,5 +1,5 @@
// This file is part of the 64k demo project.
-// It implements the FlashEffect - brief flash on beat hits.
+// It implements the FlashEffect - brief flash on u.beat hits.
// Now supports parameterized color with per-frame animation.
#include "gpu/effects/flash_effect.h"
@@ -22,7 +22,7 @@ FlashEffect::FlashEffect(const GpuContext& ctx, const FlashEffectParams& params)
struct Uniforms {
flash_intensity: f32,
- intensity: f32,
+ audio_intensity: f32,
flash_color: vec3<f32>, // Parameterized color
_pad: f32,
};
@@ -63,12 +63,10 @@ void FlashEffect::update_bind_group(WGPUTextureView input_view) {
flash_uniforms_.get(), {});
}
-void FlashEffect::render(WGPURenderPassEncoder pass, float time, float beat,
- float intensity, float aspect_ratio) {
- (void)aspect_ratio;
-
+void FlashEffect::render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) {
// Trigger flash based on configured threshold
- if (intensity > params_.trigger_threshold && flash_intensity_ < 0.2f) {
+ if (uniforms.audio_intensity > params_.trigger_threshold && flash_intensity_ < 0.2f) {
flash_intensity_ = 0.8f; // Trigger flash
}
@@ -77,14 +75,14 @@ void FlashEffect::render(WGPURenderPassEncoder pass, float time, float beat,
// *** PER-FRAME PARAMETER COMPUTATION ***
// Animate color based on time and beat
- const float r = params_.color[0] * (0.5f + 0.5f * sinf(time * 0.5f));
- const float g = params_.color[1] * (0.5f + 0.5f * cosf(time * 0.7f));
- const float b = params_.color[2] * (1.0f + 0.3f * beat);
+ const float r = params_.color[0] * (0.5f + 0.5f * sinf(uniforms.time * 0.5f));
+ const float g = params_.color[1] * (0.5f + 0.5f * cosf(uniforms.time * 0.7f));
+ const float b = params_.color[2] * (1.0f + 0.3f * uniforms.beat);
// Update uniforms with computed (animated) values
const FlashUniforms u = {
.flash_intensity = flash_intensity_,
- .intensity = intensity,
+ .intensity = uniforms.audio_intensity,
._pad1 = {0.0f, 0.0f}, // Padding for vec3 alignment
.color = {r, g, b}, // Time-dependent, computed every frame
._pad2 = 0.0f};