summaryrefslogtreecommitdiff
path: root/src/effects/hybrid3_d_effect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects/hybrid3_d_effect.cc')
-rw-r--r--src/effects/hybrid3_d_effect.cc70
1 files changed, 40 insertions, 30 deletions
diff --git a/src/effects/hybrid3_d_effect.cc b/src/effects/hybrid3_d_effect.cc
index 0e6ea35..5832b57 100644
--- a/src/effects/hybrid3_d_effect.cc
+++ b/src/effects/hybrid3_d_effect.cc
@@ -1,15 +1,17 @@
// This file is part of the 64k demo project.
-// It implements Hybrid3DEffect (simplified v2 port).
+// It implements Hybrid3D (simplified v2 port).
// TODO: Full Renderer3D integration with texture manager, noise assets
#include "util/fatal_error.h"
#include "effects/hybrid3_d_effect.h"
+#include "gpu/gpu.h"
#include <cmath>
-Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), depth_node_(outputs[0] + "_depth"),
+Hybrid3D::Hybrid3D(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), depth_node_(outputs[0] + "_depth"),
dummy_texture_(nullptr), dummy_texture_view_(nullptr) {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
@@ -32,24 +34,12 @@ Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
uint32_t white_pixel = 0xFFFFFFFF;
#if defined(DEMO_CROSS_COMPILE_WIN32)
WGPUImageCopyTexture dst = {
- .texture = dummy_texture_,
- .mipLevel = 0,
- .origin = {0, 0, 0}
- };
- WGPUTextureDataLayout data_layout = {
- .bytesPerRow = 4,
- .rowsPerImage = 1
- };
+ .texture = dummy_texture_, .mipLevel = 0, .origin = {0, 0, 0}};
+ WGPUTextureDataLayout data_layout = {.bytesPerRow = 4, .rowsPerImage = 1};
#else
WGPUTexelCopyTextureInfo dst = {
- .texture = dummy_texture_,
- .mipLevel = 0,
- .origin = {0, 0, 0}
- };
- WGPUTexelCopyBufferLayout data_layout = {
- .bytesPerRow = 4,
- .rowsPerImage = 1
- };
+ .texture = dummy_texture_, .mipLevel = 0, .origin = {0, 0, 0}};
+ WGPUTexelCopyBufferLayout data_layout = {.bytesPerRow = 4, .rowsPerImage = 1};
#endif
WGPUExtent3D size = {1, 1, 1};
wgpuQueueWriteTexture(ctx_.queue, &dst, &white_pixel, 4, &data_layout, &size);
@@ -67,8 +57,9 @@ Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
scene_.add_object(center);
for (int i = 0; i < 8; ++i) {
- ObjectType type = (i % 3 == 1) ? ObjectType::TORUS :
- (i % 3 == 2) ? ObjectType::BOX : ObjectType::SPHERE;
+ ObjectType type = (i % 3 == 1) ? ObjectType::TORUS
+ : (i % 3 == 2) ? ObjectType::BOX
+ : ObjectType::SPHERE;
Object3D obj(type);
float angle = (i / 8.0f) * 6.28318f;
@@ -86,7 +77,7 @@ Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
}
}
-Hybrid3DEffect::~Hybrid3DEffect() {
+Hybrid3D::~Hybrid3D() {
if (dummy_texture_view_)
wgpuTextureViewRelease(dummy_texture_view_);
if (dummy_texture_)
@@ -94,14 +85,14 @@ Hybrid3DEffect::~Hybrid3DEffect() {
renderer_.shutdown();
}
-void Hybrid3DEffect::declare_nodes(NodeRegistry& registry) {
+void Hybrid3D::declare_nodes(NodeRegistry& registry) {
// Declare depth buffer node
registry.declare_node(depth_node_, NodeType::DEPTH24, -1, -1);
}
-void Hybrid3DEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Hybrid3D::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Update camera (orbiting)
float angle = params.time * 0.3f;
vec3 cam_pos = vec3(std::cos(angle) * 10.0f, 5.0f, std::sin(angle) * 10.0f);
@@ -113,6 +104,25 @@ void Hybrid3DEffect::render(WGPUCommandEncoder encoder,
WGPUTextureView color_view = nodes.get_view(output_nodes_[0]);
WGPUTextureView depth_view = nodes.get_view(depth_node_);
- // Render 3D scene
- renderer_.render(scene_, camera_, params.time, color_view, depth_view);
+ // Render 3D scene using sequence encoder
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, color_view);
+ color_attachment.clearValue = {0.05f, 0.05f, 0.05f, 1.0f};
+
+ WGPURenderPassDepthStencilAttachment depth_attachment = {};
+ depth_attachment.view = depth_view;
+ depth_attachment.depthLoadOp = WGPULoadOp_Clear;
+ depth_attachment.depthStoreOp = WGPUStoreOp_Store;
+ depth_attachment.depthClearValue = 1.0f;
+
+ WGPURenderPassDescriptor pass_desc = {};
+ pass_desc.colorAttachmentCount = 1;
+ pass_desc.colorAttachments = &color_attachment;
+ pass_desc.depthStencilAttachment = &depth_attachment;
+
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ renderer_.draw(pass, scene_, camera_, params.time);
+ wgpuRenderPassEncoderEnd(pass);
+ wgpuRenderPassEncoderRelease(pass);
}