summaryrefslogtreecommitdiff
path: root/src/gpu/effects/hybrid_3d_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/hybrid_3d_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/hybrid_3d_effect.cc')
-rw-r--r--src/gpu/effects/hybrid_3d_effect.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/gpu/effects/hybrid_3d_effect.cc b/src/gpu/effects/hybrid_3d_effect.cc
index 17fef25..d580471 100644
--- a/src/gpu/effects/hybrid_3d_effect.cc
+++ b/src/gpu/effects/hybrid_3d_effect.cc
@@ -87,19 +87,19 @@ static float ease_in_out_cubic(float t) {
return 0.5f * (t * t * t + 2.0f);
}
-void Hybrid3DEffect::render(WGPURenderPassEncoder pass, float time, float beat,
- float intensity, float aspect_ratio) {
+void Hybrid3DEffect::render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) {
// Animate Objects
for (size_t i = 1; i < scene_.objects.size(); ++i) {
scene_.objects[i].rotation =
- quat::from_axis(vec3(0, 1, 0), time * 2.0f + i);
+ quat::from_axis(vec3(0, 1, 0), uniforms.time * 2.0f + i);
- scene_.objects[i].position.y = std::sin(time * 3.0f + i) * 1.5f;
+ scene_.objects[i].position.y = std::sin(uniforms.time * 3.0f + i) * 1.5f;
}
// Camera jumps every other pattern (2 seconds) for dramatic effect
- int pattern_num = (int)(time / 2.0f);
+ int pattern_num = (int)(uniforms.time / 2.0f);
int camera_preset = pattern_num % 4; // Cycle through 4 different angles
vec3 cam_pos, cam_target;
@@ -107,34 +107,34 @@ void Hybrid3DEffect::render(WGPURenderPassEncoder pass, float time, float beat,
switch (camera_preset) {
case 0: // High angle, orbiting
{
- float angle = time * 0.5f;
+ float angle = uniforms.time * 0.5f;
cam_pos = vec3(std::sin(angle) * 12.0f, 8.0f, std::cos(angle) * 12.0f);
cam_target = vec3(0, 0, 0);
} break;
case 1: // Low angle, close-up
{
- float angle = time * 0.3f + 1.57f; // Offset angle
+ float angle = uniforms.time * 0.3f + 1.57f; // Offset angle
cam_pos = vec3(std::sin(angle) * 6.0f, 2.0f, std::cos(angle) * 6.0f);
cam_target = vec3(0, 1, 0);
} break;
case 2: // Side view, sweeping
{
- float sweep = std::sin(time * 0.4f) * 10.0f;
+ float sweep = std::sin(uniforms.time * 0.4f) * 10.0f;
cam_pos = vec3(sweep, 5.0f, 8.0f);
cam_target = vec3(0, 0, 0);
} break;
case 3: // Top-down, rotating
{
- float angle = time * 0.6f;
+ float angle = uniforms.time * 0.6f;
cam_pos = vec3(std::sin(angle) * 5.0f, 12.0f, std::cos(angle) * 5.0f);
cam_target = vec3(0, 0, 0);
} break;
}
camera_.set_look_at(cam_pos, cam_target, vec3(0, 1, 0));
- camera_.aspect_ratio = aspect_ratio;
+ camera_.aspect_ratio = uniforms.aspect_ratio;
// Draw
- renderer_.draw(pass, scene_, camera_, time);
+ renderer_.draw(pass, scene_, camera_, uniforms.time);
}