diff options
Diffstat (limited to 'src/gpu/effect.cc')
| -rw-r--r-- | src/gpu/effect.cc | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index fba3353..528d7fc 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -12,8 +12,9 @@ #include <vector> // --- PostProcessEffect --- -void PostProcessEffect::render(WGPURenderPassEncoder pass, float, float, float, - float) { +void PostProcessEffect::render(WGPURenderPassEncoder pass, + const CommonPostProcessUniforms& uniforms) { + (void)uniforms; // Base implementation doesn't use uniforms if (pipeline_ && bind_group_) { wgpuRenderPassEncoderSetPipeline(pass, pipeline_); wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr); @@ -256,9 +257,19 @@ void MainSequence::render_frame(float global_time, float beat, float peak, }); // 1. Compute + // Construct common uniforms once (reused for all effects) + CommonPostProcessUniforms base_uniforms = { + .resolution = {static_cast<float>(width_), static_cast<float>(height_)}, + ._pad = {0.0f, 0.0f}, + .aspect_ratio = aspect_ratio, + .time = 0.0f, // Will be set per-effect + .beat = beat, + .audio_intensity = peak, + }; + for (const SequenceItem* item : scene_effects) { - item->effect->compute(encoder, global_time - item->start_time, beat, peak, - aspect_ratio); + base_uniforms.time = global_time - item->start_time; + item->effect->compute(encoder, base_uniforms); } // 2. Scene Pass (to A) @@ -287,8 +298,8 @@ void MainSequence::render_frame(float global_time, float beat, float peak, wgpuRenderPassEncoderSetViewport(scene_pass, 0.0f, 0.0f, (float)width_, (float)height_, 0.0f, 1.0f); for (const SequenceItem* item : scene_effects) { - item->effect->render(scene_pass, global_time - item->start_time, beat, peak, - aspect_ratio); + base_uniforms.time = global_time - item->start_time; + item->effect->render(scene_pass, base_uniforms); } wgpuRenderPassEncoderEnd(scene_pass); @@ -326,7 +337,8 @@ void MainSequence::render_frame(float global_time, float beat, float peak, PostProcessEffect* passthrough = (PostProcessEffect*)passthrough_effect_.get(); passthrough->update_bind_group(framebuffer_view_a_); - passthrough->render(capture_pass, 0, 0, 0, aspect_ratio); + base_uniforms.time = 0.0f; + passthrough->render(capture_pass, base_uniforms); wgpuRenderPassEncoderEnd(capture_pass); } @@ -358,7 +370,8 @@ void MainSequence::render_frame(float global_time, float beat, float peak, wgpuCommandEncoderBeginRenderPass(encoder, &final_desc); wgpuRenderPassEncoderSetViewport(final_pass, 0.0f, 0.0f, (float)width_, (float)height_, 0.0f, 1.0f); - passthrough_effect_->render(final_pass, 0, 0, 0, aspect_ratio); + base_uniforms.time = 0.0f; + passthrough_effect_->render(final_pass, base_uniforms); wgpuRenderPassEncoderEnd(final_pass); } else { WGPUTextureView current_input = framebuffer_view_a_; @@ -395,8 +408,8 @@ void MainSequence::render_frame(float global_time, float beat, float peak, wgpuCommandEncoderBeginRenderPass(encoder, &pp_desc); wgpuRenderPassEncoderSetViewport(pp_pass, 0.0f, 0.0f, (float)width_, (float)height_, 0.0f, 1.0f); - pp->render(pp_pass, global_time - post_effects[i]->start_time, beat, peak, - aspect_ratio); + base_uniforms.time = global_time - post_effects[i]->start_time; + pp->render(pp_pass, base_uniforms); wgpuRenderPassEncoderEnd(pp_pass); current_input = current_output; } @@ -511,8 +524,15 @@ void MainSequence::simulate_until(float target_time, float step_rate, } } for (const SequenceItem* item : scene_effects) { - item->effect->compute(encoder, t - item->start_time, beat, 0.0f, - aspect_ratio); + CommonPostProcessUniforms test_uniforms = { + .resolution = {static_cast<float>(width_), static_cast<float>(height_)}, + ._pad = {0.0f, 0.0f}, + .aspect_ratio = aspect_ratio, + .time = t - item->start_time, + .beat = beat, + .audio_intensity = 0.0f, + }; + item->effect->compute(encoder, test_uniforms); } WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr); wgpuQueueSubmit(gpu_ctx.queue, 1, &commands); |
