diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-20 08:42:07 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-20 08:42:07 +0100 |
| commit | f74bcd843c631f82daefe543fca7741fb5bb71f4 (patch) | |
| tree | 0983e6c36fb0f9e2b152f76437ecf91ee1fd99cb /cnn_v3/src/gbuffer_effect.h | |
| parent | a160cc797afb4291d356bdc0cbcf0f110e3ef8a9 (diff) | |
feat(cnn_v3): G-buffer phase 1 + training infrastructure
G-buffer (Phase 1):
- Add NodeTypes GBUF_ALBEDO/DEPTH32/R8/RGBA32UINT to NodeRegistry
- GBufferEffect: MRT raster pass (albedo+normal_mat+depth) + pack compute
- Shaders: gbuf_raster.wgsl (MRT), gbuf_pack.wgsl (feature packing, 32B/px)
- Shadow/SDF passes stubbed (placeholder textures), CMake integration deferred
Training infrastructure (Phase 2):
- blender_export.py: headless EXR export with all G-buffer render passes
- pack_blender_sample.py: EXR → per-channel PNGs (oct-normals, 1/z depth)
- pack_photo_sample.py: photo → zero-filled G-buffer sample layout
handoff(Gemini): G-buffer phases 3-5 remain (U-Net shaders, CNNv3Effect, parity)
Diffstat (limited to 'cnn_v3/src/gbuffer_effect.h')
| -rw-r--r-- | cnn_v3/src/gbuffer_effect.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/cnn_v3/src/gbuffer_effect.h b/cnn_v3/src/gbuffer_effect.h new file mode 100644 index 0000000..42fb0ec --- /dev/null +++ b/cnn_v3/src/gbuffer_effect.h @@ -0,0 +1,79 @@ +// GBufferEffect: Multi-pass G-buffer rendering for CNN v3 input +// Outputs: gbuf_feat0, gbuf_feat1 (packed rgba32uint feature textures, 32 bytes/pixel) + +#pragma once + +#include "3d/camera.h" +#include "3d/scene.h" +#include "gpu/effect.h" +#include "gpu/sequence.h" +#include "gpu/uniform_helper.h" +#include "gpu/wgpu_resource.h" +#include "util/mini_math.h" + +// Uniform for the pack compute shader +struct GBufResUniforms { + vec2 resolution; + float _pad0; + float _pad1; +}; +static_assert(sizeof(GBufResUniforms) == 16, + "GBufResUniforms must be 16 bytes"); + +class GBufferEffect : public Effect { + public: + GBufferEffect(const GpuContext& ctx, const std::vector<std::string>& inputs, + const std::vector<std::string>& outputs, float start_time, + float end_time); + + void declare_nodes(NodeRegistry& registry) override; + + void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, + NodeRegistry& nodes) override; + + void set_scene(const Scene* scene, const Camera* camera); + + private: + // Internal G-buffer node names + std::string node_albedo_; + std::string node_normal_mat_; + std::string node_depth_; + std::string node_shadow_; + std::string node_transp_; + std::string node_feat0_; + std::string node_feat1_; + + const Scene* scene_ = nullptr; + const Camera* camera_ = nullptr; + + // Pass 1: MRT rasterization pipeline + RenderPipeline raster_pipeline_; + BindGroup raster_bind_group_; + + // Pass 4: Pack compute pipeline + ComputePipeline pack_pipeline_; + BindGroup pack_bind_group_; + UniformBuffer<GBufResUniforms> 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_; + + // 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 + + void create_raster_pipeline(); + void create_pack_pipeline(); + + void update_raster_bind_group(NodeRegistry& nodes); + void update_pack_bind_group(NodeRegistry& nodes); + + void upload_scene_data(const Scene& scene, const Camera& camera, + float time); + void ensure_objects_buffer(int num_objects); +}; |
