From 850388bcaabf057beed8f126002b7b663183b2d8 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 20 Feb 2026 12:08:34 +0100 Subject: feat(sequence): port Scene1Effect + fix seq_compiler absolute time bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Scene1 effect: raymarching cube+sphere+ground (reflections, shadows) - Fix scene1.wgsl: binding 0→2, CommonUniforms→UniformsSequenceParams - Replace Heptagon+Placeholder stub in heptagon_scene with Scene1 - Fix seq_compiler.py: emit seq.start_time+effect.start/end (absolute times) so dispatch_render active check works correctly for all sequences Bug: effects in sequences starting after t=0 were never active because local times (e.g. 0-8) never satisfied params.time --- PROJECT_CONTEXT.md | 4 ++-- cmake/DemoSourceLists.cmake | 1 + doc/COMPLETED.md | 13 +++++++++++ src/effects/scene1_effect.cc | 45 +++++++++++++++++++++++++++++++++++++ src/effects/scene1_effect.h | 21 +++++++++++++++++ src/effects/shaders.cc | 1 + src/effects/shaders.h | 1 + src/gpu/demo_effects.h | 1 + src/tests/gpu/test_demo_effects.cc | 3 +++ tools/seq_compiler.py | 2 +- workspaces/main/shaders/scene1.wgsl | 4 ++-- workspaces/main/timeline.seq | 4 +--- 12 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 src/effects/scene1_effect.cc create mode 100644 src/effects/scene1_effect.h diff --git a/PROJECT_CONTEXT.md b/PROJECT_CONTEXT.md index dee9c77..758b83e 100644 --- a/PROJECT_CONTEXT.md +++ b/PROJECT_CONTEXT.md @@ -39,8 +39,8 @@ - **Effects:** CNN post-processing: CNNEffect (v1) and CNNv2Effect operational. CNN v2: sigmoid activation, storage buffer weights (~3.2 KB), 7D static features, dynamic layers. Training stable, convergence validated. - **Tools:** CNN test tool operational. Texture readback utility functional. Timeline editor (web-based, beat-aligned, audio playback). - **Build:** Asset dependency tracking. Size measurement. Hot-reload (debug-only). -- **Sequence:** DAG-based effect routing with explicit node system. Python compiler with topological sort and ping-pong optimization. 9 effects operational (Passthrough, Placeholder, GaussianBlur, Heptagon, Particles, RotatingCube, Hybrid3D, Flash, PeakMeter). See `doc/SEQUENCE.md`. -- **Testing:** **35/35 passing** +- **Sequence:** DAG-based effect routing with explicit node system. Python compiler with topological sort and ping-pong optimization. 10 effects operational (Passthrough, Placeholder, GaussianBlur, Heptagon, Particles, RotatingCube, Hybrid3D, Flash, PeakMeter, Scene1). Effect times are absolute (seq_compiler adds sequence start offset). See `doc/SEQUENCE.md`. +- **Testing:** **34/34 passing** --- diff --git a/cmake/DemoSourceLists.cmake b/cmake/DemoSourceLists.cmake index b7bc843..bc943b6 100644 --- a/cmake/DemoSourceLists.cmake +++ b/cmake/DemoSourceLists.cmake @@ -39,6 +39,7 @@ set(COMMON_GPU_EFFECTS src/effects/hybrid3_d_effect.cc src/effects/flash_effect.cc src/effects/peak_meter_effect.cc + src/effects/scene1_effect.cc # TODO: Port CNN effects to v2 (complex v1 dependencies) # cnn_v1/src/cnn_v1_effect.cc # cnn_v2/src/cnn_v2_effect.cc diff --git a/doc/COMPLETED.md b/doc/COMPLETED.md index 1fb51f5..72e389d 100644 --- a/doc/COMPLETED.md +++ b/doc/COMPLETED.md @@ -29,6 +29,19 @@ Detailed historical documents have been moved to `doc/archive/` for reference: Use `read @doc/archive/FILENAME.md` to access archived documents. +## Recently Completed (February 20, 2026) + +- [x] **Port Scene1Effect + Fix seq_compiler Timing Bug** + - **Goal**: Port `scene1.wgsl` (raymarching cube + sphere + ground, reflections, shadows) as `Scene1` effect replacing `Placeholder` stub in `heptagon_scene` sequence. + - **Implementation**: + - `src/effects/scene1_effect.h/.cc`: New effect mirroring Heptagon pattern (dummy texture, `create_post_process_pipeline`). + - `workspaces/main/shaders/scene1.wgsl`: Fixed binding (`@binding(0)` → `@binding(2)`) and struct (`CommonUniforms` → `UniformsSequenceParams`) to match post-process pipeline layout. + - Added to `COMMON_GPU_EFFECTS`, `demo_effects.h`, and `test_demo_effects.cc`. 10/10 effects tested. + - `workspaces/main/timeline.seq`: Replaced Heptagon+Placeholder chain with single `Scene1 source -> sink 0.00 8.00`. + - **Bug Fixed**: `seq_compiler.py` emitted local effect times (e.g. `0.0f, 8.0f`) but `dispatch_render` checks against absolute `params.time`. Effects in sequences starting after t=0 were **never active** (e.g. Scene1 at t=20+ never satisfied `time < 8`). Fixed by emitting `seq.start_time + effect.start/end` as absolute times. All sequences now render correctly. + - **Files**: `src/effects/scene1_effect.{h,cc}` (new), `src/effects/shaders.{h,cc}`, `cmake/DemoSourceLists.cmake`, `src/gpu/demo_effects.h`, `src/tests/gpu/test_demo_effects.cc`, `workspaces/main/shaders/scene1.wgsl`, `workspaces/main/timeline.seq`, `src/generated/timeline.cc`, `tools/seq_compiler.py` + - **Tests**: 34/34 passing + ## Recently Completed (February 18, 2026) - [x] **MQ Spectral Editor Improvements** diff --git a/src/effects/scene1_effect.cc b/src/effects/scene1_effect.cc new file mode 100644 index 0000000..7c109e7 --- /dev/null +++ b/src/effects/scene1_effect.cc @@ -0,0 +1,45 @@ +// Scene1 effect implementation + +#include "effects/scene1_effect.h" +#include "effects/shaders.h" +#include "gpu/gpu.h" +#include "gpu/post_process_helper.h" +#include "util/fatal_error.h" + +Scene1::Scene1(const GpuContext& ctx, const std::vector& inputs, + const std::vector& outputs, float start_time, + float end_time) + : Effect(ctx, inputs, outputs, start_time, end_time) { + HEADLESS_RETURN_IF_NULL(ctx_.device); + + create_nearest_sampler(); + create_dummy_scene_texture(); + + pipeline_.set(create_post_process_pipeline( + ctx_.device, WGPUTextureFormat_RGBA8Unorm, scene1_shader_wgsl)); +} + +void Scene1::render(WGPUCommandEncoder encoder, + const UniformsSequenceParams& params, + NodeRegistry& nodes) { + WGPUTextureView output_view = nodes.get_view(output_nodes_[0]); + + pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(), + dummy_texture_view_.get(), uniforms_buffer_.get(), + {nullptr, 0}); + + WGPURenderPassColorAttachment color_attachment = {}; + gpu_init_color_attachment(color_attachment, output_view); + + WGPURenderPassDescriptor pass_desc = {}; + pass_desc.colorAttachmentCount = 1; + pass_desc.colorAttachments = &color_attachment; + + WGPURenderPassEncoder pass = + wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); + wgpuRenderPassEncoderSetPipeline(pass, pipeline_.get()); + wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_.get(), 0, nullptr); + wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle + wgpuRenderPassEncoderEnd(pass); + wgpuRenderPassEncoderRelease(pass); +} diff --git a/src/effects/scene1_effect.h b/src/effects/scene1_effect.h new file mode 100644 index 0000000..781cbae --- /dev/null +++ b/src/effects/scene1_effect.h @@ -0,0 +1,21 @@ +// Scene1 effect - raymarching cube & sphere scene + +#pragma once + +#include "gpu/effect.h" +#include "gpu/uniform_helper.h" +#include "gpu/wgpu_resource.h" + +class Scene1 : public Effect { + public: + Scene1(const GpuContext& ctx, const std::vector& inputs, + const std::vector& outputs, float start_time, + float end_time); + + void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, + NodeRegistry& nodes) override; + + private: + RenderPipeline pipeline_; + BindGroup bind_group_; +}; diff --git a/src/effects/shaders.cc b/src/effects/shaders.cc index d181632..4329427 100644 --- a/src/effects/shaders.cc +++ b/src/effects/shaders.cc @@ -92,6 +92,7 @@ const char* particle_render_wgsl = const char* rotating_cube_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_ROTATING_CUBE_V2); const char* flash_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_FLASH); +const char* scene1_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_SCENE1); // Compute shaders const char* gen_noise_compute_wgsl = diff --git a/src/effects/shaders.h b/src/effects/shaders.h index b8700f5..ee6c65e 100644 --- a/src/effects/shaders.h +++ b/src/effects/shaders.h @@ -14,6 +14,7 @@ extern const char* particle_compute_wgsl; extern const char* particle_render_wgsl; extern const char* rotating_cube_wgsl; extern const char* flash_shader_wgsl; +extern const char* scene1_shader_wgsl; // Compute shaders extern const char* gen_noise_compute_wgsl; diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h index 2825891..f746326 100644 --- a/src/gpu/demo_effects.h +++ b/src/gpu/demo_effects.h @@ -26,6 +26,7 @@ #include "effects/peak_meter_effect.h" #include "effects/placeholder_effect.h" #include "effects/rotating_cube_effect.h" +#include "effects/scene1_effect.h" // TODO: Port CNN effects // #include "../../cnn_v1/src/cnn_v1_effect.h" // #include "../../cnn_v2/src/cnn_v2_effect.h" diff --git a/src/tests/gpu/test_demo_effects.cc b/src/tests/gpu/test_demo_effects.cc index f193c76..132e489 100644 --- a/src/tests/gpu/test_demo_effects.cc +++ b/src/tests/gpu/test_demo_effects.cc @@ -64,6 +64,9 @@ static void test_effects() { {"PeakMeter", std::make_shared( fixture.ctx(), std::vector{"source"}, std::vector{"sink"}, 0.0f, 1000.0f)}, + {"Scene1", std::make_shared( + fixture.ctx(), std::vector{"source"}, + std::vector{"sink"}, 0.0f, 1000.0f)}, }; int passed = 0; diff --git a/tools/seq_compiler.py b/tools/seq_compiler.py index 18d5a1f..2e51574 100755 --- a/tools/seq_compiler.py +++ b/tools/seq_compiler.py @@ -437,7 +437,7 @@ class {class_name} : public Sequence {{ .effect = std::make_shared<{effect.class_name}>(ctx, std::vector{{{inputs_str}}}, std::vector{{{outputs_str}}}, - {effect.start}f, {effect.end}f), + {seq.start_time + effect.start}f, {seq.start_time + effect.end}f), .input_nodes = {{{inputs_str}}}, .output_nodes = {{{outputs_str}}}, .execution_order = {effect.execution_order} diff --git a/workspaces/main/shaders/scene1.wgsl b/workspaces/main/shaders/scene1.wgsl index 8d5d5db..2f1174a 100644 --- a/workspaces/main/shaders/scene1.wgsl +++ b/workspaces/main/shaders/scene1.wgsl @@ -1,13 +1,13 @@ // Scene1 effect shader - ShaderToy conversion (raymarching cube & sphere) // Source: Saturday cubism experiment by skal -#include "common_uniforms" +#include "sequence_uniforms" #include "math/color" #include "math/utils" #include "math/sdf_shapes" #include "render/raymarching" -@group(0) @binding(0) var uniforms: CommonUniforms; +@group(0) @binding(2) var uniforms: UniformsSequenceParams; const PI: f32 = 3.141592654; const TAU: f32 = 6.283185307; diff --git a/workspaces/main/timeline.seq b/workspaces/main/timeline.seq index 77f013d..2b843a7 100644 --- a/workspaces/main/timeline.seq +++ b/workspaces/main/timeline.seq @@ -25,9 +25,7 @@ SEQUENCE 16.00 2 "hybrid_heptagon" EFFECT + Hybrid3D temp1 -> sink 0.00 4.00 SEQUENCE 20.00 0 "heptagon_scene" - # Heptagon -> Scene1 (placeholder) -> sink - EFFECT + Heptagon source -> temp1 0.00 8.00 - EFFECT + Placeholder temp1 -> sink 0.00 8.00 + EFFECT + Scene1 source -> sink 0.00 8.00 SEQUENCE 28.00 0 "fade_test" # Heptagon -> Fade (placeholder) -> sink -- cgit v1.2.3