diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gpu/demo_effects.h | 44 | ||||
| -rw-r--r-- | src/gpu/effect.h | 5 | ||||
| -rw-r--r-- | src/gpu/effects/chroma_aberration_effect.cc | 1 | ||||
| -rw-r--r-- | src/gpu/effects/circle_mask_effect.cc | 10 | ||||
| -rw-r--r-- | src/gpu/effects/circle_mask_effect.h | 2 | ||||
| -rw-r--r-- | src/gpu/effects/distort_effect.cc | 11 | ||||
| -rw-r--r-- | src/gpu/effects/fade_effect.cc | 5 | ||||
| -rw-r--r-- | src/gpu/effects/fade_effect.h | 1 | ||||
| -rw-r--r-- | src/gpu/effects/flash_cube_effect.h | 2 | ||||
| -rw-r--r-- | src/gpu/effects/gaussian_blur_effect.cc | 1 | ||||
| -rw-r--r-- | src/gpu/effects/heptagon_effect.cc | 24 | ||||
| -rw-r--r-- | src/gpu/effects/moving_ellipse_effect.cc | 9 | ||||
| -rw-r--r-- | src/gpu/effects/particle_spray_effect.cc | 1 | ||||
| -rw-r--r-- | src/gpu/effects/particles_effect.cc | 1 | ||||
| -rw-r--r-- | src/gpu/effects/passthrough_effect.cc | 1 | ||||
| -rw-r--r-- | src/gpu/effects/solarize_effect.cc | 1 | ||||
| -rw-r--r-- | src/gpu/effects/theme_modulation_effect.cc | 5 | ||||
| -rw-r--r-- | src/gpu/effects/theme_modulation_effect.h | 1 | ||||
| -rw-r--r-- | src/gpu/effects/vignette_effect.cc | 1 |
19 files changed, 27 insertions, 99 deletions
diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h index 1bd6020..ff7e017 100644 --- a/src/gpu/demo_effects.h +++ b/src/gpu/demo_effects.h @@ -13,6 +13,8 @@ #include "gpu/effects/rotating_cube_effect.h" #include "gpu/effects/shaders.h" #include "gpu/effects/theme_modulation_effect.h" // ThemeModulationEffect with full definition +#include "gpu/effects/hybrid_3d_effect.h" +#include "gpu/effects/flash_cube_effect.h" #include "gpu/gpu.h" #include "gpu/texture_manager.h" #include "gpu/uniform_helper.h" @@ -49,7 +51,6 @@ class ParticlesEffect : public Effect { ComputePass compute_pass_; RenderPass render_pass_; GpuBuffer particles_buffer_; - UniformBuffer<CommonPostProcessUniforms> uniforms_; }; class PassthroughEffect : public PostProcessEffect { @@ -58,7 +59,6 @@ class PassthroughEffect : public PostProcessEffect { void update_bind_group(WGPUTextureView input_view) override; private: - UniformBuffer<CommonPostProcessUniforms> uniforms_; }; class MovingEllipseEffect : public Effect { @@ -83,7 +83,6 @@ class ParticleSprayEffect : public Effect { ComputePass compute_pass_; RenderPass render_pass_; GpuBuffer particles_buffer_; - UniformBuffer<CommonPostProcessUniforms> uniforms_; }; // Parameters for GaussianBlurEffect (set at construction time) @@ -106,7 +105,6 @@ class GaussianBlurEffect : public PostProcessEffect { private: GaussianBlurParams params_; - UniformBuffer<CommonPostProcessUniforms> uniforms_; UniformBuffer<GaussianBlurParams> params_buffer_; }; @@ -118,7 +116,6 @@ class SolarizeEffect : public PostProcessEffect { void update_bind_group(WGPUTextureView input_view) override; private: - UniformBuffer<CommonPostProcessUniforms> uniforms_; }; // Parameters for VignetteEffect @@ -137,7 +134,6 @@ class VignetteEffect : public PostProcessEffect { private: VignetteParams params_; - UniformBuffer<CommonPostProcessUniforms> uniforms_; UniformBuffer<VignetteParams> params_buffer_; }; @@ -160,26 +156,9 @@ class ChromaAberrationEffect : public PostProcessEffect { private: ChromaAberrationParams params_; - UniformBuffer<CommonPostProcessUniforms> uniforms_; UniformBuffer<ChromaAberrationParams> params_buffer_; }; -class Hybrid3DEffect : public Effect { - public: - Hybrid3DEffect(const GpuContext& ctx); - void init(MainSequence* demo) override; - void render(WGPURenderPassEncoder pass, float time, float beat, - float intensity, float aspect_ratio) override; - - private: - Renderer3D renderer_; - TextureManager texture_manager_; - Scene scene_; - Camera camera_; - int width_ = 1280; - int height_ = 720; -}; - // Parameters for DistortEffect struct DistortParams { float strength = 0.01f; // Default distortion strength @@ -197,27 +176,8 @@ class DistortEffect : public PostProcessEffect { private: DistortParams params_; - UniformBuffer<CommonPostProcessUniforms> common_uniforms_; UniformBuffer<DistortParams> params_buffer_; }; -class FlashCubeEffect : public Effect { - public: - FlashCubeEffect(const GpuContext& ctx); - void init(MainSequence* demo) override; - void resize(int width, int height) override; - void render(WGPURenderPassEncoder pass, float time, float beat, - float intensity, float aspect_ratio) override; - - private: - Renderer3D renderer_; - TextureManager texture_manager_; - Scene scene_; - Camera camera_; - int width_ = 1280; - int height_ = 720; - float last_beat_; - float flash_intensity_; -}; // ThemeModulationEffect now defined in gpu/effects/theme_modulation_effect.h // (included above) FadeEffect now defined in gpu/effects/fade_effect.h diff --git a/src/gpu/effect.h b/src/gpu/effect.h index 6fdb0f4..8f35f3c 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -1,5 +1,7 @@ #pragma once #include "gpu/gpu.h" +#include "gpu/effects/post_process_helper.h" +#include "gpu/uniform_helper.h" #include <algorithm> #include <map> #include <memory> @@ -12,6 +14,7 @@ class PostProcessEffect; class Effect { public: Effect(const GpuContext& ctx) : ctx_(ctx) { + uniforms_.init(ctx.device); } virtual ~Effect() = default; virtual void init(MainSequence* demo) { @@ -43,7 +46,7 @@ class Effect { protected: const GpuContext& ctx_; - GpuBuffer uniforms_; + UniformBuffer<CommonPostProcessUniforms> uniforms_; int width_ = 1280; int height_ = 720; }; diff --git a/src/gpu/effects/chroma_aberration_effect.cc b/src/gpu/effects/chroma_aberration_effect.cc index 7f41153..af3acc5 100644 --- a/src/gpu/effects/chroma_aberration_effect.cc +++ b/src/gpu/effects/chroma_aberration_effect.cc @@ -18,7 +18,6 @@ ChromaAberrationEffect::ChromaAberrationEffect( : PostProcessEffect(ctx), params_(params) { pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, chroma_aberration_shader_wgsl); - uniforms_.init(ctx_.device); params_buffer_.init(ctx_.device); } diff --git a/src/gpu/effects/circle_mask_effect.cc b/src/gpu/effects/circle_mask_effect.cc index 2368631..720b6ea 100644 --- a/src/gpu/effects/circle_mask_effect.cc +++ b/src/gpu/effects/circle_mask_effect.cc @@ -30,9 +30,7 @@ void CircleMaskEffect::init(MainSequence* demo) { demo_->register_auxiliary_texture("circle_mask", width, height); - compute_uniforms_.init(ctx_.device); compute_params_.init(ctx_.device); - render_uniforms_.init(ctx_.device); WGPUSamplerDescriptor sampler_desc = {}; sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge; @@ -82,7 +80,7 @@ void CircleMaskEffect::init(MainSequence* demo) { const WGPUBindGroupEntry compute_entries[] = { {.binding = 0, - .buffer = compute_uniforms_.get().buffer, + .buffer = uniforms_.get().buffer, .size = sizeof(CommonPostProcessUniforms)}, {.binding = 1, .buffer = compute_params_.get().buffer, @@ -139,7 +137,7 @@ void CircleMaskEffect::init(MainSequence* demo) { {.binding = 0, .textureView = mask_view}, {.binding = 1, .sampler = mask_sampler_}, {.binding = 2, - .buffer = render_uniforms_.get().buffer, + .buffer = uniforms_.get().buffer, .size = sizeof(CommonPostProcessUniforms)}, }; const WGPUBindGroupDescriptor render_bg_desc = { @@ -160,7 +158,7 @@ void CircleMaskEffect::compute(WGPUCommandEncoder encoder, float time, .beat = beat, .audio_intensity = intensity, }; - compute_uniforms_.update(ctx_.queue, uniforms); + uniforms_.update(ctx_.queue, uniforms); const CircleMaskParams params = { .radius = radius_, @@ -199,7 +197,7 @@ void CircleMaskEffect::render(WGPURenderPassEncoder pass, float time, .beat = beat, .audio_intensity = intensity, }; - render_uniforms_.update(ctx_.queue, uniforms); + uniforms_.update(ctx_.queue, uniforms); wgpuRenderPassEncoderSetPipeline(pass, render_pipeline_); wgpuRenderPassEncoderSetBindGroup(pass, 0, render_bind_group_, 0, nullptr); diff --git a/src/gpu/effects/circle_mask_effect.h b/src/gpu/effects/circle_mask_effect.h index bf9cdfb..2ddbb11 100644 --- a/src/gpu/effects/circle_mask_effect.h +++ b/src/gpu/effects/circle_mask_effect.h @@ -33,13 +33,11 @@ class CircleMaskEffect : public Effect { WGPURenderPipeline compute_pipeline_ = nullptr; WGPUBindGroup compute_bind_group_ = nullptr; - UniformBuffer<CommonPostProcessUniforms> compute_uniforms_; UniformBuffer<CircleMaskParams> compute_params_; WGPURenderPipeline render_pipeline_ = nullptr; WGPUBindGroup render_bind_group_ = nullptr; WGPUSampler mask_sampler_ = nullptr; - UniformBuffer<CommonPostProcessUniforms> render_uniforms_; }; #endif /* CIRCLE_MASK_EFFECT_H_ */ diff --git a/src/gpu/effects/distort_effect.cc b/src/gpu/effects/distort_effect.cc index b5acf83..52a8ec7 100644 --- a/src/gpu/effects/distort_effect.cc +++ b/src/gpu/effects/distort_effect.cc @@ -9,9 +9,8 @@ DistortEffect::DistortEffect(const GpuContext& ctx) : DistortEffect(ctx, DistortParams()) { } -DistortEffect::DistEffect(const GpuContext& ctx, const DistortParams& params) +DistortEffect::DistortEffect(const GpuContext& ctx, const DistortParams& params) : PostProcessEffect(ctx), params_(params) { - common_uniforms_.init(ctx_.device); params_buffer_.init(ctx_.device); pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, distort_shader_wgsl); @@ -27,7 +26,7 @@ void DistortEffect::render(WGPURenderPassEncoder pass, float t, float b, .beat = b, .audio_intensity = i, }; - common_uniforms_.update(ctx_.queue, common_u); + uniforms_.update(ctx_.queue, common_u); // Populate DistortParams const DistortParams distort_p = { @@ -40,7 +39,5 @@ void DistortEffect::render(WGPURenderPassEncoder pass, float t, float b, } void DistortEffect::update_bind_group(WGPUTextureView v) { - - pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, v, common_uniforms_.get(), params_buffer_); - -} + pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, v, uniforms_.get(), params_buffer_); +}
\ No newline at end of file diff --git a/src/gpu/effects/fade_effect.cc b/src/gpu/effects/fade_effect.cc index 7730a2e..39b54e0 100644 --- a/src/gpu/effects/fade_effect.cc +++ b/src/gpu/effects/fade_effect.cc @@ -63,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, @@ -82,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 diff --git a/src/gpu/effects/fade_effect.h b/src/gpu/effects/fade_effect.h index 2e5a6a0..178c360 100644 --- a/src/gpu/effects/fade_effect.h +++ b/src/gpu/effects/fade_effect.h @@ -16,6 +16,5 @@ class FadeEffect : public PostProcessEffect { void update_bind_group(WGPUTextureView input_view) override; private: - UniformBuffer<CommonPostProcessUniforms> common_uniforms_; GpuBuffer params_buffer_; }; diff --git a/src/gpu/effects/flash_cube_effect.h b/src/gpu/effects/flash_cube_effect.h index 7089af2..5faeb00 100644 --- a/src/gpu/effects/flash_cube_effect.h +++ b/src/gpu/effects/flash_cube_effect.h @@ -22,8 +22,6 @@ class FlashCubeEffect : public Effect { TextureManager texture_manager_; Scene scene_; Camera camera_; - int width_ = 1280; - int height_ = 720; float last_beat_ = 0.0f; float flash_intensity_ = 0.0f; }; diff --git a/src/gpu/effects/gaussian_blur_effect.cc b/src/gpu/effects/gaussian_blur_effect.cc index 0cc4821..697be88 100644 --- a/src/gpu/effects/gaussian_blur_effect.cc +++ b/src/gpu/effects/gaussian_blur_effect.cc @@ -18,7 +18,6 @@ GaussianBlurEffect::GaussianBlurEffect(const GpuContext& ctx, : PostProcessEffect(ctx), params_(params) { pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, gaussian_blur_shader_wgsl); - uniforms_.init(ctx_.device); params_buffer_.init(ctx_.device); } diff --git a/src/gpu/effects/heptagon_effect.cc b/src/gpu/effects/heptagon_effect.cc index f7a30eb..7b0702d 100644 --- a/src/gpu/effects/heptagon_effect.cc +++ b/src/gpu/effects/heptagon_effect.cc @@ -5,39 +5,25 @@ #include "gpu/gpu.h" #include "util/mini_math.h" -// Match CommonUniforms struct from main_shader.wgsl. -// Padded to 32 bytes for WGSL alignment rules. -struct HeptagonUniforms { - vec2 resolution; // 8 bytes - float _pad0[2]; // 8 bytes padding to align next float - float aspect_ratio; // 4 bytes - float time; // 4 bytes - float beat; // 4 bytes - float audio_intensity; // 4 bytes -}; -static_assert(sizeof(HeptagonUniforms) == 32, - "HeptagonUniforms must be 32 bytes for WGSL alignment"); - // --- HeptagonEffect --- HeptagonEffect::HeptagonEffect(const GpuContext& ctx) : Effect(ctx) { - uniforms_ = - gpu_create_buffer(ctx_.device, sizeof(HeptagonUniforms), - WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); - ResourceBinding bindings[] = {{uniforms_, WGPUBufferBindingType_Uniform}}; + // uniforms_ is initialized by Effect base class + ResourceBinding bindings[] = {{uniforms_.get(), WGPUBufferBindingType_Uniform}}; pass_ = gpu_create_render_pass(ctx_.device, ctx_.format, main_shader_wgsl, bindings, 1); pass_.vertex_count = 21; } void HeptagonEffect::render(WGPURenderPassEncoder pass, float t, float b, float i, float a) { - HeptagonUniforms u = { + CommonPostProcessUniforms u = { .resolution = {(float)width_, (float)height_}, + ._pad = {0.0f, 0.0f}, .aspect_ratio = a, .time = t, .beat = b, .audio_intensity = i, }; - wgpuQueueWriteBuffer(ctx_.queue, uniforms_.buffer, 0, &u, sizeof(u)); + uniforms_.update(ctx_.queue, u); wgpuRenderPassEncoderSetPipeline(pass, pass_.pipeline); wgpuRenderPassEncoderSetBindGroup(pass, 0, pass_.bind_group, 0, nullptr); wgpuRenderPassEncoderDraw(pass, pass_.vertex_count, 1, 0, 0); diff --git a/src/gpu/effects/moving_ellipse_effect.cc b/src/gpu/effects/moving_ellipse_effect.cc index 945f807..9866f20 100644 --- a/src/gpu/effects/moving_ellipse_effect.cc +++ b/src/gpu/effects/moving_ellipse_effect.cc @@ -7,10 +7,8 @@ // --- MovingEllipseEffect --- MovingEllipseEffect::MovingEllipseEffect(const GpuContext& ctx) : Effect(ctx) { - uniforms_ = - gpu_create_buffer(ctx_.device, sizeof(CommonPostProcessUniforms), - WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); - ResourceBinding bindings[] = {{uniforms_, WGPUBufferBindingType_Uniform}}; + // uniforms_ is initialized by Effect base class + ResourceBinding bindings[] = {{uniforms_.get(), WGPUBufferBindingType_Uniform}}; pass_ = gpu_create_render_pass(ctx_.device, ctx_.format, ellipse_shader_wgsl, bindings, 1); pass_.vertex_count = 3; @@ -19,12 +17,13 @@ void MovingEllipseEffect::render(WGPURenderPassEncoder pass, float t, float b, float i, float a) { const CommonPostProcessUniforms u = { .resolution = {(float)width_, (float)height_}, + ._pad = {0.0f, 0.0f}, .aspect_ratio = a, .time = t, .beat = b, .audio_intensity = i, }; - wgpuQueueWriteBuffer(ctx_.queue, uniforms_.buffer, 0, &u, sizeof(u)); + uniforms_.update(ctx_.queue, u); wgpuRenderPassEncoderSetPipeline(pass, pass_.pipeline); wgpuRenderPassEncoderSetBindGroup(pass, 0, pass_.bind_group, 0, nullptr); wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); diff --git a/src/gpu/effects/particle_spray_effect.cc b/src/gpu/effects/particle_spray_effect.cc index 3fd2590..a435884 100644 --- a/src/gpu/effects/particle_spray_effect.cc +++ b/src/gpu/effects/particle_spray_effect.cc @@ -8,7 +8,6 @@ // --- ParticleSprayEffect --- ParticleSprayEffect::ParticleSprayEffect(const GpuContext& ctx) : Effect(ctx) { - uniforms_.init(ctx_.device); std::vector<Particle> init_p(NUM_PARTICLES); for (Particle& p : init_p) p.pos[3] = 0.0f; diff --git a/src/gpu/effects/particles_effect.cc b/src/gpu/effects/particles_effect.cc index 01f90a5..cd0df74 100644 --- a/src/gpu/effects/particles_effect.cc +++ b/src/gpu/effects/particles_effect.cc @@ -8,7 +8,6 @@ // --- ParticlesEffect --- ParticlesEffect::ParticlesEffect(const GpuContext& ctx) : Effect(ctx) { - uniforms_.init(ctx_.device); std::vector<Particle> init_p(NUM_PARTICLES); particles_buffer_ = gpu_create_buffer( ctx_.device, sizeof(Particle) * NUM_PARTICLES, diff --git a/src/gpu/effects/passthrough_effect.cc b/src/gpu/effects/passthrough_effect.cc index 93cf948..01d557a 100644 --- a/src/gpu/effects/passthrough_effect.cc +++ b/src/gpu/effects/passthrough_effect.cc @@ -7,7 +7,6 @@ // --- PassthroughEffect --- PassthroughEffect::PassthroughEffect(const GpuContext& ctx) : PostProcessEffect(ctx) { - uniforms_.init(ctx_.device); pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, passthrough_shader_wgsl); } diff --git a/src/gpu/effects/solarize_effect.cc b/src/gpu/effects/solarize_effect.cc index 7a94004..4f47218 100644 --- a/src/gpu/effects/solarize_effect.cc +++ b/src/gpu/effects/solarize_effect.cc @@ -6,7 +6,6 @@ // --- SolarizeEffect --- SolarizeEffect::SolarizeEffect(const GpuContext& ctx) : PostProcessEffect(ctx) { - uniforms_.init(ctx.device); pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, solarize_shader_wgsl); } diff --git a/src/gpu/effects/theme_modulation_effect.cc b/src/gpu/effects/theme_modulation_effect.cc index 7c222aa..b1eff90 100644 --- a/src/gpu/effects/theme_modulation_effect.cc +++ b/src/gpu/effects/theme_modulation_effect.cc @@ -67,14 +67,13 @@ ThemeModulationEffect::ThemeModulationEffect(const GpuContext& 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 ThemeModulationEffect::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 ThemeModulationEffect::render(WGPURenderPassEncoder pass, float time, @@ -87,7 +86,7 @@ void ThemeModulationEffect::render(WGPURenderPassEncoder pass, float time, .beat = beat, .audio_intensity = intensity, }; - common_uniforms_.update(ctx_.queue, u); + uniforms_.update(ctx_.queue, u); // Alternate between bright and dark every 4 seconds (2 pattern changes) // Music patterns change every 2 seconds at 120 BPM diff --git a/src/gpu/effects/theme_modulation_effect.h b/src/gpu/effects/theme_modulation_effect.h index 474d6da..713347b 100644 --- a/src/gpu/effects/theme_modulation_effect.h +++ b/src/gpu/effects/theme_modulation_effect.h @@ -16,6 +16,5 @@ class ThemeModulationEffect : public PostProcessEffect { void update_bind_group(WGPUTextureView input_view) override; private: - UniformBuffer<CommonPostProcessUniforms> common_uniforms_; GpuBuffer params_buffer_; }; diff --git a/src/gpu/effects/vignette_effect.cc b/src/gpu/effects/vignette_effect.cc index 1b9e36d..bba0372 100644 --- a/src/gpu/effects/vignette_effect.cc +++ b/src/gpu/effects/vignette_effect.cc @@ -12,7 +12,6 @@ VignetteEffect::VignetteEffect(const GpuContext& ctx) VignetteEffect::VignetteEffect(const GpuContext& ctx, const VignetteParams& params) : PostProcessEffect(ctx), params_(params) { - uniforms_.init(ctx_.device); params_buffer_.init(ctx_.device); pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, vignette_shader_wgsl); |
