From e3ef115804b46e8bfc594987b04b1059aed5e002 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 1 Feb 2026 18:56:47 +0100 Subject: feat(gpu/assets): Fix tests, integrate bumpy 3D renderer and procedural assets - Fixed test_sequence by restoring MainSequence::init_test for mocking. - Corrected CMakeLists.txt dependencies and source groupings to prevent duplicate symbols. - standardizing Effect constructor signature for seq_compiler compatibility. - Implemented Hybrid3DEffect using bumpy Renderer3D and procedural NOISE_TEX. - Updated MainSequence to support depth buffer for 3D elements. - Formatted all source files with clang-format. --- src/3d/renderer.cc | 52 +++++++++++++--------------------------------------- src/3d/renderer.h | 23 +++++++++++------------ 2 files changed, 24 insertions(+), 51 deletions(-) (limited to 'src/3d') diff --git a/src/3d/renderer.cc b/src/3d/renderer.cc index 0a2ae9a..db9d73d 100644 --- a/src/3d/renderer.cc +++ b/src/3d/renderer.cc @@ -3,8 +3,8 @@ #include "3d/renderer.h" #include -#include #include +#include #include static const char* kShaderCode = R"( @@ -429,17 +429,14 @@ void Renderer3D::update_uniforms(const Scene& scene, const Camera& camera, } } -void Renderer3D::draw(WGPURenderPassEncoder pass, const Scene& scene, const Camera& camera, float time) { - +void Renderer3D::draw(WGPURenderPassEncoder pass, const Scene& scene, + const Camera& camera, float time) { update_uniforms(scene, camera, time); - - // Lazy Bind Group creation - if (bind_group_) wgpuBindGroupRelease(bind_group_); - - + if (bind_group_) + wgpuBindGroupRelease(bind_group_); WGPUBindGroupEntry bg_entries[4] = {}; @@ -463,8 +460,6 @@ void Renderer3D::draw(WGPURenderPassEncoder pass, const Scene& scene, const Came bg_entries[3].sampler = default_sampler_; - - WGPUBindGroupDescriptor bg_desc = {}; bg_desc.layout = wgpuRenderPipelineGetBindGroupLayout(pipeline_, 0); @@ -477,35 +472,26 @@ void Renderer3D::draw(WGPURenderPassEncoder pass, const Scene& scene, const Came wgpuBindGroupLayoutRelease(bg_desc.layout); - - wgpuRenderPassEncoderSetPipeline(pass, pipeline_); wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr); - - - uint32_t instance_count = (uint32_t)std::min((size_t)kMaxObjects, scene.objects.size()); + uint32_t instance_count = + (uint32_t)std::min((size_t)kMaxObjects, scene.objects.size()); if (instance_count > 0) { - wgpuRenderPassEncoderDraw(pass, 36, instance_count, 0, 0); - } - } - - void Renderer3D::render(const Scene& scene, const Camera& camera, float time, - WGPUTextureView target_view, WGPUTextureView depth_view_opt) { - + WGPUTextureView target_view, + WGPUTextureView depth_view_opt) { WGPUTextureView depth_view = depth_view_opt ? depth_view_opt : depth_view_; - if (!depth_view) return; - - + if (!depth_view) + return; WGPURenderPassColorAttachment color_attachment = {}; @@ -513,8 +499,6 @@ void Renderer3D::render(const Scene& scene, const Camera& camera, float time, color_attachment.clearValue = {0.05, 0.05, 0.1, 1.0}; - - WGPURenderPassDepthStencilAttachment depth_attachment = {}; depth_attachment.view = depth_view; @@ -525,8 +509,6 @@ void Renderer3D::render(const Scene& scene, const Camera& camera, float time, depth_attachment.depthClearValue = 1.0f; - - WGPURenderPassDescriptor pass_desc = {}; pass_desc.colorAttachmentCount = 1; @@ -535,30 +517,22 @@ void Renderer3D::render(const Scene& scene, const Camera& camera, float time, pass_desc.depthStencilAttachment = &depth_attachment; - - WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device_, nullptr); - WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); - - + WGPURenderPassEncoder pass = + wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); draw(pass, scene, camera, time); - - wgpuRenderPassEncoderEnd(pass); WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr); wgpuQueueSubmit(queue_, 1, &commands); - - wgpuRenderPassEncoderRelease(pass); wgpuCommandBufferRelease(commands); wgpuCommandEncoderRelease(encoder); - } \ No newline at end of file diff --git a/src/3d/renderer.h b/src/3d/renderer.h index e87d47a..8cb379b 100644 --- a/src/3d/renderer.h +++ b/src/3d/renderer.h @@ -28,25 +28,24 @@ class Renderer3D { void init(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void shutdown(); - // Renders the scene to the given texture view (Convenience: creates a pass) + // Renders the scene to the given texture view (Convenience: creates a pass) - void render(const Scene& scene, const Camera& camera, float time, + void render(const Scene& scene, const Camera& camera, float time, - WGPUTextureView target_view, WGPUTextureView depth_view_opt = nullptr); + WGPUTextureView target_view, + WGPUTextureView depth_view_opt = nullptr); - + // Records draw commands to an existing pass. - // Records draw commands to an existing pass. + // Assumes the pass has a compatible pipeline (or we set it here). - // Assumes the pass has a compatible pipeline (or we set it here). + // Note: Caller must ensure depth/color attachments are set up correctly in + // the pass. - // Note: Caller must ensure depth/color attachments are set up correctly in the pass. + void draw(WGPURenderPassEncoder pass, const Scene& scene, + const Camera& camera, float time); - void draw(WGPURenderPassEncoder pass, const Scene& scene, const Camera& camera, float time); - - - - void set_noise_texture(WGPUTextureView noise_view); + void set_noise_texture(WGPUTextureView noise_view); // Resize handler (if needed for internal buffers) void resize(int width, int height); -- cgit v1.2.3