summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/main.cc7
-rw-r--r--src/effects/chroma_aberration_effect.cc3
-rw-r--r--src/effects/chroma_aberration_effect.h29
-rw-r--r--src/effects/distort_effect.cc3
-rw-r--r--src/effects/distort_effect.h28
-rw-r--r--src/effects/gaussian_blur_effect.cc3
-rw-r--r--src/effects/gaussian_blur_effect.h32
-rw-r--r--src/effects/heptagon_effect.cc3
-rw-r--r--src/effects/heptagon_effect.h16
-rw-r--r--src/effects/moving_ellipse_effect.cc3
-rw-r--r--src/effects/moving_ellipse_effect.h16
-rw-r--r--src/effects/particle_defs.h13
-rw-r--r--src/effects/particle_spray_effect.cc3
-rw-r--r--src/effects/particle_spray_effect.h21
-rw-r--r--src/effects/particles_effect.cc3
-rw-r--r--src/effects/particles_effect.h21
-rw-r--r--src/effects/passthrough_effect.cc3
-rw-r--r--src/effects/passthrough_effect.h14
-rw-r--r--src/effects/sdf_test_effect.cc36
-rw-r--r--src/effects/sdf_test_effect.h16
-rw-r--r--src/effects/solarize_effect.cc3
-rw-r--r--src/effects/solarize_effect.h16
-rw-r--r--src/effects/vignette_effect.cc3
-rw-r--r--src/effects/vignette_effect.h26
-rw-r--r--src/gpu/camera_params.h18
-rw-r--r--src/gpu/demo_effects.h203
-rw-r--r--src/gpu/gpu.cc3
-rw-r--r--src/gpu/sdf_effect.h53
-rw-r--r--src/gpu/shaders.cc5
-rw-r--r--src/gpu/shaders.h1
-rw-r--r--src/tests/gpu/test_demo_effects.cc1
31 files changed, 423 insertions, 182 deletions
diff --git a/src/app/main.cc b/src/app/main.cc
index 27d6312..90e3015 100644
--- a/src/app/main.cc
+++ b/src/app/main.cc
@@ -67,7 +67,7 @@ int main(int argc, char** argv) {
}
} else if (strcmp(argv[i], "--debug") == 0) {
Renderer3D::SetDebugEnabled(true);
- } else if (strcmp(argv[i], "--dump_wav") == 0) {
+ } else if (strcmp(argv[i], "--dump-wav") == 0) {
dump_wav = true;
// Optional: allow specifying output filename
if (i + 1 < argc && argv[i + 1][0] != '-') {
@@ -85,6 +85,9 @@ int main(int argc, char** argv) {
} else if (strcmp(argv[i], "--hot-reload") == 0) {
hot_reload_enabled = true;
printf("Hot-reload enabled (watching config files)\n");
+ } else {
+ fprintf(stderr, "Error: Unrecognized option '%s'\n", argv[i]);
+ return 1;
}
}
#else
@@ -239,7 +242,9 @@ int main(int argc, char** argv) {
platform_shutdown(&platform_state);
return 0;
}
+#endif
+#if !defined(STRIP_ALL)
// In WAV dump mode, run headless simulation and write audio to file
if (dump_wav) {
printf("Running WAV dump simulation...\n");
diff --git a/src/effects/chroma_aberration_effect.cc b/src/effects/chroma_aberration_effect.cc
index 2a92225..4038696 100644
--- a/src/effects/chroma_aberration_effect.cc
+++ b/src/effects/chroma_aberration_effect.cc
@@ -1,9 +1,10 @@
// This file is part of the 64k demo project.
// It implements the ChromaAberrationEffect with parameterization.
-#include "gpu/demo_effects.h"
+#include "effects/chroma_aberration_effect.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
+#include "gpu/shaders.h"
// --- ChromaAberrationEffect ---
diff --git a/src/effects/chroma_aberration_effect.h b/src/effects/chroma_aberration_effect.h
new file mode 100644
index 0000000..1790952
--- /dev/null
+++ b/src/effects/chroma_aberration_effect.h
@@ -0,0 +1,29 @@
+// This file is part of the 64k demo project.
+// It declares the ChromaAberrationEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+#include "gpu/uniform_helper.h"
+
+// Parameters for ChromaAberrationEffect (set at construction time)
+struct ChromaAberrationParams {
+ float offset_scale = 0.02f; // Default: 2% screen offset
+ float angle = 0.0f; // Default: horizontal (0 radians)
+};
+
+class ChromaAberrationEffect : public PostProcessEffect {
+ public:
+ // Backward compatibility constructor (uses default params)
+ ChromaAberrationEffect(const GpuContext& ctx);
+ // New parameterized constructor
+ ChromaAberrationEffect(const GpuContext& ctx,
+ const ChromaAberrationParams& params);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+ void update_bind_group(WGPUTextureView input_view) override;
+
+ private:
+ ChromaAberrationParams params_;
+ UniformBuffer<ChromaAberrationParams> params_buffer_;
+};
diff --git a/src/effects/distort_effect.cc b/src/effects/distort_effect.cc
index f4e68d2..aa72386 100644
--- a/src/effects/distort_effect.cc
+++ b/src/effects/distort_effect.cc
@@ -1,8 +1,9 @@
// This file is part of the 64k demo project.
// It implements the DistortEffect.
-#include "gpu/demo_effects.h"
+#include "effects/distort_effect.h"
#include "gpu/gpu.h"
+#include "gpu/shaders.h"
// --- DistortEffect ---
DistortEffect::DistortEffect(const GpuContext& ctx)
diff --git a/src/effects/distort_effect.h b/src/effects/distort_effect.h
new file mode 100644
index 0000000..548cf91
--- /dev/null
+++ b/src/effects/distort_effect.h
@@ -0,0 +1,28 @@
+// This file is part of the 64k demo project.
+// It declares the DistortEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+#include "gpu/uniform_helper.h"
+
+// Parameters for DistortEffect
+struct DistortParams {
+ float strength = 0.01f; // Default distortion strength
+ float speed = 1.0f; // Default distortion speed
+};
+static_assert(sizeof(DistortParams) == 8,
+ "DistortParams must be 8 bytes for WGSL alignment");
+
+class DistortEffect : public PostProcessEffect {
+ public:
+ DistortEffect(const GpuContext& ctx);
+ DistortEffect(const GpuContext& ctx, const DistortParams& params);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+ void update_bind_group(WGPUTextureView input_view) override;
+
+ private:
+ DistortParams params_;
+ UniformBuffer<DistortParams> params_buffer_;
+};
diff --git a/src/effects/gaussian_blur_effect.cc b/src/effects/gaussian_blur_effect.cc
index 6a0675d..b5961fa 100644
--- a/src/effects/gaussian_blur_effect.cc
+++ b/src/effects/gaussian_blur_effect.cc
@@ -1,9 +1,10 @@
// This file is part of the 64k demo project.
// It implements the GaussianBlurEffect with parameterization.
-#include "gpu/demo_effects.h"
+#include "effects/gaussian_blur_effect.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
+#include "gpu/shaders.h"
// --- GaussianBlurEffect ---
diff --git a/src/effects/gaussian_blur_effect.h b/src/effects/gaussian_blur_effect.h
new file mode 100644
index 0000000..651c5c3
--- /dev/null
+++ b/src/effects/gaussian_blur_effect.h
@@ -0,0 +1,32 @@
+// This file is part of the 64k demo project.
+// It declares the GaussianBlurEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+#include "gpu/uniform_helper.h"
+
+// Parameters for GaussianBlurEffect (set at construction time)
+struct GaussianBlurParams {
+ float strength = 1.0f; // Default
+ float strength_audio = 0.5f; // how much to pulse with audio
+ float stretch = 1.f; // y/x axis ratio
+ float _pad = 0.;
+};
+static_assert(sizeof(GaussianBlurParams) == 16,
+ "GaussianBlurParams must be 16 bytes for WGSL alignment");
+
+class GaussianBlurEffect : public PostProcessEffect {
+ public:
+ // Backward compatibility constructor (uses default params)
+ GaussianBlurEffect(const GpuContext& ctx);
+ // New parameterized constructor
+ GaussianBlurEffect(const GpuContext& ctx, const GaussianBlurParams& params);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+ void update_bind_group(WGPUTextureView input_view) override;
+
+ private:
+ GaussianBlurParams params_;
+ UniformBuffer<GaussianBlurParams> params_buffer_;
+};
diff --git a/src/effects/heptagon_effect.cc b/src/effects/heptagon_effect.cc
index 273adc2..d15882d 100644
--- a/src/effects/heptagon_effect.cc
+++ b/src/effects/heptagon_effect.cc
@@ -1,8 +1,9 @@
// This file is part of the 64k demo project.
// It implements the HeptagonEffect.
-#include "gpu/demo_effects.h"
+#include "effects/heptagon_effect.h"
#include "gpu/gpu.h"
+#include "gpu/shaders.h"
#include "util/mini_math.h"
// --- HeptagonEffect ---
diff --git a/src/effects/heptagon_effect.h b/src/effects/heptagon_effect.h
new file mode 100644
index 0000000..fe19839
--- /dev/null
+++ b/src/effects/heptagon_effect.h
@@ -0,0 +1,16 @@
+// This file is part of the 64k demo project.
+// It declares the HeptagonEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+
+class HeptagonEffect : public Effect {
+ public:
+ HeptagonEffect(const GpuContext& ctx);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+
+ private:
+ RenderPass pass_;
+};
diff --git a/src/effects/moving_ellipse_effect.cc b/src/effects/moving_ellipse_effect.cc
index e641927..6fb0195 100644
--- a/src/effects/moving_ellipse_effect.cc
+++ b/src/effects/moving_ellipse_effect.cc
@@ -1,9 +1,10 @@
// This file is part of the 64k demo project.
// It implements the MovingEllipseEffect.
-#include "gpu/demo_effects.h"
+#include "effects/moving_ellipse_effect.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
+#include "gpu/shaders.h"
// --- MovingEllipseEffect ---
MovingEllipseEffect::MovingEllipseEffect(const GpuContext& ctx) : Effect(ctx) {
diff --git a/src/effects/moving_ellipse_effect.h b/src/effects/moving_ellipse_effect.h
new file mode 100644
index 0000000..46c1f0e
--- /dev/null
+++ b/src/effects/moving_ellipse_effect.h
@@ -0,0 +1,16 @@
+// This file is part of the 64k demo project.
+// It declares the MovingEllipseEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+
+class MovingEllipseEffect : public Effect {
+ public:
+ MovingEllipseEffect(const GpuContext& ctx);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+
+ private:
+ RenderPass pass_;
+};
diff --git a/src/effects/particle_defs.h b/src/effects/particle_defs.h
new file mode 100644
index 0000000..dcbb830
--- /dev/null
+++ b/src/effects/particle_defs.h
@@ -0,0 +1,13 @@
+// This file is part of the 64k demo project.
+// It defines common structures for particle-based effects.
+
+#pragma once
+
+static const int NUM_PARTICLES = 10000;
+
+struct Particle {
+ float pos[4];
+ float vel[4];
+ float rot[4];
+ float color[4];
+};
diff --git a/src/effects/particle_spray_effect.cc b/src/effects/particle_spray_effect.cc
index 0b0dba1..1acf67d 100644
--- a/src/effects/particle_spray_effect.cc
+++ b/src/effects/particle_spray_effect.cc
@@ -1,9 +1,10 @@
// This file is part of the 64k demo project.
// It implements the ParticleSprayEffect.
-#include "gpu/demo_effects.h"
+#include "effects/particle_spray_effect.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
+#include "gpu/shaders.h"
#include <vector>
// --- ParticleSprayEffect ---
diff --git a/src/effects/particle_spray_effect.h b/src/effects/particle_spray_effect.h
new file mode 100644
index 0000000..c83d691
--- /dev/null
+++ b/src/effects/particle_spray_effect.h
@@ -0,0 +1,21 @@
+// This file is part of the 64k demo project.
+// It declares the ParticleSprayEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+#include "effects/particle_defs.h"
+
+class ParticleSprayEffect : public Effect {
+ public:
+ ParticleSprayEffect(const GpuContext& ctx);
+ void compute(WGPUCommandEncoder encoder,
+ const CommonPostProcessUniforms& uniforms) override;
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+
+ private:
+ ComputePass compute_pass_;
+ RenderPass render_pass_;
+ GpuBuffer particles_buffer_;
+};
diff --git a/src/effects/particles_effect.cc b/src/effects/particles_effect.cc
index b05aecd..25589fd 100644
--- a/src/effects/particles_effect.cc
+++ b/src/effects/particles_effect.cc
@@ -1,9 +1,10 @@
// This file is part of the 64k demo project.
// It implements the ParticlesEffect.
-#include "gpu/demo_effects.h"
+#include "effects/particles_effect.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
+#include "gpu/shaders.h"
#include <vector>
// --- ParticlesEffect ---
diff --git a/src/effects/particles_effect.h b/src/effects/particles_effect.h
new file mode 100644
index 0000000..6d46ea2
--- /dev/null
+++ b/src/effects/particles_effect.h
@@ -0,0 +1,21 @@
+// This file is part of the 64k demo project.
+// It declares the ParticlesEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+#include "effects/particle_defs.h"
+
+class ParticlesEffect : public Effect {
+ public:
+ ParticlesEffect(const GpuContext& ctx);
+ void compute(WGPUCommandEncoder encoder,
+ const CommonPostProcessUniforms& uniforms) override;
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+
+ private:
+ ComputePass compute_pass_;
+ RenderPass render_pass_;
+ GpuBuffer particles_buffer_;
+};
diff --git a/src/effects/passthrough_effect.cc b/src/effects/passthrough_effect.cc
index aedb387..50f5a5c 100644
--- a/src/effects/passthrough_effect.cc
+++ b/src/effects/passthrough_effect.cc
@@ -1,8 +1,9 @@
// This file is part of the 64k demo project.
// It implements the PassthroughEffect.
-#include "gpu/demo_effects.h"
+#include "effects/passthrough_effect.h"
#include "gpu/gpu.h"
+#include "gpu/shaders.h"
// --- PassthroughEffect ---
PassthroughEffect::PassthroughEffect(const GpuContext& ctx)
diff --git a/src/effects/passthrough_effect.h b/src/effects/passthrough_effect.h
new file mode 100644
index 0000000..36f93f2
--- /dev/null
+++ b/src/effects/passthrough_effect.h
@@ -0,0 +1,14 @@
+// This file is part of the 64k demo project.
+// It declares the PassthroughEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+
+class PassthroughEffect : public PostProcessEffect {
+ public:
+ PassthroughEffect(const GpuContext& ctx);
+ void update_bind_group(WGPUTextureView input_view) override;
+
+ private:
+};
diff --git a/src/effects/sdf_test_effect.cc b/src/effects/sdf_test_effect.cc
new file mode 100644
index 0000000..28b3513
--- /dev/null
+++ b/src/effects/sdf_test_effect.cc
@@ -0,0 +1,36 @@
+// This file is part of the 64k demo project.
+// It implements the SDFTestEffect.
+
+#include "effects/sdf_test_effect.h"
+#include "gpu/gpu.h"
+#include "gpu/shaders.h"
+
+SDFTestEffect::SDFTestEffect(const GpuContext& ctx) : SDFEffect(ctx) {
+ ResourceBinding bindings[] = {
+ {uniforms_.get(), WGPUBufferBindingType_Uniform},
+ {camera_params_.get(), WGPUBufferBindingType_Uniform}};
+ pass_ = gpu_create_render_pass(ctx_.device, ctx_.format,
+ sdf_test_shader_wgsl, bindings, 2);
+ pass_.vertex_count = 3;
+}
+
+void SDFTestEffect::render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) {
+ // Update common uniforms
+ uniforms_.update(ctx_.queue, uniforms);
+
+ // Update camera (simple orbiting camera)
+ const float radius = 5.0f;
+ const float speed = 0.3f;
+ vec3 cam_pos(std::cos(uniforms.time * speed) * radius, 2.0f,
+ std::sin(uniforms.time * speed) * radius);
+ vec3 cam_target(0.0f, 0.0f, 0.0f);
+ vec3 cam_up(0.0f, 1.0f, 0.0f);
+ update_camera(cam_pos, cam_target, cam_up, 0.785398f, 0.1f, 100.0f,
+ uniforms.aspect_ratio);
+
+ // Render
+ wgpuRenderPassEncoderSetPipeline(pass, pass_.pipeline);
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, pass_.bind_group, 0, nullptr);
+ wgpuRenderPassEncoderDraw(pass, pass_.vertex_count, 1, 0, 0);
+}
diff --git a/src/effects/sdf_test_effect.h b/src/effects/sdf_test_effect.h
new file mode 100644
index 0000000..41baf83
--- /dev/null
+++ b/src/effects/sdf_test_effect.h
@@ -0,0 +1,16 @@
+// This file is part of the 64k demo project.
+// It demonstrates SDFEffect base class usage.
+
+#pragma once
+
+#include "gpu/sdf_effect.h"
+
+class SDFTestEffect : public SDFEffect {
+ public:
+ SDFTestEffect(const GpuContext& ctx);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+
+ private:
+ RenderPass pass_;
+};
diff --git a/src/effects/solarize_effect.cc b/src/effects/solarize_effect.cc
index cdb9354..a367e51 100644
--- a/src/effects/solarize_effect.cc
+++ b/src/effects/solarize_effect.cc
@@ -1,8 +1,9 @@
// This file is part of the 64k demo project.
// It implements the SolarizeEffect.
-#include "gpu/demo_effects.h"
+#include "effects/solarize_effect.h"
#include "gpu/gpu.h"
+#include "gpu/shaders.h"
// --- SolarizeEffect ---
SolarizeEffect::SolarizeEffect(const GpuContext& ctx) : PostProcessEffect(ctx) {
diff --git a/src/effects/solarize_effect.h b/src/effects/solarize_effect.h
new file mode 100644
index 0000000..6132f58
--- /dev/null
+++ b/src/effects/solarize_effect.h
@@ -0,0 +1,16 @@
+// This file is part of the 64k demo project.
+// It declares the SolarizeEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+
+class SolarizeEffect : public PostProcessEffect {
+ public:
+ SolarizeEffect(const GpuContext& ctx);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+ void update_bind_group(WGPUTextureView input_view) override;
+
+ private:
+};
diff --git a/src/effects/vignette_effect.cc b/src/effects/vignette_effect.cc
index f5c3f05..3ddbee3 100644
--- a/src/effects/vignette_effect.cc
+++ b/src/effects/vignette_effect.cc
@@ -1,9 +1,10 @@
// This file is part of the 64k demo project.
// It implements the VignetteEffect.
-#include "gpu/demo_effects.h"
+#include "effects/vignette_effect.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
+#include "gpu/shaders.h"
VignetteEffect::VignetteEffect(const GpuContext& ctx)
: VignetteEffect(ctx, VignetteParams()) {
diff --git a/src/effects/vignette_effect.h b/src/effects/vignette_effect.h
new file mode 100644
index 0000000..f891d14
--- /dev/null
+++ b/src/effects/vignette_effect.h
@@ -0,0 +1,26 @@
+// This file is part of the 64k demo project.
+// It declares the VignetteEffect.
+
+#pragma once
+
+#include "gpu/effect.h"
+#include "gpu/uniform_helper.h"
+
+// Parameters for VignetteEffect
+struct VignetteParams {
+ float radius = 0.5f; // Radius of the clear center
+ float softness = 0.5f; // Softness of the vignette edge
+};
+
+class VignetteEffect : public PostProcessEffect {
+ public:
+ VignetteEffect(const GpuContext& ctx);
+ VignetteEffect(const GpuContext& ctx, const VignetteParams& params);
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
+ void update_bind_group(WGPUTextureView input_view) override;
+
+ private:
+ VignetteParams params_;
+ UniformBuffer<VignetteParams> params_buffer_;
+};
diff --git a/src/gpu/camera_params.h b/src/gpu/camera_params.h
new file mode 100644
index 0000000..361f65f
--- /dev/null
+++ b/src/gpu/camera_params.h
@@ -0,0 +1,18 @@
+// This file is part of the 64k demo project.
+// It defines CameraParams for raymarching effects.
+
+#pragma once
+
+#include "util/mini_math.h"
+
+// Camera parameters for SDF raymarching effects
+// Binding convention: @group(0) @binding(3)
+struct CameraParams {
+ mat4 inv_view; // Inverse view matrix (screen→world transform)
+ float fov; // Vertical field of view in radians
+ float near_plane; // Near clipping plane
+ float far_plane; // Far clipping plane
+ float aspect_ratio; // Width/height ratio
+};
+static_assert(sizeof(CameraParams) == 80,
+ "CameraParams must be 80 bytes for WGSL alignment");
diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h
index 72c8e6e..85498ad 100644
--- a/src/gpu/demo_effects.h
+++ b/src/gpu/demo_effects.h
@@ -1,192 +1,53 @@
// This file is part of the 64k demo project.
-// It declares the concrete effects used in the demo.
+// It includes all concrete effects used in the demo.
#pragma once
+
+// Core 3D
#include "3d/camera.h"
#include "3d/renderer.h"
#include "3d/scene.h"
+
+// Base effect classes
#include "effect.h"
-#include "effects/circle_mask_effect.h"
-#include "effects/fade_effect.h" // FadeEffect with full definition
-#include "effects/flash_cube_effect.h"
-#include "effects/flash_effect.h" // FlashEffect with params support
-#include "effects/hybrid_3d_effect.h"
-#include "effects/rotating_cube_effect.h"
-#include "effects/scene1_effect.h"
-#include "effects/theme_modulation_effect.h" // ThemeModulationEffect with full definition
-#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
#include "gpu/shaders.h"
#include "gpu/texture_manager.h"
#include "gpu/uniform_helper.h"
-#include <memory>
-
-static const int NUM_PARTICLES = 10000;
-
-struct Particle {
- float pos[4];
- float vel[4];
- float rot[4];
- float color[4];
-};
-
-class HeptagonEffect : public Effect {
- public:
- HeptagonEffect(const GpuContext& ctx);
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
-
- private:
- RenderPass pass_;
-};
-
-class ParticlesEffect : public Effect {
- public:
- ParticlesEffect(const GpuContext& ctx);
- void compute(WGPUCommandEncoder encoder,
- const CommonPostProcessUniforms& uniforms) override;
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
-
- private:
- ComputePass compute_pass_;
- RenderPass render_pass_;
- GpuBuffer particles_buffer_;
-};
-
-class PassthroughEffect : public PostProcessEffect {
- public:
- PassthroughEffect(const GpuContext& ctx);
- void update_bind_group(WGPUTextureView input_view) override;
-
- private:
-};
-
-class MovingEllipseEffect : public Effect {
- public:
- MovingEllipseEffect(const GpuContext& ctx);
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
-
- private:
- RenderPass pass_;
-};
-
-class ParticleSprayEffect : public Effect {
- public:
- ParticleSprayEffect(const GpuContext& ctx);
- void compute(WGPUCommandEncoder encoder,
- const CommonPostProcessUniforms& uniforms) override;
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
- private:
- ComputePass compute_pass_;
- RenderPass render_pass_;
- GpuBuffer particles_buffer_;
-};
-
-// Parameters for GaussianBlurEffect (set at construction time)
-struct GaussianBlurParams {
- float strength = 1.0f; // Default
- float strength_audio = 0.5f; // how much to pulse with audio
- float stretch = 1.f; // y/x axis ratio
- float _pad = 0.;
-};
-static_assert(sizeof(GaussianBlurParams) == 16,
- "GaussianBlurParams must be 16 bytes for WGSL alignment");
-
-class GaussianBlurEffect : public PostProcessEffect {
- public:
- // Backward compatibility constructor (uses default params)
- GaussianBlurEffect(const GpuContext& ctx);
- // New parameterized constructor
- GaussianBlurEffect(const GpuContext& ctx, const GaussianBlurParams& params);
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
- void update_bind_group(WGPUTextureView input_view) override;
-
- private:
- GaussianBlurParams params_;
- UniformBuffer<GaussianBlurParams> params_buffer_;
-};
-
-class SolarizeEffect : public PostProcessEffect {
- public:
- SolarizeEffect(const GpuContext& ctx);
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
- void update_bind_group(WGPUTextureView input_view) override;
-
- private:
-};
-
-// Parameters for VignetteEffect
-struct VignetteParams {
- float radius = 0.5f; // Radius of the clear center
- float softness = 0.5f; // Softness of the vignette edge
-};
-
-class VignetteEffect : public PostProcessEffect {
- public:
- VignetteEffect(const GpuContext& ctx);
- VignetteEffect(const GpuContext& ctx, const VignetteParams& params);
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
- void update_bind_group(WGPUTextureView input_view) override;
-
- private:
- VignetteParams params_;
- UniformBuffer<VignetteParams> params_buffer_;
-};
+// Individual Effect Headers
+#include "effects/chroma_aberration_effect.h"
+#include "effects/circle_mask_effect.h"
+#include "effects/cnn_effect.h"
+#include "effects/cnn_v2_effect.h"
+#include "effects/distort_effect.h"
+#include "effects/fade_effect.h"
+#include "effects/flash_cube_effect.h"
+#include "effects/flash_effect.h"
+#include "effects/gaussian_blur_effect.h"
+#include "effects/heptagon_effect.h"
+#include "effects/hybrid_3d_effect.h"
+#include "effects/moving_ellipse_effect.h"
+#include "effects/particle_spray_effect.h"
+#include "effects/particles_effect.h"
+#include "effects/passthrough_effect.h"
+#include "effects/rotating_cube_effect.h"
+#include "effects/scene1_effect.h"
+#include "effects/sdf_test_effect.h"
+#include "effects/solarize_effect.h"
+#include "effects/theme_modulation_effect.h"
+#include "effects/vignette_effect.h"
-// Parameters for ChromaAberrationEffect (set at construction time)
-struct ChromaAberrationParams {
- float offset_scale = 0.02f; // Default: 2% screen offset
- float angle = 0.0f; // Default: horizontal (0 radians)
-};
+#include <memory>
-class ChromaAberrationEffect : public PostProcessEffect {
- public:
- // Backward compatibility constructor (uses default params)
- ChromaAberrationEffect(const GpuContext& ctx);
- // New parameterized constructor
- ChromaAberrationEffect(const GpuContext& ctx,
- const ChromaAberrationParams& params);
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
- void update_bind_group(WGPUTextureView input_view) override;
- private:
- ChromaAberrationParams params_;
- UniformBuffer<ChromaAberrationParams> params_buffer_;
-};
-// Parameters for DistortEffect
-struct DistortParams {
- float strength = 0.01f; // Default distortion strength
- float speed = 1.0f; // Default distortion speed
-};
-static_assert(sizeof(DistortParams) == 8,
- "DistortParams must be 8 bytes for WGSL alignment");
+// Common particle definition is now in effects/particle_defs.h
-class DistortEffect : public PostProcessEffect {
- public:
- DistortEffect(const GpuContext& ctx);
- DistortEffect(const GpuContext& ctx, const DistortParams& params);
- void render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& uniforms) override;
- void update_bind_group(WGPUTextureView input_view) override;
- private:
- DistortParams params_;
- UniformBuffer<DistortParams> params_buffer_;
-};
-#include "effects/cnn_effect.h"
-#include "effects/cnn_v2_effect.h"
+// Auto-generated functions from sequence compiler
-// Auto-generated functions
void LoadTimeline(MainSequence& main_seq, const GpuContext& ctx);
-float GetDemoDuration(); // Returns demo end time in seconds, or -1 if not
- // specified \ No newline at end of file
+
+float GetDemoDuration();
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index 6d2c7d5..ce234fa 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -138,10 +138,12 @@ RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format,
wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
wgsl_src.code = str_view(composed_shader.c_str());
WGPUShaderModuleDescriptor shader_desc = {};
+ shader_desc.label = label_view("render_shader");
shader_desc.nextInChain = &wgsl_src.chain;
WGPUShaderModule shader_module =
wgpuDeviceCreateShaderModule(device, &shader_desc);
+
// Create Bind Group Layout & Bind Group
std::vector<WGPUBindGroupLayoutEntry> bgl_entries;
std::vector<WGPUBindGroupEntry> bg_entries;
@@ -241,6 +243,7 @@ ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code,
wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
wgsl_src.code = str_view(composed_shader.c_str());
WGPUShaderModuleDescriptor shader_desc = {};
+ shader_desc.label = label_view("compute_shader");
shader_desc.nextInChain = &wgsl_src.chain;
WGPUShaderModule shader_module =
wgpuDeviceCreateShaderModule(device, &shader_desc);
diff --git a/src/gpu/sdf_effect.h b/src/gpu/sdf_effect.h
new file mode 100644
index 0000000..4f23604
--- /dev/null
+++ b/src/gpu/sdf_effect.h
@@ -0,0 +1,53 @@
+// This file is part of the 64k demo project.
+// It defines SDFEffect base class for raymarching effects.
+
+#pragma once
+
+#include "3d/camera.h"
+#include "gpu/camera_params.h"
+#include "gpu/effect.h"
+#include "gpu/uniform_helper.h"
+
+// Base class for SDF raymarching effects
+// Provides CameraParams uniform buffer and helper methods
+//
+// Binding convention:
+// @group(0) @binding(2): CommonPostProcessUniforms (from Effect base)
+// @group(0) @binding(3): CameraParams
+// @group(0) @binding(4+): Per-effect custom parameters
+class SDFEffect : public Effect {
+ public:
+ SDFEffect(const GpuContext& ctx) : Effect(ctx) {
+ camera_params_.init(ctx.device);
+ }
+
+ virtual ~SDFEffect() = default;
+
+ // Populate camera parameters from Camera object
+ void update_camera(const Camera& camera, float aspect_ratio) {
+ CameraParams params;
+ params.inv_view = camera.get_view_matrix().inverse();
+ params.fov = camera.fov_y_rad;
+ params.near_plane = camera.near_plane;
+ params.far_plane = camera.far_plane;
+ params.aspect_ratio = aspect_ratio;
+ camera_params_.update(ctx_.queue, params);
+ }
+
+ // Populate camera parameters with custom values
+ void update_camera(const vec3& position, const vec3& target, const vec3& up,
+ float fov, float near_plane, float far_plane,
+ float aspect_ratio) {
+ mat4 view = mat4::look_at(position, target, up);
+ CameraParams params;
+ params.inv_view = view.inverse();
+ params.fov = fov;
+ params.near_plane = near_plane;
+ params.far_plane = far_plane;
+ params.aspect_ratio = aspect_ratio;
+ camera_params_.update(ctx_.queue, params);
+ }
+
+ protected:
+ UniformBuffer<CameraParams> camera_params_;
+};
diff --git a/src/gpu/shaders.cc b/src/gpu/shaders.cc
index 1bf5604..30bbb0c 100644
--- a/src/gpu/shaders.cc
+++ b/src/gpu/shaders.cc
@@ -31,6 +31,7 @@ void InitShaderComposer() {
};
register_if_exists("common_uniforms", AssetId::ASSET_SHADER_COMMON_UNIFORMS);
+ 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",
@@ -114,6 +115,10 @@ const char* scene1_shader_wgsl =
SafeGetAsset(AssetId::ASSET_SHADER_SCENE1);
+const char* sdf_test_shader_wgsl =
+
+ SafeGetAsset(AssetId::ASSET_SHADER_SDF_TEST);
+
const char* distort_shader_wgsl =
SafeGetAsset(AssetId::ASSET_SHADER_DISTORT);
diff --git a/src/gpu/shaders.h b/src/gpu/shaders.h
index 03fa48c..03263db 100644
--- a/src/gpu/shaders.h
+++ b/src/gpu/shaders.h
@@ -16,6 +16,7 @@ extern const char* particle_spray_compute_wgsl;
extern const char* gaussian_blur_shader_wgsl;
extern const char* solarize_shader_wgsl;
extern const char* scene1_shader_wgsl;
+extern const char* sdf_test_shader_wgsl;
extern const char* distort_shader_wgsl;
extern const char* chroma_aberration_shader_wgsl;
extern const char* vignette_shader_wgsl;
diff --git a/src/tests/gpu/test_demo_effects.cc b/src/tests/gpu/test_demo_effects.cc
index 4234901..ec78c10 100644
--- a/src/tests/gpu/test_demo_effects.cc
+++ b/src/tests/gpu/test_demo_effects.cc
@@ -136,6 +136,7 @@ static void test_scene_effects() {
{"RotatingCubeEffect",
std::make_shared<RotatingCubeEffect>(fixture.ctx())},
{"Scene1Effect", std::make_shared<Scene1Effect>(fixture.ctx())},
+ {"SDFTestEffect", std::make_shared<SDFTestEffect>(fixture.ctx())},
};
int passed = 0;