summaryrefslogtreecommitdiff
path: root/src/effects/chroma_aberration_effect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects/chroma_aberration_effect.cc')
-rw-r--r--src/effects/chroma_aberration_effect.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/effects/chroma_aberration_effect.cc b/src/effects/chroma_aberration_effect.cc
new file mode 100644
index 0000000..a096f5b
--- /dev/null
+++ b/src/effects/chroma_aberration_effect.cc
@@ -0,0 +1,38 @@
+// This file is part of the 64k demo project.
+// It implements the ChromaAberrationEffect with parameterization.
+
+#include "gpu/demo_effects.h"
+#include "gpu/post_process_helper.h"
+#include "gpu/gpu.h"
+
+// --- ChromaAberrationEffect ---
+
+// Backward compatibility constructor (delegates to parameterized constructor)
+ChromaAberrationEffect::ChromaAberrationEffect(const GpuContext& ctx)
+ : 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);
+ params_buffer_.init(ctx_.device);
+}
+
+void ChromaAberrationEffect::render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) {
+ // Update uniforms with current state and parameters
+ uniforms_.update(ctx_.queue, uniforms);
+ params_buffer_.update(ctx_.queue, params_);
+
+ wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
+}
+
+void ChromaAberrationEffect::update_bind_group(WGPUTextureView input_view) {
+ pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view,
+ uniforms_.get(), params_buffer_.get());
+}