summaryrefslogtreecommitdiff
path: root/src/effects
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/scratch.wgsl14
-rw-r--r--src/effects/scratch_effect.cc44
-rw-r--r--src/effects/scratch_effect.h20
-rw-r--r--src/effects/shaders.cc3
-rw-r--r--src/effects/shaders.h1
5 files changed, 82 insertions, 0 deletions
diff --git a/src/effects/scratch.wgsl b/src/effects/scratch.wgsl
new file mode 100644
index 0000000..818202e
--- /dev/null
+++ b/src/effects/scratch.wgsl
@@ -0,0 +1,14 @@
+// Scratch effect - overlays film scratch lines on top of the input buffer
+#include "sequence_uniforms"
+#include "render/fullscreen_uv_vs"
+#include "render/scratch_lines"
+
+@group(0) @binding(0) var input_sampler: sampler;
+@group(0) @binding(1) var input_texture: texture_2d<f32>;
+@group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams;
+
+@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f {
+ let color = textureSample(input_texture, input_sampler, in.uv);
+ let s = scratch_lines(in.uv, uniforms.resolution, uniforms.time);
+ return vec4f(color.rgb + vec3f(s), color.a);
+}
diff --git a/src/effects/scratch_effect.cc b/src/effects/scratch_effect.cc
new file mode 100644
index 0000000..f49e601
--- /dev/null
+++ b/src/effects/scratch_effect.cc
@@ -0,0 +1,44 @@
+// Scratch effect - film scratch overlay post-process
+
+#include "effects/scratch_effect.h"
+#include "effects/shaders.h"
+#include "gpu/post_process_helper.h"
+#include "util/fatal_error.h"
+
+Scratch::Scratch(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);
+
+ create_linear_sampler();
+
+ pipeline_.set(create_post_process_pipeline(ctx_.device,
+ WGPUTextureFormat_RGBA8Unorm,
+ scratch_shader_wgsl));
+}
+
+void Scratch::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]);
+
+ pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(),
+ input_view, uniforms_buffer_.get(), {nullptr, 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_.get());
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_.get(), 0, nullptr);
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
+ wgpuRenderPassEncoderEnd(pass);
+ wgpuRenderPassEncoderRelease(pass);
+}
diff --git a/src/effects/scratch_effect.h b/src/effects/scratch_effect.h
new file mode 100644
index 0000000..fb36a96
--- /dev/null
+++ b/src/effects/scratch_effect.h
@@ -0,0 +1,20 @@
+// Scratch effect - film scratch overlay post-process
+// Reads input buffer, additively blends scratch_lines() on top.
+
+#pragma once
+#include "gpu/effect.h"
+#include "gpu/wgpu_resource.h"
+
+class Scratch : public Effect {
+ public:
+ Scratch(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:
+ RenderPipeline pipeline_;
+ BindGroup bind_group_;
+};
diff --git a/src/effects/shaders.cc b/src/effects/shaders.cc
index c6a81d0..e4b9b25 100644
--- a/src/effects/shaders.cc
+++ b/src/effects/shaders.cc
@@ -51,6 +51,8 @@ void InitShaderComposer() {
register_if_exists("ray_box", AssetId::ASSET_SHADER_RAY_BOX);
register_if_exists("ray_triangle", AssetId::ASSET_SHADER_RAY_TRIANGLE);
+ register_if_exists("render/scratch_lines",
+ AssetId::ASSET_SHADER_RENDER_SCRATCH_LINES);
register_if_exists("render/fullscreen_vs",
AssetId::ASSET_SHADER_RENDER_FULLSCREEN_VS);
register_if_exists("render/fullscreen_uv_vs",
@@ -97,6 +99,7 @@ const char* rotating_cube_wgsl =
const char* flash_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_FLASH);
const char* scene1_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_SCENE1);
const char* scene2_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_SCENE2);
+const char* scratch_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_SCRATCH);
// Compute shaders
const char* gen_noise_compute_wgsl =
diff --git a/src/effects/shaders.h b/src/effects/shaders.h
index 5fc442a..76b5d96 100644
--- a/src/effects/shaders.h
+++ b/src/effects/shaders.h
@@ -16,6 +16,7 @@ extern const char* rotating_cube_wgsl;
extern const char* flash_shader_wgsl;
extern const char* scene1_shader_wgsl;
extern const char* scene2_shader_wgsl;
+extern const char* scratch_shader_wgsl;
// Compute shaders
extern const char* gen_noise_compute_wgsl;