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/gpu/effects/hybrid_3d_effect.cc | 83 ++++++++++++++++++++----------------- src/gpu/effects/hybrid_3d_effect.h | 10 +++-- 2 files changed, 52 insertions(+), 41 deletions(-) (limited to 'src/gpu/effects') diff --git a/src/gpu/effects/hybrid_3d_effect.cc b/src/gpu/effects/hybrid_3d_effect.cc index 41ede0b..6af2bd4 100644 --- a/src/gpu/effects/hybrid_3d_effect.cc +++ b/src/gpu/effects/hybrid_3d_effect.cc @@ -2,34 +2,38 @@ // It implements the Hybrid3DEffect. #include "gpu/effects/hybrid_3d_effect.h" -#include "util/asset_manager.h" #include "generated/assets.h" -#include +#include "util/asset_manager.h" #include +#include #include -Hybrid3DEffect::Hybrid3DEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) : Effect(device, queue), width_(1280), height_(720) { +Hybrid3DEffect::Hybrid3DEffect(WGPUDevice device, WGPUQueue queue, + WGPUTextureFormat format) + : Effect(device, queue), width_(1280), height_(720) { (void)format; // Passed to base, not directly used here. } void Hybrid3DEffect::init(MainSequence* demo) { - (void)demo; - WGPUTextureFormat format = demo->format; // Get current format from MainSequence (might be different than constructor if resized) - + (void)demo; + WGPUTextureFormat format = + demo->format; // Get current format from MainSequence (might be different + // than constructor if resized) + renderer_.init(device_, queue_, format); renderer_.resize(width_, height_); // Texture Manager texture_manager_.init(device_, queue_); - + // Load Noise Asset size_t size = 0; const uint8_t* noise_data = GetAsset(AssetId::ASSET_NOISE_TEX, &size); if (noise_data && size == 256 * 256 * 4) { - texture_manager_.create_texture("noise", 256, 256, noise_data); - renderer_.set_noise_texture(texture_manager_.get_texture_view("noise")); + texture_manager_.create_texture("noise", 256, 256, noise_data); + renderer_.set_noise_texture(texture_manager_.get_texture_view("noise")); } else { - std::cerr << "Failed to load NOISE_TEX asset." << std::endl; + std::cerr << "Failed to load NOISE_TEX asset." << std::endl; } // Setup Scene @@ -41,40 +45,45 @@ void Hybrid3DEffect::init(MainSequence* demo) { for (int i = 0; i < 8; ++i) { ObjectType type = ObjectType::SPHERE; - if (i % 3 == 1) type = ObjectType::TORUS; - if (i % 3 == 2) type = ObjectType::BOX; - + if (i % 3 == 1) + type = ObjectType::TORUS; + if (i % 3 == 2) + type = ObjectType::BOX; + Object3D obj(type); float angle = (i / 8.0f) * 6.28318f; obj.position = vec3(std::cos(angle) * 4.0f, 0, std::sin(angle) * 4.0f); obj.scale = vec3(0.5f, 0.5f, 0.5f); - - if (type == ObjectType::SPHERE) obj.color = vec4(0, 1, 0, 1); - else if (type == ObjectType::TORUS) obj.color = vec4(0, 0.5, 1, 1); - else obj.color = vec4(1, 1, 0, 1); - + + if (type == ObjectType::SPHERE) + obj.color = vec4(0, 1, 0, 1); + else if (type == ObjectType::TORUS) + obj.color = vec4(0, 0.5, 1, 1); + else + obj.color = vec4(1, 1, 0, 1); + scene_.add_object(obj); } } -void Hybrid3DEffect::render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) { - // Animate Objects - for (size_t i = 1; i < scene_.objects.size(); ++i) { - scene_.objects[i].rotation = quat::from_axis(vec3(0, 1, 0), time * 2.0f + i); - scene_.objects[i].position.y = std::sin(time * 3.0f + i) * 1.5f; - } - - // Animate Camera - float cam_radius = 10.0f + std::sin(time * 0.3f) * 4.0f; - float cam_height = 5.0f + std::cos(time * 0.4f) * 3.0f; - camera_.set_look_at( - vec3(std::sin(time * 0.5f) * cam_radius, cam_height, std::cos(time * 0.5f) * cam_radius), - vec3(0, 0, 0), - vec3(0, 1, 0) - ); - - camera_.aspect_ratio = aspect_ratio; +void Hybrid3DEffect::render(WGPURenderPassEncoder pass, float time, float beat, + float intensity, float aspect_ratio) { + // Animate Objects + for (size_t i = 1; i < scene_.objects.size(); ++i) { + scene_.objects[i].rotation = + quat::from_axis(vec3(0, 1, 0), time * 2.0f + i); + scene_.objects[i].position.y = std::sin(time * 3.0f + i) * 1.5f; + } + + // Animate Camera + float cam_radius = 10.0f + std::sin(time * 0.3f) * 4.0f; + float cam_height = 5.0f + std::cos(time * 0.4f) * 3.0f; + camera_.set_look_at(vec3(std::sin(time * 0.5f) * cam_radius, cam_height, + std::cos(time * 0.5f) * cam_radius), + vec3(0, 0, 0), vec3(0, 1, 0)); + + camera_.aspect_ratio = aspect_ratio; - // Draw - renderer_.draw(pass, scene_, camera_, time); + // Draw + renderer_.draw(pass, scene_, camera_, time); } diff --git a/src/gpu/effects/hybrid_3d_effect.h b/src/gpu/effects/hybrid_3d_effect.h index 1b0eab7..ef62883 100644 --- a/src/gpu/effects/hybrid_3d_effect.h +++ b/src/gpu/effects/hybrid_3d_effect.h @@ -1,12 +1,13 @@ // This file is part of the 64k demo project. -// It defines the Hybrid3DEffect, integrating the 3D renderer into the demo timeline. +// It defines the Hybrid3DEffect, integrating the 3D renderer into the demo +// timeline. #pragma once -#include "gpu/effect.h" +#include "3d/camera.h" #include "3d/renderer.h" #include "3d/scene.h" -#include "3d/camera.h" +#include "gpu/effect.h" #include "gpu/texture_manager.h" class Hybrid3DEffect : public Effect { @@ -15,7 +16,8 @@ class Hybrid3DEffect : public Effect { virtual ~Hybrid3DEffect() override = default; void init(MainSequence* demo) override; - void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; + void render(WGPURenderPassEncoder pass, float time, float beat, + float intensity, float aspect_ratio) override; private: Renderer3D renderer_; -- cgit v1.2.3