From 8296fe5180b979b9d1f32f6375b41f0e0a8a399d Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 8 Feb 2026 17:39:33 +0100 Subject: feat(gpu): Add parameter-driven ChromaAberrationEffect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements Task #73 - Extends shader parametrization system to ChromaAberrationEffect following the FlashEffect pattern. Changes: - Added ChromaAberrationParams struct (offset_scale, angle) - Added ChromaUniforms with proper WGSL alignment (32 bytes) - Updated shader to compute offset direction from angle parameter - Extended seq_compiler to parse offset/angle parameters - Updated demo.seq with 2 parameterized instances: * Line 50: offset=0.03 angle=0.785 (45° diagonal, stronger) * Line 76: offset=0.01 angle=1.57 (90° vertical, subtle) Technical details: - Backward-compatible default constructor maintained - Migrated from raw buffer to UniformBuffer - Shader computes direction: vec2(cos(angle), sin(angle)) - Generated code creates ChromaAberrationParams initialization Testing: - All 32/32 tests pass - Demo runs without errors - Binary size: 5.6M stripped (~200-300 bytes impact) Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/demo_effects.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/gpu/demo_effects.h') diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h index d9487fa..36be118 100644 --- a/src/gpu/demo_effects.h +++ b/src/gpu/demo_effects.h @@ -6,11 +6,12 @@ #include "3d/renderer.h" #include "3d/scene.h" #include "effect.h" -#include "gpu/effects/flash_effect.h" // FlashEffect with params support +#include "gpu/effects/flash_effect.h" // FlashEffect with params support #include "gpu/effects/post_process_helper.h" #include "gpu/effects/shaders.h" #include "gpu/gpu.h" #include "gpu/texture_manager.h" +#include "gpu/uniform_helper.h" #include static const int NUM_PARTICLES = 10000; @@ -100,12 +101,40 @@ class DistortEffect : public PostProcessEffect { void update_bind_group(WGPUTextureView input_view) override; }; +// Parameters for ChromaAberrationEffect (set at construction time) +struct ChromaAberrationParams { + float offset_scale = 0.02f; // Default: 2% screen offset + float angle = 0.0f; // Default: horizontal (0 radians) +}; + +// Uniform data sent to GPU shader +struct ChromaUniforms { + float time; // offset 0 + float beat; // offset 4 + float intensity; // offset 8 + float aspect_ratio; // offset 12 + float width; // offset 16 + float height; // offset 20 + float offset_scale; // offset 24 + float angle; // offset 28 +}; +static_assert(sizeof(ChromaUniforms) == 32, + "ChromaUniforms must be 32 bytes for WGSL alignment"); + class ChromaAberrationEffect : public PostProcessEffect { public: + // Backward compatibility constructor (uses default params) ChromaAberrationEffect(const GpuContext& ctx); + // New parameterized constructor + ChromaAberrationEffect(const GpuContext& ctx, + const ChromaAberrationParams& params); void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; + + private: + ChromaAberrationParams params_; + UniformBuffer uniforms_; }; class Hybrid3DEffect : public Effect { -- cgit v1.2.3