diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-08 17:39:33 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-08 17:39:33 +0100 |
| commit | 8296fe5180b979b9d1f32f6375b41f0e0a8a399d (patch) | |
| tree | 28918defcd64001105f8f631a3c0494abd580026 /assets/final | |
| parent | b85635ea92ace57e4d94288031a3a61a96fcbd2a (diff) | |
feat(gpu): Add parameter-driven ChromaAberrationEffect
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<ChromaUniforms>
- 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 <noreply@anthropic.com>
Diffstat (limited to 'assets/final')
| -rw-r--r-- | assets/final/shaders/chroma_aberration.wgsl | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/assets/final/shaders/chroma_aberration.wgsl b/assets/final/shaders/chroma_aberration.wgsl index cd80afa..f1a3034 100644 --- a/assets/final/shaders/chroma_aberration.wgsl +++ b/assets/final/shaders/chroma_aberration.wgsl @@ -6,7 +6,10 @@ struct Uniforms { beat: f32, intensity: f32, aspect_ratio: f32, - resolution: vec2<f32>, + width: f32, + height: f32, + offset_scale: f32, + angle: f32, }; @group(0) @binding(2) var<uniform> uniforms: Uniforms; @@ -21,10 +24,16 @@ struct Uniforms { } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - let uv = p.xy / uniforms.resolution; - let off = 0.02 * uniforms.intensity; - let r = textureSample(txt, smplr, uv + vec2<f32>(off, 0.0)).r; + let uv = p.xy / vec2<f32>(uniforms.width, uniforms.height); + + // Compute offset magnitude and direction + let offset_mag = uniforms.offset_scale * uniforms.intensity; + let offset_dir = vec2<f32>(cos(uniforms.angle), sin(uniforms.angle)); + let offset = offset_mag * offset_dir; + + // Sample RGB channels with chromatic aberration + let r = textureSample(txt, smplr, uv + offset).r; let g = textureSample(txt, smplr, uv).g; - let b = textureSample(txt, smplr, uv - vec2<f32>(off, 0.0)).b; + let b = textureSample(txt, smplr, uv - offset).b; return vec4<f32>(r, g, b, 1.0); } |
