From c5e66964c0463219019d0439ec20b79248637fa4 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 22 Mar 2026 19:15:55 +0100 Subject: feat(cnn_v3): GBufferEffect internal scene + GBufViewEffect debug wiring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GBufferEffect: - set_scene() now owns Scene/Camera internally; no external pointers needed - 20 randomly rotating cubes (xorshift32 seed, axis-angle animation) - 4 pumping spheres (radius = base_r * (1 + audio_intensity * 0.8)) - Camera at (0,2.5,6) looking at origin; aspect updated per-frame - GBufLightsUniforms: 2 directional lights (warm key + cool fill) - object_type written to ObjectData.params.x (ready for SDF shadow) - shadow/transp nodes cleared via zero-draw render passes (placeholder) - bilinear sampler cached via create_linear_sampler() / sampler_.get() - dead placeholder textures removed GBufViewEffect: - gbuf_view.wgsl: all channels now fully grayscale (removed color tint) - seq_compiler.py: GBufViewEffect added to CLASS_TO_HEADER - timeline.seq: cnn_v3_test uses GBufViewEffect -> sink for debug view Docs: HOWTO.md §1 updated with set_scene() description + §1b implementation plan for Pass 2 SDF shadow (shader spec, bind layout, C++ additions) handoff(Gemini): GBufferEffect has internal scene, 36/36 tests green. Next: implement Pass 2 shadow (gbuf_shadow.wgsl) per §1b plan in HOWTO.md. --- cnn_v3/src/gbuffer_effect.h | 51 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) (limited to 'cnn_v3/src/gbuffer_effect.h') diff --git a/cnn_v3/src/gbuffer_effect.h b/cnn_v3/src/gbuffer_effect.h index 42fb0ec..d45be75 100644 --- a/cnn_v3/src/gbuffer_effect.h +++ b/cnn_v3/src/gbuffer_effect.h @@ -10,6 +10,7 @@ #include "gpu/uniform_helper.h" #include "gpu/wgpu_resource.h" #include "util/mini_math.h" +#include // Uniform for the pack compute shader struct GBufResUniforms { @@ -20,6 +21,20 @@ struct GBufResUniforms { static_assert(sizeof(GBufResUniforms) == 16, "GBufResUniforms must be 16 bytes"); +// Single directional light: direction points *toward* the light source (world space). +struct GBufLight { + vec4 direction; // xyz = normalized direction toward light, w = unused + vec4 color; // rgb = color, a = intensity +}; +static_assert(sizeof(GBufLight) == 32, "GBufLight must be 32 bytes"); + +struct GBufLightsUniforms { + GBufLight lights[2]; + vec4 params; // x = num_lights +}; +static_assert(sizeof(GBufLightsUniforms) == 80, + "GBufLightsUniforms must be 80 bytes"); + class GBufferEffect : public Effect { public: GBufferEffect(const GpuContext& ctx, const std::vector& inputs, @@ -31,9 +46,22 @@ class GBufferEffect : public Effect { void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) override; - void set_scene(const Scene* scene, const Camera* camera); + // Populate the internal scene with ~20 rotating cubes and a few pumping + // spheres. Must be called once before the first render(). + void set_scene(); private: + // Per-cube animation state (axis-angle rotation) + struct CubeAnim { + vec3 axis; + float speed; // radians/second, may be negative + }; + // Per-sphere animation state (radius driven by audio_intensity) + struct SphereAnim { + int obj_idx; // index into scene_.objects + float base_radius; + }; + // Internal G-buffer node names std::string node_albedo_; std::string node_normal_mat_; @@ -43,8 +71,13 @@ class GBufferEffect : public Effect { std::string node_feat0_; std::string node_feat1_; - const Scene* scene_ = nullptr; - const Camera* camera_ = nullptr; + // Owned scene and camera — populated by set_scene() + Scene scene_; + Camera camera_; + bool scene_ready_ = false; + + std::vector cube_anims_; + std::vector sphere_anims_; // Pass 1: MRT rasterization pipeline RenderPipeline raster_pipeline_; @@ -53,19 +86,13 @@ class GBufferEffect : public Effect { // Pass 4: Pack compute pipeline ComputePipeline pack_pipeline_; BindGroup pack_bind_group_; - UniformBuffer pack_res_uniform_; - - // Placeholder textures for shadow/transp (white/black cleared once) - Texture shadow_placeholder_tex_; - TextureView shadow_placeholder_view_; - Texture transp_placeholder_tex_; - TextureView transp_placeholder_view_; + UniformBuffer pack_res_uniform_; + UniformBuffer lights_uniform_; // GPU-side object data buffers (global uniforms + objects storage) - // These mirror the layout expected by gbuf_raster.wgsl GpuBuffer global_uniforms_buf_; GpuBuffer objects_buf_; - int objects_buf_capacity_ = 0; // number of ObjectData slots allocated + int objects_buf_capacity_ = 0; void create_raster_pipeline(); void create_pack_pipeline(); -- cgit v1.2.3