From e4851ae9f310b44dab25eb979733281002c8953d Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 7 Mar 2026 19:02:07 +0100 Subject: refactor(effects): introduce WgslEffect for shader-only post-process effects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace boilerplate .h/.cc pairs for simple single-pass effects with a generic WgslEffect base class that takes a shader string + optional WgslEffectParams (binding 3). Port Flash, Passthrough, Heptagon, Scratch, and GaussianBlur to thin header-only wrappers — no .cc files, no CMake entries needed. Removes 5 .cc files (-243 lines). Update EFFECT_WORKFLOW.md, CONTRIBUTING.md, and AI_RULES.md to document the WgslEffect (Path A) vs full class (Path B) workflow. Doc cleanup: fix stale GaussianBlurParams/PostProcessEffect references and test counts. handoff(Claude): WgslEffect landed; 5 effects ported; docs updated. Co-Authored-By: Claude Sonnet 4.6 --- doc/CONTRIBUTING.md | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'doc/CONTRIBUTING.md') diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index 7fbfd64..c077342 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -66,22 +66,30 @@ See `doc/CODING_STYLE.md` for detailed examples. ### Adding Visual Effect -**For SDF/raymarching effects:** Use `SDFEffect` base class (see `doc/SDF_EFFECT_GUIDE.md`). - -**For standard effects:** -1. Create effect class files (each effect should have its own `.h` and `.cc` file, e.g., `src/effects/my_effect.h` and `src/effects/my_effect.cc`). Use `tools/shadertoy/convert_shadertoy.py` or templates. -2. Add shader to `workspaces/main/assets.txt` -3. Add effect `.cc` file to `CMakeLists.txt` GPU_SOURCES (both sections) -4. Include header in `src/gpu/demo_effects.h` (which now serves as a central include for all individual effect headers) -5. Add to workspace `timeline.seq` (e.g., `workspaces/main/timeline.seq`) -6. **Update `src/tests/gpu/test_demo_effects.cc`**: - - Add to `post_process_effects` list (lines 80-93) or `scene_effects` list (lines 125-137) - - Example: `{"MyEffect", std::make_shared(fixture.ctx())},` -7. Verify: +**Full workflow:** See `doc/EFFECT_WORKFLOW.md`. + +**Simple post-process (shader only) — WgslEffect path:** +1. Write `src/effects/.wgsl` +2. Add to `workspaces/main/assets.txt` +3. Create `src/effects/_effect.h` as a thin wrapper (no `.cc`, no CMake entry): + ```cpp + struct MyEffect : public WgslEffect { + MyEffect(const GpuContext& ctx, const std::vector& inputs, + const std::vector& outputs, float s, float e) + : WgslEffect(ctx, inputs, outputs, s, e, my_shader_wgsl) {} + }; + ``` +4. Add `extern const char* my_shader_wgsl;` to `shaders.h`, definition to `shaders.cc` +5. Include in `src/gpu/demo_effects.h`, add test entry in `test_demo_effects.cc` +6. Add to `workspaces/main/timeline.seq` + +**Complex effects (custom uniforms / 3D / compute):** follow all 7 steps in `doc/EFFECT_WORKFLOW.md`. + +**For SDF/raymarching effects:** See `doc/SDF_EFFECT_GUIDE.md`. + +Verify: ```bash -cmake -S . -B build -DDEMO_BUILD_TESTS=ON -cmake --build build -j4 --target test_demo_effects -cd build && ./test_demo_effects +cmake --build build -j4 && cd build && ./test_demo_effects ``` ### Audio Initialization -- cgit v1.2.3