summaryrefslogtreecommitdiff
path: root/src/gpu/effects/chroma_aberration_effect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/effects/chroma_aberration_effect.cc')
-rw-r--r--src/gpu/effects/chroma_aberration_effect.cc48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/gpu/effects/chroma_aberration_effect.cc b/src/gpu/effects/chroma_aberration_effect.cc
index dc28ee5..3e953e3 100644
--- a/src/gpu/effects/chroma_aberration_effect.cc
+++ b/src/gpu/effects/chroma_aberration_effect.cc
@@ -1,26 +1,46 @@
// This file is part of the 64k demo project.
-// It implements the ChromaAberrationEffect.
+// It implements the ChromaAberrationEffect with parameterization.
#include "gpu/demo_effects.h"
+#include "gpu/effects/post_process_helper.h"
#include "gpu/gpu.h"
// --- ChromaAberrationEffect ---
+
+// Backward compatibility constructor (delegates to parameterized constructor)
ChromaAberrationEffect::ChromaAberrationEffect(const GpuContext& ctx)
- : PostProcessEffect(ctx) {
- uniforms_ =
- gpu_create_buffer(ctx_.device, sizeof(float) * 6,
- WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst);
+ : ChromaAberrationEffect(ctx, ChromaAberrationParams{}) {
+}
+
+// Parameterized constructor
+ChromaAberrationEffect::ChromaAberrationEffect(
+ const GpuContext& ctx, const ChromaAberrationParams& params)
+ : PostProcessEffect(ctx), params_(params) {
pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format,
chroma_aberration_shader_wgsl);
+ uniforms_.init(ctx_.device);
}
-void ChromaAberrationEffect::render(WGPURenderPassEncoder pass, float t,
- float b, float i, float a) {
- struct {
- float t, b, i, a, w, h;
- } u = {t, b, i, a, (float)width_, (float)height_};
- wgpuQueueWriteBuffer(ctx_.queue, uniforms_.buffer, 0, &u, sizeof(u));
- PostProcessEffect::render(pass, t, b, i, a);
+
+void ChromaAberrationEffect::render(WGPURenderPassEncoder pass, float time,
+ float beat, float intensity,
+ float aspect_ratio) {
+ // Update uniforms with current state and parameters
+ const ChromaUniforms u = {.time = time,
+ .beat = beat,
+ .intensity = intensity,
+ .aspect_ratio = aspect_ratio,
+ .width = (float)width_,
+ .height = (float)height_,
+ .offset_scale = params_.offset_scale,
+ .angle = params_.angle};
+ uniforms_.update(ctx_.queue, u);
+
+ wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
}
-void ChromaAberrationEffect::update_bind_group(WGPUTextureView v) {
- pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, v, uniforms_);
+
+void ChromaAberrationEffect::update_bind_group(WGPUTextureView input_view) {
+ pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view,
+ uniforms_.get());
}