diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-11 11:34:08 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-11 11:34:08 +0100 |
| commit | d378da77eec4d506bc01e4c08c38644d72969cc7 (patch) | |
| tree | 5cc38517320ba3aefb46a2f9c939c9fdc8ed5fae /src/gpu/effects/rotating_cube_effect.cc | |
| parent | 4da0a3a5369142078fd7c681e3f0f1817bd6e2f3 (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/rotating_cube_effect.cc')
| -rw-r--r-- | src/gpu/effects/rotating_cube_effect.cc | 9 |
1 files changed, 4 insertions, 5 deletions
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), }; |
