summaryrefslogtreecommitdiff
path: root/src/gpu/effects/fade_effect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/effects/fade_effect.cc')
-rw-r--r--src/gpu/effects/fade_effect.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/gpu/effects/fade_effect.cc b/src/gpu/effects/fade_effect.cc
index 3efc583..39b54e0 100644
--- a/src/gpu/effects/fade_effect.cc
+++ b/src/gpu/effects/fade_effect.cc
@@ -5,6 +5,12 @@
#include "gpu/effects/post_process_helper.h"
#include <cmath>
+struct FadeParams {
+ float fade_amount;
+ float _pad[3];
+};
+static_assert(sizeof(FadeParams) == 16, "FadeParams must be 16 bytes for WGSL alignment");
+
FadeEffect::FadeEffect(const GpuContext& ctx) : PostProcessEffect(ctx) {
const char* shader_code = R"(
struct VertexOutput {
@@ -22,7 +28,7 @@ FadeEffect::FadeEffect(const GpuContext& ctx) : PostProcessEffect(ctx) {
audio_intensity: f32,
};
- struct EffectParams {
+ struct FadeParams {
fade_amount: f32,
_pad0: f32,
_pad1: f32,
@@ -32,7 +38,7 @@ FadeEffect::FadeEffect(const GpuContext& ctx) : PostProcessEffect(ctx) {
@group(0) @binding(0) var inputSampler: sampler;
@group(0) @binding(1) var inputTexture: texture_2d<f32>;
@group(0) @binding(2) var<uniform> uniforms: CommonUniforms;
- @group(0) @binding(3) var<uniform> params: EffectParams;
+ @group(0) @binding(3) var<uniform> params: FadeParams;
@vertex
fn vs_main(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {
@@ -57,14 +63,13 @@ FadeEffect::FadeEffect(const GpuContext& ctx) : PostProcessEffect(ctx) {
pipeline_ =
create_post_process_pipeline(ctx_.device, ctx_.format, shader_code);
- common_uniforms_.init(ctx_.device);
params_buffer_ = gpu_create_buffer(
ctx_.device, 16, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst);
}
void FadeEffect::update_bind_group(WGPUTextureView input_view) {
pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view,
- common_uniforms_.get(), params_buffer_);
+ uniforms_.get(), params_buffer_);
}
void FadeEffect::render(WGPURenderPassEncoder pass, float time, float beat,
@@ -76,7 +81,7 @@ void FadeEffect::render(WGPURenderPassEncoder pass, float time, float beat,
.beat = beat,
.audio_intensity = intensity,
};
- common_uniforms_.update(ctx_.queue, u);
+ uniforms_.update(ctx_.queue, u);
// Example fade pattern: fade in at start, fade out at end
// Customize this based on your needs
@@ -90,8 +95,8 @@ void FadeEffect::render(WGPURenderPassEncoder pass, float time, float beat,
fade_amount = fmaxf(fade_amount, 0.0f);
}
- float params[4] = {fade_amount, 0.0f, 0.0f, 0.0f};
- wgpuQueueWriteBuffer(ctx_.queue, params_buffer_.buffer, 0, params,
+ FadeParams params = {fade_amount, {0.0f, 0.0f, 0.0f}};
+ wgpuQueueWriteBuffer(ctx_.queue, params_buffer_.buffer, 0, &params,
sizeof(params));
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);