summaryrefslogtreecommitdiff
path: root/src/effects
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/flash_effect.cc2
-rw-r--r--src/effects/gaussian_blur_effect.cc6
-rw-r--r--src/effects/heptagon_effect.cc8
-rw-r--r--src/effects/particles_effect.cc6
-rw-r--r--src/effects/passthrough_effect.cc6
-rw-r--r--src/effects/placeholder_effect.cc8
-rw-r--r--src/effects/rotating_cube_effect.cc8
-rw-r--r--src/effects/shaders.cc109
-rw-r--r--src/effects/shaders.h25
9 files changed, 156 insertions, 22 deletions
diff --git a/src/effects/flash_effect.cc b/src/effects/flash_effect.cc
index 787e33d..9f0a6fa 100644
--- a/src/effects/flash_effect.cc
+++ b/src/effects/flash_effect.cc
@@ -3,7 +3,7 @@
#include "effects/flash_effect.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
#include "util/fatal_error.h"
Flash::Flash(const GpuContext& ctx,
diff --git a/src/effects/gaussian_blur_effect.cc b/src/effects/gaussian_blur_effect.cc
index f2e0197..d163e51 100644
--- a/src/effects/gaussian_blur_effect.cc
+++ b/src/effects/gaussian_blur_effect.cc
@@ -1,9 +1,9 @@
-// Gaussian blur effect v2 implementation
+// Gaussian blur effect implementation
#include "effects/gaussian_blur_effect.h"
#include "util/fatal_error.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
GaussianBlur::GaussianBlur(const GpuContext& ctx,
const std::vector<std::string>& inputs,
@@ -15,7 +15,7 @@ GaussianBlur::GaussianBlur(const GpuContext& ctx,
// Create pipeline
pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- gaussian_blur_v2_shader_wgsl);
+ gaussian_blur_shader_wgsl);
// Create sampler
WGPUSamplerDescriptor sampler_desc = {};
diff --git a/src/effects/heptagon_effect.cc b/src/effects/heptagon_effect.cc
index 1bc9d06..20761dc 100644
--- a/src/effects/heptagon_effect.cc
+++ b/src/effects/heptagon_effect.cc
@@ -1,10 +1,10 @@
-// Heptagon effect v2 implementation
+// Heptagon effect implementation
#include "effects/heptagon_effect.h"
#include "util/fatal_error.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
Heptagon::Heptagon(const GpuContext& ctx,
const std::vector<std::string>& inputs,
@@ -16,9 +16,9 @@ Heptagon::Heptagon(const GpuContext& ctx,
// Init uniforms
uniforms_buffer_.init(ctx_.device);
- // Create pipeline (standard v2 post-process, no depth)
+ // Create pipeline (standard post-process, no depth)
pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- heptagon_v2_shader_wgsl);
+ heptagon_shader_wgsl);
// Create dummy sampler (scene effects don't use texture input)
WGPUSamplerDescriptor sampler_desc = {};
diff --git a/src/effects/particles_effect.cc b/src/effects/particles_effect.cc
index f93133f..7a8d94d 100644
--- a/src/effects/particles_effect.cc
+++ b/src/effects/particles_effect.cc
@@ -4,7 +4,7 @@
#include "util/fatal_error.h"
#include "effects/particles_effect.h"
#include "gpu/gpu.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
#include <vector>
Particles::Particles(const GpuContext& ctx,
@@ -49,7 +49,7 @@ Particles::Particles(const GpuContext& ctx,
ResourceBinding compute_bindings[] = {
{particles_buffer_, WGPUBufferBindingType_Storage},
{uniforms_.get(), WGPUBufferBindingType_Uniform}};
- compute_pass_ = gpu_create_compute_pass(ctx_.device, particle_compute_v2_wgsl,
+ compute_pass_ = gpu_create_compute_pass(ctx_.device, particle_compute_wgsl,
compute_bindings, 2);
compute_pass_.workgroup_size_x = (NUM_PARTICLES + 63) / 64;
@@ -58,7 +58,7 @@ Particles::Particles(const GpuContext& ctx,
{particles_buffer_, WGPUBufferBindingType_ReadOnlyStorage},
{uniforms_.get(), WGPUBufferBindingType_Uniform}};
render_pass_ = gpu_create_render_pass(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- particle_render_v2_wgsl, render_bindings, 2);
+ particle_render_wgsl, render_bindings, 2);
render_pass_.vertex_count = 6;
render_pass_.instance_count = NUM_PARTICLES;
}
diff --git a/src/effects/passthrough_effect.cc b/src/effects/passthrough_effect.cc
index 7c1cf09..94da241 100644
--- a/src/effects/passthrough_effect.cc
+++ b/src/effects/passthrough_effect.cc
@@ -1,9 +1,9 @@
-// Passthrough effect v2 implementation
+// Passthrough effect implementation
#include "effects/passthrough_effect.h"
#include "util/fatal_error.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
Passthrough::Passthrough(const GpuContext& ctx,
const std::vector<std::string>& inputs,
@@ -17,7 +17,7 @@ Passthrough::Passthrough(const GpuContext& ctx,
uniforms_buffer_.init(ctx_.device);
// Create pipeline (simple version without effect params)
pipeline_ = create_post_process_pipeline_simple(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- passthrough_v2_shader_wgsl);
+ passthrough_shader_wgsl);
// Create sampler
WGPUSamplerDescriptor sampler_desc = {};
diff --git a/src/effects/placeholder_effect.cc b/src/effects/placeholder_effect.cc
index 6127e0c..73ee5a8 100644
--- a/src/effects/placeholder_effect.cc
+++ b/src/effects/placeholder_effect.cc
@@ -1,9 +1,9 @@
-// Placeholder effect v2 implementation - logs TODO warning once
+// Placeholder effect implementation - logs TODO warning once
#include "effects/placeholder_effect.h"
#include "util/fatal_error.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
#include <cstdio>
Placeholder::Placeholder(const GpuContext& ctx,
@@ -13,14 +13,14 @@ Placeholder::Placeholder(const GpuContext& ctx,
: Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
sampler_(nullptr), name_(placeholder_name) {
// Log once on construction
- fprintf(stderr, "TODO: %s not yet ported to v2, using passthrough\n", name_);
+ fprintf(stderr, "TODO: %s not yet implemented, using passthrough\n", name_);
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
uniforms_buffer_.init(ctx_.device);
pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- passthrough_v2_shader_wgsl);
+ passthrough_shader_wgsl);
WGPUSamplerDescriptor sampler_desc = {};
sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc
index a91bc78..c892dfe 100644
--- a/src/effects/rotating_cube_effect.cc
+++ b/src/effects/rotating_cube_effect.cc
@@ -1,11 +1,11 @@
// This file is part of the 64k demo project.
-// It implements RotatingCube (simplified v2 port).
+// It implements RotatingCube.
#include "util/fatal_error.h"
#include "effects/rotating_cube_effect.h"
#include "gpu/bind_group_builder.h"
#include "gpu/gpu.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
RotatingCube::RotatingCube(const GpuContext& ctx,
const std::vector<std::string>& inputs,
@@ -39,10 +39,10 @@ RotatingCube::RotatingCube(const GpuContext& ctx,
WGPUPipelineLayout pipeline_layout =
wgpuDeviceCreatePipelineLayout(ctx_.device, &pl_desc);
- // Load shader (TODO: create rotating_cube_v2.wgsl)
+ // Load shader
WGPUShaderSourceWGSL wgsl_src = {};
wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
- wgsl_src.code = str_view(rotating_cube_v2_wgsl);
+ wgsl_src.code = str_view(rotating_cube_wgsl);
WGPUShaderModuleDescriptor shader_desc = {};
shader_desc.nextInChain = &wgsl_src.chain;
diff --git a/src/effects/shaders.cc b/src/effects/shaders.cc
new file mode 100644
index 0000000..a9a82de
--- /dev/null
+++ b/src/effects/shaders.cc
@@ -0,0 +1,109 @@
+// This file is part of the 64k demo project.
+// It defines WGSL shader code for various effects.
+
+#include "effects/shaders.h"
+#include "gpu/shader_composer.h"
+#include "util/asset_manager.h"
+
+#if defined(USE_TEST_ASSETS)
+#include "test_assets.h"
+#else
+#include "generated/assets.h"
+#endif
+
+void InitShaderComposer() {
+ auto& sc = ShaderComposer::Get();
+
+ auto register_if_exists = [&](const char* name, AssetId id) {
+ size_t size;
+
+ const char* data = (const char*)GetAsset(id, &size);
+
+ if (data) {
+ sc.RegisterSnippet(name, std::string(data, size));
+ }
+ };
+
+ register_if_exists("common_uniforms", AssetId::ASSET_SHADER_COMMON_UNIFORMS);
+ register_if_exists("sequence_uniforms",
+ AssetId::ASSET_SHADER_SEQUENCE_V2_UNIFORMS);
+ register_if_exists("postprocess_inline",
+ AssetId::ASSET_SHADER_POSTPROCESS_INLINE);
+ // 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",
+ AssetId::ASSET_SHADER_MATH_COMMON_UTILS);
+ register_if_exists("math/noise", AssetId::ASSET_SHADER_MATH_NOISE);
+ register_if_exists("render/shadows", AssetId::ASSET_SHADER_RENDER_SHADOWS);
+ register_if_exists("render/scene_query_bvh",
+ AssetId::ASSET_SHADER_RENDER_SCENE_QUERY_BVH);
+ register_if_exists("render/scene_query_linear",
+ AssetId::ASSET_SHADER_RENDER_SCENE_QUERY_LINEAR);
+ register_if_exists("render/lighting_utils",
+ AssetId::ASSET_SHADER_RENDER_LIGHTING_UTILS);
+ register_if_exists("render/mesh", AssetId::ASSET_SHADER_MESH);
+
+ register_if_exists("math/sdf_shapes", AssetId::ASSET_SHADER_SDF_SHAPES);
+
+ register_if_exists("lighting", AssetId::ASSET_SHADER_LIGHTING);
+
+ register_if_exists("ray_box", AssetId::ASSET_SHADER_RAY_BOX);
+ register_if_exists("ray_triangle", AssetId::ASSET_SHADER_RAY_TRIANGLE);
+
+ register_if_exists("render/fullscreen_vs",
+ AssetId::ASSET_SHADER_RENDER_FULLSCREEN_VS);
+ register_if_exists("math/color", AssetId::ASSET_SHADER_MATH_COLOR);
+ register_if_exists("math/utils", AssetId::ASSET_SHADER_MATH_UTILS);
+ register_if_exists("render/raymarching",
+ AssetId::ASSET_SHADER_RENDER_RAYMARCHING);
+
+ // CNN shaders (workspace-specific)
+ // register_if_exists("cnn_activation", AssetId::ASSET_SHADER_CNN_ACTIVATION);
+ // register_if_exists("cnn_conv1x1", AssetId::ASSET_SHADER_CNN_CONV1X1);
+ // register_if_exists("cnn_conv3x3", AssetId::ASSET_SHADER_CNN_CONV3X3);
+ // register_if_exists("cnn_conv5x5", AssetId::ASSET_SHADER_CNN_CONV5X5);
+ // register_if_exists("cnn_conv7x7", AssetId::ASSET_SHADER_CNN_CONV7X7);
+ // register_if_exists("cnn_weights_generated",
+ // AssetId::ASSET_SHADER_CNN_WEIGHTS);
+
+#if !defined(STRIP_ALL)
+ sc.VerifyIncludes();
+#endif
+}
+
+// Helper to get asset string or empty string
+static const char* SafeGetAsset(AssetId id) {
+ const uint8_t* data = GetAsset(id);
+ return data ? (const char*)data : "";
+}
+
+// Effect shaders
+const char* passthrough_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_PASSTHROUGH_V2);
+const char* gaussian_blur_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR_V2);
+const char* heptagon_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_HEPTAGON_V2);
+const char* particle_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE);
+const char* particle_render_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER);
+const char* rotating_cube_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_ROTATING_CUBE_V2);
+const char* flash_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_FLASH);
+
+// Compute shaders
+const char* gen_noise_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_NOISE);
+const char* gen_perlin_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_PERLIN);
+const char* gen_grid_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_GRID);
+#if !defined(STRIP_GPU_COMPOSITE)
+const char* gen_blend_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_BLEND);
+const char* gen_mask_compute_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_MASK);
+#endif
diff --git a/src/effects/shaders.h b/src/effects/shaders.h
new file mode 100644
index 0000000..b8700f5
--- /dev/null
+++ b/src/effects/shaders.h
@@ -0,0 +1,25 @@
+// This file is part of the 64k demo project.
+// It declares the WGSL shader strings and initialization function.
+
+#pragma once
+
+// Initializes the ShaderComposer with snippet assets.
+void InitShaderComposer();
+
+// Effect shaders
+extern const char* passthrough_shader_wgsl;
+extern const char* gaussian_blur_shader_wgsl;
+extern const char* heptagon_shader_wgsl;
+extern const char* particle_compute_wgsl;
+extern const char* particle_render_wgsl;
+extern const char* rotating_cube_wgsl;
+extern const char* flash_shader_wgsl;
+
+// Compute shaders
+extern const char* gen_noise_compute_wgsl;
+extern const char* gen_perlin_compute_wgsl;
+extern const char* gen_grid_compute_wgsl;
+#if !defined(STRIP_GPU_COMPOSITE)
+extern const char* gen_blend_compute_wgsl;
+extern const char* gen_mask_compute_wgsl;
+#endif