summaryrefslogtreecommitdiff
path: root/src/effects
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/flash_effect.cc70
-rw-r--r--src/effects/flash_effect.h21
-rw-r--r--src/effects/gaussian_blur_effect.cc54
-rw-r--r--src/effects/gaussian_blur_effect.h13
-rw-r--r--src/effects/heptagon_effect.cc80
-rw-r--r--src/effects/heptagon_effect.h18
-rw-r--r--src/effects/hybrid3_d_effect.cc70
-rw-r--r--src/effects/hybrid3_d_effect.h13
-rw-r--r--src/effects/particles_effect.cc67
-rw-r--r--src/effects/particles_effect.h13
-rw-r--r--src/effects/passthrough_effect.cc69
-rw-r--r--src/effects/passthrough_effect.h14
-rw-r--r--src/effects/peak_meter_effect.cc38
-rw-r--r--src/effects/peak_meter_effect.h14
-rw-r--r--src/effects/placeholder_effect.cc57
-rw-r--r--src/effects/placeholder_effect.h11
-rw-r--r--src/effects/rotating_cube_effect.cc68
-rw-r--r--src/effects/rotating_cube_effect.h13
-rw-r--r--src/effects/shaders.cc108
-rw-r--r--src/effects/shaders.h25
20 files changed, 437 insertions, 399 deletions
diff --git a/src/effects/flash_effect.cc b/src/effects/flash_effect.cc
index 1d0e629..93ff4dd 100644
--- a/src/effects/flash_effect.cc
+++ b/src/effects/flash_effect.cc
@@ -2,54 +2,26 @@
// Pulses white based on beat timing
#include "effects/flash_effect.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
#include "util/fatal_error.h"
-FlashEffect::FlashEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
- sampler_(nullptr), dummy_texture_(nullptr), dummy_texture_view_(nullptr) {
+Flash::Flash(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) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
- uniforms_buffer_.init(ctx_.device);
- pipeline_ = create_post_process_pipeline(ctx_.device,
- WGPUTextureFormat_RGBA8Unorm,
- flash_shader_wgsl);
+ init_uniforms_buffer();
+ create_nearest_sampler();
+ create_dummy_scene_texture();
- // Create dummy sampler (scene effects don't use texture input)
- WGPUSamplerDescriptor sampler_desc = {};
- sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
- sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
- sampler_desc.magFilter = WGPUFilterMode_Nearest;
- sampler_desc.minFilter = WGPUFilterMode_Nearest;
- sampler_desc.maxAnisotropy = 1;
- sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
-
- // Create 1×1 dummy texture
- WGPUTextureDescriptor tex_desc = {};
- tex_desc.size = {1, 1, 1};
- tex_desc.format = WGPUTextureFormat_RGBA8Unorm;
- tex_desc.usage = WGPUTextureUsage_TextureBinding;
- tex_desc.dimension = WGPUTextureDimension_2D;
- tex_desc.mipLevelCount = 1;
- tex_desc.sampleCount = 1;
- dummy_texture_ = wgpuDeviceCreateTexture(ctx_.device, &tex_desc);
- dummy_texture_view_ = wgpuTextureCreateView(dummy_texture_, nullptr);
-}
-
-FlashEffect::~FlashEffect() {
- if (bind_group_) wgpuBindGroupRelease(bind_group_);
- if (pipeline_) wgpuRenderPipelineRelease(pipeline_);
- if (sampler_) wgpuSamplerRelease(sampler_);
- if (dummy_texture_view_) wgpuTextureViewRelease(dummy_texture_view_);
- if (dummy_texture_) wgpuTextureRelease(dummy_texture_);
+ pipeline_.set(create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, flash_shader_wgsl));
}
-void FlashEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Flash::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params, NodeRegistry& nodes) {
// Get output view (scene effects typically write to output, ignore input)
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -57,24 +29,22 @@ void FlashEffect::render(WGPUCommandEncoder encoder,
uniforms_buffer_.update(ctx_.queue, params);
// Update bind group (use dummy texture for scene effect)
- pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, dummy_texture_view_,
- uniforms_buffer_.get(), {nullptr, 0});
+ pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(),
+ dummy_texture_view_.get(), uniforms_buffer_.get(),
+ {nullptr, 0});
// Render pass
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
- color_attachment.loadOp = WGPULoadOp_Clear;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
- wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
- wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ wgpuRenderPassEncoderSetPipeline(pass, pipeline_.get());
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_.get(), 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
wgpuRenderPassEncoderEnd(pass);
wgpuRenderPassEncoderRelease(pass);
diff --git a/src/effects/flash_effect.h b/src/effects/flash_effect.h
index b9bbff8..052957d 100644
--- a/src/effects/flash_effect.h
+++ b/src/effects/flash_effect.h
@@ -4,23 +4,18 @@
#pragma once
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
+#include "gpu/wgpu_resource.h"
-class FlashEffect : public Effect {
+class Flash : public Effect {
public:
- FlashEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~FlashEffect() override;
+ Flash(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
- WGPURenderPipeline pipeline_;
- WGPUBindGroup bind_group_;
- WGPUSampler sampler_;
- WGPUTexture dummy_texture_;
- WGPUTextureView dummy_texture_view_;
- UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
+ RenderPipeline pipeline_;
+ BindGroup bind_group_;
};
diff --git a/src/effects/gaussian_blur_effect.cc b/src/effects/gaussian_blur_effect.cc
index adb094c..0548b4a 100644
--- a/src/effects/gaussian_blur_effect.cc
+++ b/src/effects/gaussian_blur_effect.cc
@@ -1,39 +1,28 @@
-// Gaussian blur effect v2 implementation
+// Gaussian blur effect implementation
#include "effects/gaussian_blur_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-GaussianBlurEffect::GaussianBlurEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
- sampler_(nullptr) {
- // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
+GaussianBlur::GaussianBlur(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), pipeline_(nullptr), bind_group_(nullptr) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
- // Create pipeline
- pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- gaussian_blur_v2_shader_wgsl);
-
- // Create sampler
- WGPUSamplerDescriptor sampler_desc = {};
- sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
- sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
- sampler_desc.magFilter = WGPUFilterMode_Linear;
- sampler_desc.minFilter = WGPUFilterMode_Linear;
- sampler_desc.maxAnisotropy = 1;
- sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
-
- // Init uniform buffers
+ init_uniforms_buffer();
+ create_linear_sampler();
params_buffer_.init(ctx_.device);
- uniforms_buffer_.init(ctx_.device);
+
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, gaussian_blur_shader_wgsl);
}
-void GaussianBlurEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void GaussianBlur::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Get input/output views
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -45,7 +34,7 @@ void GaussianBlurEffect::render(WGPUCommandEncoder encoder,
// Update bind group
WGPUBindGroupEntry entries[4] = {};
entries[0].binding = PP_BINDING_SAMPLER;
- entries[0].sampler = sampler_;
+ entries[0].sampler = sampler_.get();
entries[1].binding = PP_BINDING_TEXTURE;
entries[1].textureView = input_view;
entries[2].binding = PP_BINDING_UNIFORMS;
@@ -67,17 +56,14 @@ void GaussianBlurEffect::render(WGPUCommandEncoder encoder,
// Render pass
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
- color_attachment.loadOp = WGPULoadOp_Clear;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
diff --git a/src/effects/gaussian_blur_effect.h b/src/effects/gaussian_blur_effect.h
index 8bf34dc..f4b8fcf 100644
--- a/src/effects/gaussian_blur_effect.h
+++ b/src/effects/gaussian_blur_effect.h
@@ -6,7 +6,7 @@
#include "gpu/uniform_helper.h"
struct GaussianBlurParams {
- float strength = 1.0f;
+ float strength = 8.0f;
float strength_audio = 0.5f;
float stretch = 1.0f;
float _pad = 0.0f;
@@ -14,11 +14,11 @@ struct GaussianBlurParams {
static_assert(sizeof(GaussianBlurParams) == 16,
"GaussianBlurParams must be 16 bytes");
-class GaussianBlurEffect : public Effect {
+class GaussianBlur : public Effect {
public:
- GaussianBlurEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
+ GaussianBlur(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
@@ -26,9 +26,6 @@ class GaussianBlurEffect : public Effect {
private:
WGPURenderPipeline pipeline_;
WGPUBindGroup bind_group_;
- WGPUSampler sampler_;
GaussianBlurParams blur_params_;
UniformBuffer<GaussianBlurParams> params_buffer_;
- UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
};
-
diff --git a/src/effects/heptagon_effect.cc b/src/effects/heptagon_effect.cc
index 303ab2a..c9ec17c 100644
--- a/src/effects/heptagon_effect.cc
+++ b/src/effects/heptagon_effect.cc
@@ -1,57 +1,29 @@
-// Heptagon effect v2 implementation
+// Heptagon effect implementation
#include "effects/heptagon_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-HeptagonEffect::HeptagonEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr), sampler_(nullptr) {
- // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
+Heptagon::Heptagon(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) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
- // Init uniforms
- uniforms_buffer_.init(ctx_.device);
-
- // Create pipeline (standard v2 post-process, no depth)
- pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- heptagon_v2_shader_wgsl);
-
- // Create dummy sampler (scene effects don't use texture input)
- WGPUSamplerDescriptor sampler_desc = {};
- sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
- sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
- sampler_desc.magFilter = WGPUFilterMode_Nearest;
- sampler_desc.minFilter = WGPUFilterMode_Nearest;
- sampler_desc.maxAnisotropy = 1;
- sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
-
- // Create 1×1 dummy texture
- WGPUTextureDescriptor tex_desc = {};
- tex_desc.size = {1, 1, 1};
- tex_desc.format = WGPUTextureFormat_RGBA8Unorm;
- tex_desc.usage = WGPUTextureUsage_TextureBinding;
- tex_desc.dimension = WGPUTextureDimension_2D;
- tex_desc.mipLevelCount = 1;
- tex_desc.sampleCount = 1;
- dummy_texture_ = wgpuDeviceCreateTexture(ctx_.device, &tex_desc);
- dummy_texture_view_ = wgpuTextureCreateView(dummy_texture_, nullptr);
-}
+ init_uniforms_buffer();
+ create_nearest_sampler();
+ create_dummy_scene_texture();
-HeptagonEffect::~HeptagonEffect() {
- if (bind_group_) wgpuBindGroupRelease(bind_group_);
- if (pipeline_) wgpuRenderPipelineRelease(pipeline_);
- if (sampler_) wgpuSamplerRelease(sampler_);
- if (dummy_texture_view_) wgpuTextureViewRelease(dummy_texture_view_);
- if (dummy_texture_) wgpuTextureRelease(dummy_texture_);
+ pipeline_.set(create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, heptagon_shader_wgsl));
}
-void HeptagonEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Heptagon::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Get output view (scene effects typically write to output, ignore input)
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -59,25 +31,23 @@ void HeptagonEffect::render(WGPUCommandEncoder encoder,
uniforms_buffer_.update(ctx_.queue, params);
// Create bind group (use dummy texture for scene effect)
- pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, dummy_texture_view_,
- uniforms_buffer_.get(), {nullptr, 0});
+ pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(),
+ dummy_texture_view_.get(), uniforms_buffer_.get(),
+ {nullptr, 0});
// Render pass
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
- color_attachment.loadOp = WGPULoadOp_Clear;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
- wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
- wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 21, 1, 0, 0); // 7 triangles * 3 vertices
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ wgpuRenderPassEncoderSetPipeline(pass, pipeline_.get());
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_.get(), 0, nullptr);
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle
wgpuRenderPassEncoderEnd(pass);
wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/heptagon_effect.h b/src/effects/heptagon_effect.h
index 9f148a1..4563e47 100644
--- a/src/effects/heptagon_effect.h
+++ b/src/effects/heptagon_effect.h
@@ -4,22 +4,18 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
+#include "gpu/wgpu_resource.h"
-class HeptagonEffect : public Effect {
+class Heptagon : public Effect {
public:
- HeptagonEffect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~HeptagonEffect();
+ Heptagon(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
- WGPURenderPipeline pipeline_;
- WGPUBindGroup bind_group_;
- WGPUSampler sampler_;
- WGPUTexture dummy_texture_;
- WGPUTextureView dummy_texture_view_;
- UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
+ RenderPipeline pipeline_;
+ BindGroup bind_group_;
};
-
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);
}
diff --git a/src/effects/hybrid3_d_effect.h b/src/effects/hybrid3_d_effect.h
index e6e0f49..e0aa6da 100644
--- a/src/effects/hybrid3_d_effect.h
+++ b/src/effects/hybrid3_d_effect.h
@@ -9,16 +9,15 @@
#include "3d/scene.h"
#include "gpu/effect.h"
-class Hybrid3DEffect : public Effect {
+class Hybrid3D : public Effect {
public:
- Hybrid3DEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~Hybrid3DEffect() override;
+ Hybrid3D(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~Hybrid3D() override;
void declare_nodes(NodeRegistry& registry) override;
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
diff --git a/src/effects/particles_effect.cc b/src/effects/particles_effect.cc
index b9e2b9c..3c9feb7 100644
--- a/src/effects/particles_effect.cc
+++ b/src/effects/particles_effect.cc
@@ -1,21 +1,20 @@
// This file is part of the 64k demo project.
-// It implements the ParticlesEffect.
+// It implements the Particles.
-#include "util/fatal_error.h"
#include "effects/particles_effect.h"
+#include "effects/shaders.h"
#include "gpu/gpu.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
#include <vector>
-ParticlesEffect::ParticlesEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs) {
- // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
+Particles::Particles(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) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
- // Initialize uniforms
- uniforms_.init(ctx_.device);
+ init_uniforms_buffer();
// Initialize particles buffer
std::vector<Particle> init_p(NUM_PARTICLES);
@@ -48,51 +47,53 @@ ParticlesEffect::ParticlesEffect(const GpuContext& ctx,
// Create compute shader (particle simulation)
ResourceBinding compute_bindings[] = {
{particles_buffer_, WGPUBufferBindingType_Storage},
- {uniforms_.get(), WGPUBufferBindingType_Uniform}};
- compute_pass_ = gpu_create_compute_pass(ctx_.device, particle_compute_v2_wgsl,
+ {uniforms_buffer_.get(), WGPUBufferBindingType_Uniform}};
+ compute_pass_ = gpu_create_compute_pass(ctx_.device, particle_compute_wgsl,
compute_bindings, 2);
compute_pass_.workgroup_size_x = (NUM_PARTICLES + 63) / 64;
// Create render shader (particle rendering)
ResourceBinding render_bindings[] = {
{particles_buffer_, WGPUBufferBindingType_ReadOnlyStorage},
- {uniforms_.get(), WGPUBufferBindingType_Uniform}};
- render_pass_ = gpu_create_render_pass(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- particle_render_v2_wgsl, render_bindings, 2);
+ {uniforms_buffer_.get(), WGPUBufferBindingType_Uniform}};
+ render_pass_ =
+ gpu_create_render_pass(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
+ particle_render_wgsl, render_bindings, 2);
render_pass_.vertex_count = 6;
render_pass_.instance_count = NUM_PARTICLES;
}
-void ParticlesEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Particles::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Update uniforms
- uniforms_.update(ctx_.queue, params);
+ uniforms_buffer_.update(ctx_.queue, params);
// Run compute pass (particle simulation)
- WGPUComputePassEncoder compute = wgpuCommandEncoderBeginComputePass(encoder, nullptr);
+ WGPUComputePassEncoder compute =
+ wgpuCommandEncoderBeginComputePass(encoder, nullptr);
wgpuComputePassEncoderSetPipeline(compute, compute_pass_.pipeline);
- wgpuComputePassEncoderSetBindGroup(compute, 0, compute_pass_.bind_group, 0, nullptr);
- wgpuComputePassEncoderDispatchWorkgroups(compute, compute_pass_.workgroup_size_x, 1, 1);
+ wgpuComputePassEncoderSetBindGroup(compute, 0, compute_pass_.bind_group, 0,
+ nullptr);
+ wgpuComputePassEncoderDispatchWorkgroups(
+ compute, compute_pass_.workgroup_size_x, 1, 1);
wgpuComputePassEncoderEnd(compute);
// Run render pass (draw particles to output)
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
- WGPURenderPassColorAttachment color_attachment = {
- .view = output_view,
- .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
- .storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}};
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor render_desc = {
- .colorAttachmentCount = 1,
- .colorAttachments = &color_attachment};
+ .colorAttachmentCount = 1, .colorAttachments = &color_attachment};
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &render_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &render_desc);
wgpuRenderPassEncoderSetPipeline(pass, render_pass_.pipeline);
- wgpuRenderPassEncoderSetBindGroup(pass, 0, render_pass_.bind_group, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, render_pass_.vertex_count, render_pass_.instance_count, 0, 0);
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, render_pass_.bind_group, 0,
+ nullptr);
+ wgpuRenderPassEncoderDraw(pass, render_pass_.vertex_count,
+ render_pass_.instance_count, 0, 0);
wgpuRenderPassEncoderEnd(pass);
}
diff --git a/src/effects/particles_effect.h b/src/effects/particles_effect.h
index 76c2ef4..e855b7b 100644
--- a/src/effects/particles_effect.h
+++ b/src/effects/particles_effect.h
@@ -18,19 +18,16 @@ struct Particle {
float color[4];
};
-class ParticlesEffect : public Effect {
+class Particles : public Effect {
public:
- ParticlesEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ Particles(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
ComputePass compute_pass_;
RenderPass render_pass_;
GpuBuffer particles_buffer_;
- UniformBuffer<UniformsSequenceParams> uniforms_;
};
-
diff --git a/src/effects/passthrough_effect.cc b/src/effects/passthrough_effect.cc
index 56e3711..24eefca 100644
--- a/src/effects/passthrough_effect.cc
+++ b/src/effects/passthrough_effect.cc
@@ -1,39 +1,27 @@
-// Passthrough effect v2 implementation
+// Passthrough effect implementation
#include "effects/passthrough_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-PassthroughEffect::PassthroughEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
- sampler_(nullptr) {
- // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
+Passthrough::Passthrough(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) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
- // Init uniform buffer
- uniforms_buffer_.init(ctx_.device);
- // Create pipeline (simple version without effect params)
- pipeline_ = create_post_process_pipeline_simple(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- passthrough_v2_shader_wgsl);
+ init_uniforms_buffer();
+ create_linear_sampler();
- // Create sampler
- WGPUSamplerDescriptor sampler_desc = {};
- sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
- sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
- sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
- sampler_desc.magFilter = WGPUFilterMode_Linear;
- sampler_desc.minFilter = WGPUFilterMode_Linear;
- sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Nearest;
- sampler_desc.maxAnisotropy = 1;
- sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
+ pipeline_.set(create_post_process_pipeline_simple(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, passthrough_shader_wgsl));
}
-void PassthroughEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Passthrough::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Get input/output views
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -44,7 +32,7 @@ void PassthroughEffect::render(WGPUCommandEncoder encoder,
// Manually create bind group with only 3 entries (no effect params needed)
WGPUBindGroupEntry entries[3] = {};
entries[0].binding = PP_BINDING_SAMPLER;
- entries[0].sampler = sampler_;
+ entries[0].sampler = sampler_.get();
entries[1].binding = PP_BINDING_TEXTURE;
entries[1].textureView = input_view;
entries[2].binding = PP_BINDING_UNIFORMS;
@@ -52,32 +40,25 @@ void PassthroughEffect::render(WGPUCommandEncoder encoder,
entries[2].size = sizeof(UniformsSequenceParams);
WGPUBindGroupDescriptor bg_desc = {};
- bg_desc.layout = wgpuRenderPipelineGetBindGroupLayout(pipeline_, 0);
+ bg_desc.layout = wgpuRenderPipelineGetBindGroupLayout(pipeline_.get(), 0);
bg_desc.entryCount = 3;
bg_desc.entries = entries;
- if (bind_group_) {
- wgpuBindGroupRelease(bind_group_);
- }
- bind_group_ = wgpuDeviceCreateBindGroup(ctx_.device, &bg_desc);
+ bind_group_.replace(wgpuDeviceCreateBindGroup(ctx_.device, &bg_desc));
// Render pass
- WGPURenderPassColorAttachment color_attachment = {
- .view = output_view,
- .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
- .storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}
- };
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
- wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
- wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ wgpuRenderPassEncoderSetPipeline(pass, pipeline_.get());
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_.get(), 0, nullptr);
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle
wgpuRenderPassEncoderEnd(pass);
wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/passthrough_effect.h b/src/effects/passthrough_effect.h
index 125ac5a..1c60e02 100644
--- a/src/effects/passthrough_effect.h
+++ b/src/effects/passthrough_effect.h
@@ -4,18 +4,18 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
+#include "gpu/wgpu_resource.h"
-class PassthroughEffect : public Effect {
+class Passthrough : public Effect {
public:
- PassthroughEffect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
+ Passthrough(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
- WGPURenderPipeline pipeline_;
- WGPUBindGroup bind_group_;
- WGPUSampler sampler_;
- UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
+ RenderPipeline pipeline_;
+ BindGroup bind_group_;
};
diff --git a/src/effects/peak_meter_effect.cc b/src/effects/peak_meter_effect.cc
index 692d851..d077302 100644
--- a/src/effects/peak_meter_effect.cc
+++ b/src/effects/peak_meter_effect.cc
@@ -5,13 +5,14 @@
#include "gpu/shader_composer.h"
#include "util/fatal_error.h"
-PeakMeterEffect::PeakMeterEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr) {
+PeakMeter::PeakMeter(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), pipeline_(nullptr), bind_group_(nullptr) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
- uniforms_buffer_.init(ctx_.device);
+ init_uniforms_buffer();
const char* shader_main = R"(
struct VertexOutput {
@@ -58,19 +59,20 @@ PeakMeterEffect::PeakMeterEffect(const GpuContext& ctx,
std::string shader_code =
ShaderComposer::Get().Compose({"common_uniforms"}, shader_main);
- pipeline_ = create_post_process_pipeline(ctx_.device,
- WGPUTextureFormat_RGBA8Unorm,
- shader_code.c_str());
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, shader_code.c_str());
}
-PeakMeterEffect::~PeakMeterEffect() {
- if (bind_group_) wgpuBindGroupRelease(bind_group_);
- if (pipeline_) wgpuRenderPipelineRelease(pipeline_);
+PeakMeter::~PeakMeter() {
+ if (bind_group_)
+ wgpuBindGroupRelease(bind_group_);
+ if (pipeline_)
+ wgpuRenderPipelineRelease(pipeline_);
}
-void PeakMeterEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void PeakMeter::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -79,17 +81,15 @@ void PeakMeterEffect::render(WGPUCommandEncoder encoder,
uniforms_buffer_.get(), {nullptr, 0});
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
+ gpu_init_color_attachment(color_attachment, output_view);
color_attachment.loadOp = WGPULoadOp_Load;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
diff --git a/src/effects/peak_meter_effect.h b/src/effects/peak_meter_effect.h
index 905bcda..1786522 100644
--- a/src/effects/peak_meter_effect.h
+++ b/src/effects/peak_meter_effect.h
@@ -5,19 +5,17 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-class PeakMeterEffect : public Effect {
+class PeakMeter : public Effect {
public:
- PeakMeterEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~PeakMeterEffect() override;
+ PeakMeter(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~PeakMeter() override;
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
WGPURenderPipeline pipeline_;
WGPUBindGroup bind_group_;
- UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
};
diff --git a/src/effects/placeholder_effect.cc b/src/effects/placeholder_effect.cc
index d8852da..e024a6b 100644
--- a/src/effects/placeholder_effect.cc
+++ b/src/effects/placeholder_effect.cc
@@ -1,41 +1,32 @@
-// Placeholder effect v2 implementation - logs TODO warning once
+// Placeholder effect implementation - logs TODO warning once
#include "effects/placeholder_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
#include <cstdio>
-PlaceholderEffect::PlaceholderEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs,
- const char* placeholder_name)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
- sampler_(nullptr), name_(placeholder_name) {
- // Log once on construction
- fprintf(stderr, "TODO: %s not yet ported to v2, using passthrough\n", name_);
+Placeholder::Placeholder(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs,
+ float start_time, float end_time,
+ const char* placeholder_name)
+ : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr),
+ bind_group_(nullptr), name_(placeholder_name) {
+ fprintf(stderr, "TODO: %s not yet implemented, using passthrough\n", name_);
- // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
- uniforms_buffer_.init(ctx_.device);
- pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- passthrough_v2_shader_wgsl);
+ init_uniforms_buffer();
+ create_linear_sampler();
- WGPUSamplerDescriptor sampler_desc = {};
- sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
- sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
- sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
- sampler_desc.magFilter = WGPUFilterMode_Linear;
- sampler_desc.minFilter = WGPUFilterMode_Linear;
- sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Nearest;
- sampler_desc.maxAnisotropy = 1;
- sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, passthrough_shader_wgsl);
}
-void PlaceholderEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Placeholder::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -44,19 +35,15 @@ void PlaceholderEffect::render(WGPUCommandEncoder encoder,
pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view,
uniforms_buffer_.get(), {nullptr, 0});
- WGPURenderPassColorAttachment color_attachment = {
- .view = output_view,
- .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
- .storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}
- };
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
diff --git a/src/effects/placeholder_effect.h b/src/effects/placeholder_effect.h
index f7917ab..72b156f 100644
--- a/src/effects/placeholder_effect.h
+++ b/src/effects/placeholder_effect.h
@@ -6,11 +6,11 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-class PlaceholderEffect : public Effect {
+class Placeholder : public Effect {
public:
- PlaceholderEffect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs,
- const char* placeholder_name = "UnknownEffect");
+ Placeholder(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time, const char* placeholder_name = "UnknownEffect");
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
@@ -18,8 +18,5 @@ class PlaceholderEffect : public Effect {
private:
WGPURenderPipeline pipeline_;
WGPUBindGroup bind_group_;
- WGPUSampler sampler_;
- UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
const char* name_;
};
-
diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc
index 57f0a83..6c350a7 100644
--- a/src/effects/rotating_cube_effect.cc
+++ b/src/effects/rotating_cube_effect.cc
@@ -1,16 +1,17 @@
// This file is part of the 64k demo project.
-// It implements RotatingCubeEffect (simplified v2 port).
+// It implements RotatingCube.
-#include "util/fatal_error.h"
#include "effects/rotating_cube_effect.h"
+#include "effects/shaders.h"
#include "gpu/bind_group_builder.h"
#include "gpu/gpu.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), depth_node_(outputs[0] + "_depth") {
+RotatingCube::RotatingCube(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") {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
@@ -39,10 +40,10 @@ RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx,
WGPUPipelineLayout pipeline_layout =
wgpuDeviceCreatePipelineLayout(ctx_.device, &pl_desc);
- // Load shader (TODO: create rotating_cube_v2.wgsl)
+ // Load shader
WGPUShaderSourceWGSL wgsl_src = {};
wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
- wgsl_src.code = str_view(rotating_cube_v2_wgsl);
+ wgsl_src.code = str_view(rotating_cube_wgsl);
WGPUShaderModuleDescriptor shader_desc = {};
shader_desc.nextInChain = &wgsl_src.chain;
@@ -100,21 +101,21 @@ RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx,
wgpuBindGroupLayoutRelease(bgl);
}
-RotatingCubeEffect::~RotatingCubeEffect() {
+RotatingCube::~RotatingCube() {
if (bind_group_)
wgpuBindGroupRelease(bind_group_);
if (pipeline_)
wgpuRenderPipelineRelease(pipeline_);
}
-void RotatingCubeEffect::declare_nodes(NodeRegistry& registry) {
+void RotatingCube::declare_nodes(NodeRegistry& registry) {
// Declare depth buffer node
registry.declare_node(depth_node_, NodeType::DEPTH24, -1, -1);
}
-void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void RotatingCube::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
rotation_ += 0.016f * 1.5f;
// Camera setup
@@ -138,7 +139,8 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
const Uniforms uniforms = {
.view_proj = view_proj,
.inv_view_proj = view_proj.inverse(),
- .camera_pos_time = vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time),
+ .camera_pos_time =
+ vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time),
.params = vec4(1.0f, 0.0f, 0.0f, 0.0f),
.resolution = params.resolution,
.aspect_ratio = params.aspect_ratio,
@@ -156,6 +158,22 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
wgpuQueueWriteBuffer(ctx_.queue, object_buffer_.buffer, 0, &obj_data,
sizeof(ObjectData));
+ // Blit input to output if compositing (not reading from source)
+ if (!input_nodes_.empty() && input_nodes_[0] != "source") {
+ WGPUTexture input_tex = nodes.get_texture(input_nodes_[0]);
+ WGPUTexture output_tex = nodes.get_texture(output_nodes_[0]);
+ if (input_tex && output_tex) {
+ GpuTextureCopyInfo src = {
+ .texture = input_tex, .mipLevel = 0, .aspect = WGPUTextureAspect_All};
+ GpuTextureCopyInfo dst = {.texture = output_tex,
+ .mipLevel = 0,
+ .aspect = WGPUTextureAspect_All};
+ WGPUExtent3D copy_size = {(uint32_t)params.resolution.x,
+ (uint32_t)params.resolution.y, 1};
+ wgpuCommandEncoderCopyTextureToTexture(encoder, &src, &dst, &copy_size);
+ }
+ }
+
// Get output views
WGPUTextureView color_view = nodes.get_view(output_nodes_[0]);
WGPUTextureView depth_view = nodes.get_view(depth_node_);
@@ -163,10 +181,13 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
// Render pass with depth
WGPURenderPassColorAttachment color_attachment = {
.view = color_view,
+ #if !defined(DEMO_CROSS_COMPILE_WIN32)
.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
+#endif
+ // .loadOp = WGPULoadOp_Clear,
+ .loadOp = WGPULoadOp_Load,
.storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}};
+ .clearValue = {0.0, 0.0, 0.0, 0.0}};
WGPURenderPassDepthStencilAttachment depth_attachment = {
.view = depth_view,
@@ -174,15 +195,16 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
.depthStoreOp = WGPUStoreOp_Discard,
.depthClearValue = 1.0f};
- WGPURenderPassDescriptor pass_desc = {
- .colorAttachmentCount = 1,
- .colorAttachments = &color_attachment,
- .depthStencilAttachment = &depth_attachment};
+ WGPURenderPassDescriptor pass_desc = {.colorAttachmentCount = 1,
+ .colorAttachments = &color_attachment,
+ .depthStencilAttachment =
+ &depth_attachment};
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 36, 1, 0, 0); // 36 vertices for cube
+ wgpuRenderPassEncoderDraw(pass, 36, 1, 0, 0); // 36 vertices for cube
wgpuRenderPassEncoderEnd(pass);
wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/rotating_cube_effect.h b/src/effects/rotating_cube_effect.h
index 1c0155a..e773025 100644
--- a/src/effects/rotating_cube_effect.h
+++ b/src/effects/rotating_cube_effect.h
@@ -8,16 +8,15 @@
#include "gpu/uniform_helper.h"
#include "util/mini_math.h"
-class RotatingCubeEffect : public Effect {
+class RotatingCube : public Effect {
public:
- RotatingCubeEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~RotatingCubeEffect() override;
+ RotatingCube(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~RotatingCube() override;
void declare_nodes(NodeRegistry& registry) override;
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
diff --git a/src/effects/shaders.cc b/src/effects/shaders.cc
new file mode 100644
index 0000000..d181632
--- /dev/null
+++ b/src/effects/shaders.cc
@@ -0,0 +1,108 @@
+// This file is part of the 64k demo project.
+// It defines WGSL shader code for various effects.
+
+#include "effects/shaders.h"
+#include "gpu/shader_composer.h"
+#include "util/asset_manager.h"
+
+#if defined(USE_TEST_ASSETS)
+#include "test_assets.h"
+#else
+#include "generated/assets.h"
+#endif
+
+void InitShaderComposer() {
+ auto& sc = ShaderComposer::Get();
+
+ auto register_if_exists = [&](const char* name, AssetId id) {
+ size_t size;
+
+ const char* data = (const char*)GetAsset(id, &size);
+
+ if (data) {
+ sc.RegisterSnippet(name, std::string(data, size));
+ }
+ };
+
+ register_if_exists("common_uniforms", AssetId::ASSET_SHADER_COMMON_UNIFORMS);
+ register_if_exists("sequence_uniforms",
+ AssetId::ASSET_SHADER_SEQUENCE_V2_UNIFORMS);
+ register_if_exists("postprocess_inline",
+ AssetId::ASSET_SHADER_POSTPROCESS_INLINE);
+ // register_if_exists("camera_common", AssetId::ASSET_SHADER_CAMERA_COMMON);
+ register_if_exists("math/sdf_shapes", AssetId::ASSET_SHADER_MATH_SDF_SHAPES);
+ register_if_exists("math/sdf_utils", AssetId::ASSET_SHADER_MATH_SDF_UTILS);
+ register_if_exists("math/common_utils",
+ AssetId::ASSET_SHADER_MATH_COMMON_UTILS);
+ register_if_exists("math/noise", AssetId::ASSET_SHADER_MATH_NOISE);
+ register_if_exists("render/shadows", AssetId::ASSET_SHADER_RENDER_SHADOWS);
+ register_if_exists("render/scene_query_bvh",
+ AssetId::ASSET_SHADER_RENDER_SCENE_QUERY_BVH);
+ register_if_exists("render/scene_query_linear",
+ AssetId::ASSET_SHADER_RENDER_SCENE_QUERY_LINEAR);
+ register_if_exists("render/lighting_utils",
+ AssetId::ASSET_SHADER_RENDER_LIGHTING_UTILS);
+ register_if_exists("render/mesh", AssetId::ASSET_SHADER_MESH);
+
+ register_if_exists("math/sdf_shapes", AssetId::ASSET_SHADER_SDF_SHAPES);
+
+ register_if_exists("lighting", AssetId::ASSET_SHADER_LIGHTING);
+
+ register_if_exists("ray_box", AssetId::ASSET_SHADER_RAY_BOX);
+ register_if_exists("ray_triangle", AssetId::ASSET_SHADER_RAY_TRIANGLE);
+
+ register_if_exists("render/fullscreen_vs",
+ AssetId::ASSET_SHADER_RENDER_FULLSCREEN_VS);
+ register_if_exists("math/color", AssetId::ASSET_SHADER_MATH_COLOR);
+ register_if_exists("math/utils", AssetId::ASSET_SHADER_MATH_UTILS);
+ register_if_exists("render/raymarching",
+ AssetId::ASSET_SHADER_RENDER_RAYMARCHING);
+
+ // CNN shaders (workspace-specific)
+ // register_if_exists("cnn_activation", AssetId::ASSET_SHADER_CNN_ACTIVATION);
+ // register_if_exists("cnn_conv1x1", AssetId::ASSET_SHADER_CNN_CONV1X1);
+ // register_if_exists("cnn_conv3x3", AssetId::ASSET_SHADER_CNN_CONV3X3);
+ // register_if_exists("cnn_conv5x5", AssetId::ASSET_SHADER_CNN_CONV5X5);
+ // register_if_exists("cnn_conv7x7", AssetId::ASSET_SHADER_CNN_CONV7X7);
+ // register_if_exists("cnn_weights_generated",
+ // AssetId::ASSET_SHADER_CNN_WEIGHTS);
+
+#if !defined(STRIP_ALL)
+ sc.VerifyIncludes();
+#endif
+}
+
+// Helper to get asset string or empty string
+static const char* SafeGetAsset(AssetId id) {
+ const uint8_t* data = GetAsset(id);
+ return data ? (const char*)data : "";
+}
+
+// Effect shaders
+const char* passthrough_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_PASSTHROUGH_V2);
+const char* gaussian_blur_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR_V2);
+const char* heptagon_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_HEPTAGON_V2);
+const char* particle_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE);
+const char* particle_render_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER);
+const char* rotating_cube_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_ROTATING_CUBE_V2);
+const char* flash_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_FLASH);
+
+// Compute shaders
+const char* gen_noise_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_NOISE);
+const char* gen_perlin_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_PERLIN);
+const char* gen_grid_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_GRID);
+#if !defined(STRIP_GPU_COMPOSITE)
+const char* gen_blend_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_BLEND);
+const char* gen_mask_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_MASK);
+#endif
diff --git a/src/effects/shaders.h b/src/effects/shaders.h
new file mode 100644
index 0000000..b8700f5
--- /dev/null
+++ b/src/effects/shaders.h
@@ -0,0 +1,25 @@
+// This file is part of the 64k demo project.
+// It declares the WGSL shader strings and initialization function.
+
+#pragma once
+
+// Initializes the ShaderComposer with snippet assets.
+void InitShaderComposer();
+
+// Effect shaders
+extern const char* passthrough_shader_wgsl;
+extern const char* gaussian_blur_shader_wgsl;
+extern const char* heptagon_shader_wgsl;
+extern const char* particle_compute_wgsl;
+extern const char* particle_render_wgsl;
+extern const char* rotating_cube_wgsl;
+extern const char* flash_shader_wgsl;
+
+// Compute shaders
+extern const char* gen_noise_compute_wgsl;
+extern const char* gen_perlin_compute_wgsl;
+extern const char* gen_grid_compute_wgsl;
+#if !defined(STRIP_GPU_COMPOSITE)
+extern const char* gen_blend_compute_wgsl;
+extern const char* gen_mask_compute_wgsl;
+#endif