From 86e56474d284944795f4c02ae850561374620f8a Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 8 Feb 2026 21:58:49 +0100 Subject: feat: Add CircleMaskEffect and RotatingCubeEffect with auxiliary texture masking Implements demonstration of auxiliary texture masking system with: - CircleMaskEffect: Generates circular mask, renders green outside circle - RotatingCubeEffect: Renders SDF cube inside circle using mask Architecture: - Mask generation in compute phase (1.0 inside, 0.0 outside) - CircleMask renders green where mask < 0.5 (outside circle) - RotatingCube samples mask and discards where mask < 0.5 Files added: - src/gpu/effects/circle_mask_effect.{h,cc} - src/gpu/effects/rotating_cube_effect.{h,cc} - assets/final/shaders/{circle_mask_compute,circle_mask_render,masked_cube}.wgsl Build system: - Updated CMakeLists.txt with new effect sources - Registered shaders in demo_assets.txt - Updated test_demo_effects.cc (8 scene effects total) Status: Effects temporarily disabled in demo.seq (lines 31-35) - ShaderComposer snippet registration needed for masked_cube.wgsl - All 33 tests pass, demo runs without crashes Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/effects/rotating_cube_effect.h | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/gpu/effects/rotating_cube_effect.h (limited to 'src/gpu/effects/rotating_cube_effect.h') diff --git a/src/gpu/effects/rotating_cube_effect.h b/src/gpu/effects/rotating_cube_effect.h new file mode 100644 index 0000000..1ce81b7 --- /dev/null +++ b/src/gpu/effects/rotating_cube_effect.h @@ -0,0 +1,51 @@ +// This file is part of the 64k demo project. +// It defines RotatingCubeEffect for rendering a bump-mapped rotating cube. +// Uses auxiliary texture masking to render only inside a circular region. + +#ifndef ROTATING_CUBE_EFFECT_H_ +#define ROTATING_CUBE_EFFECT_H_ + +#include "gpu/effect.h" +#include "gpu/gpu.h" +#include "util/mini_math.h" + +class RotatingCubeEffect : public Effect { + public: + RotatingCubeEffect(const GpuContext& ctx); + ~RotatingCubeEffect() override; + + void init(MainSequence* demo) override; + void render(WGPURenderPassEncoder pass, float time, float beat, + float intensity, float aspect_ratio) override; + + private: + struct Uniforms { + mat4 view_proj; + mat4 inv_view_proj; + vec4 camera_pos_time; + vec4 params; + vec2 resolution; + vec2 padding; + }; + + struct ObjectData { + mat4 model; + mat4 inv_model; + vec4 color; + vec4 params; + }; + + MainSequence* demo_ = nullptr; + WGPURenderPipeline pipeline_ = nullptr; + WGPUBindGroup bind_group_0_ = nullptr; + WGPUBindGroup bind_group_1_ = nullptr; + GpuBuffer uniform_buffer_; + GpuBuffer object_buffer_; + WGPUTexture noise_texture_ = nullptr; + WGPUTextureView noise_view_ = nullptr; + WGPUSampler noise_sampler_ = nullptr; + WGPUSampler mask_sampler_ = nullptr; + float rotation_ = 0.0f; +}; + +#endif /* ROTATING_CUBE_EFFECT_H_ */ -- cgit v1.2.3