From 47397444b30b0f461b1633297a68300179586fda Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 10 Feb 2026 08:01:25 +0100 Subject: feat: Add CNN post-processing effect with modular WGSL architecture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements multi-layer convolutional neural network shader for stylized post-processing of 3D rendered scenes: **Core Components:** - CNNEffect: C++ effect class with single-layer rendering (expandable to multi-pass) - Modular WGSL snippets: cnn_activation, cnn_conv3x3/5x5/7x7, cnn_weights_generated - Placeholder identity-like weights for initial testing (to be replaced by trained weights) **Architecture:** - Flexible kernel sizes (3×3, 5×5, 7×7) via separate snippet files - ShaderComposer integration (#include resolution) - Residual connections (input + processed output) - Supports parallel convolutions (design ready, single conv implemented) **Size Impact:** - ~3-4 KB shader code (snippets + main shader) - ~2-4 KB weights (depends on network architecture when trained) - Total: ~5-8 KB (acceptable for 64k demo) **Testing:** - CNNEffect added to test_demo_effects.cc - 36/36 tests passing (100%) **Next Steps:** - Training script (scripts/train_cnn.py) to generate real weights - Multi-layer rendering with ping-pong textures - Weight quantization for size optimization handoff(Claude): CNN effect foundation complete, ready for training integration --- src/gpu/effects/cnn_effect.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/gpu/effects/cnn_effect.h (limited to 'src/gpu/effects/cnn_effect.h') diff --git a/src/gpu/effects/cnn_effect.h b/src/gpu/effects/cnn_effect.h new file mode 100644 index 0000000..9cc4935 --- /dev/null +++ b/src/gpu/effects/cnn_effect.h @@ -0,0 +1,29 @@ +// CNN post-processing effect header +// Multi-layer neural network stylization + +#pragma once +#include "gpu/effect.h" +#include "gpu/uniform_helper.h" + +struct CNNLayerParams { + int layer_index; + int use_residual; + float _pad[2]; +}; +static_assert(sizeof(CNNLayerParams) == 16); + +class CNNEffect : public PostProcessEffect { + public: + explicit CNNEffect(const GpuContext& ctx, int num_layers = 1); + + void init(MainSequence* demo) override; + void render(WGPURenderPassEncoder pass, float time, float beat, + float intensity, float aspect_ratio) override; + void update_bind_group(WGPUTextureView input_view) override; + + private: + int num_layers_; + WGPUTextureView input_view_; + UniformBuffer params_buffer_; + WGPUBindGroup bind_group_; +}; -- cgit v1.2.3