summaryrefslogtreecommitdiff
path: root/src/effects/gaussian_blur_effect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects/gaussian_blur_effect.cc')
-rw-r--r--src/effects/gaussian_blur_effect.cc54
1 files changed, 20 insertions, 34 deletions
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);