summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/effects/shaders.cc104
1 files changed, 86 insertions, 18 deletions
diff --git a/src/gpu/effects/shaders.cc b/src/gpu/effects/shaders.cc
index 6b37869..cd516cd 100644
--- a/src/gpu/effects/shaders.cc
+++ b/src/gpu/effects/shaders.cc
@@ -2,39 +2,107 @@
// It defines WGSL shader code for various effects.
#include "../demo_effects.h"
+
+
+
+#if defined(USE_TEST_ASSETS)
+
+#include "test_assets.h"
+
+#else
+
#include "generated/assets.h"
+
+#endif
+
+
+
#include "gpu/effects/shader_composer.h"
+
#include "util/asset_manager.h"
+
+
void InitShaderComposer() {
+
auto& sc = ShaderComposer::Get();
- sc.RegisterSnippet("common_uniforms",
- (const char*)GetAsset(AssetId::ASSET_SHADER_COMMON_UNIFORMS));
- sc.RegisterSnippet("sdf_primitives",
- (const char*)GetAsset(AssetId::ASSET_SHADER_SDF_PRIMITIVES));
- sc.RegisterSnippet("lighting",
- (const char*)GetAsset(AssetId::ASSET_SHADER_LIGHTING));
- sc.RegisterSnippet("ray_box",
- (const char*)GetAsset(AssetId::ASSET_SHADER_RAY_BOX));
+
+
+ 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("sdf_primitives", AssetId::ASSET_SHADER_SDF_PRIMITIVES);
+
+ register_if_exists("lighting", AssetId::ASSET_SHADER_LIGHTING);
+
+ register_if_exists("ray_box", AssetId::ASSET_SHADER_RAY_BOX);
+
}
-const char* main_shader_wgsl = (const char*)GetAsset(AssetId::ASSET_SHADER_MAIN);
+
+
+// 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 : "";
+
+}
+
+
+
+const char* main_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_MAIN);
+
const char* particle_compute_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE);
+
const char* particle_render_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER);
+
const char* passthrough_shader_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_PASSTHROUGH);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_PASSTHROUGH);
+
const char* ellipse_shader_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_ELLIPSE);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_ELLIPSE);
+
const char* particle_spray_compute_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_PARTICLE_SPRAY_COMPUTE);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_SPRAY_COMPUTE);
+
const char* gaussian_blur_shader_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR);
+
const char* solarize_shader_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_SOLARIZE);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_SOLARIZE);
+
const char* distort_shader_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_DISTORT);
+
+ SafeGetAsset(AssetId::ASSET_SHADER_DISTORT);
+
const char* chroma_aberration_shader_wgsl =
- (const char*)GetAsset(AssetId::ASSET_SHADER_CHROMA_ABERRATION); \ No newline at end of file
+
+ SafeGetAsset(AssetId::ASSET_SHADER_CHROMA_ABERRATION);