From f32afcbeffa0e8b947457c67c73566da4ebf33cc Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 3 Feb 2026 08:18:13 +0100 Subject: refactor: Shader Asset Integration (Task #24) Extracted all hardcoded WGSL shaders into external assets. Updated AssetManager to handle shader snippets. Refactored Renderer3D, VisualDebug, and Effects to load shaders via the AssetManager, enabling better shader management and composition. --- src/3d/visual_debug.cc | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) (limited to 'src/3d/visual_debug.cc') diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc index 51ccc39..f8d9bed 100644 --- a/src/3d/visual_debug.cc +++ b/src/3d/visual_debug.cc @@ -5,40 +5,11 @@ #if !defined(STRIP_ALL) +#include "generated/assets.h" +#include "util/asset_manager.h" #include #include -// Simple shader for drawing colored lines -static const char* kDebugShaderCode = R"( -struct Uniforms { - viewProj : mat4x4, -} -@group(0) @binding(0) var uniforms : Uniforms; - -struct VertexInput { - @location(0) position : vec3, - @location(1) color : vec3, -} - -struct VertexOutput { - @builtin(position) position : vec4, - @location(0) color : vec3, -} - -@vertex -fn vs_main(in : VertexInput) -> VertexOutput { - var out : VertexOutput; - out.position = uniforms.viewProj * vec4(in.position, 1.0); - out.color = in.color; - return out; -} - -@fragment -fn fs_main(in : VertexOutput) -> @location(0) vec4 { - return vec4(in.color, 1.0); -} -)"; - void VisualDebug::init(WGPUDevice device, WGPUTextureFormat format) { device_ = device; create_pipeline(format); @@ -92,16 +63,20 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) { wgpuDeviceCreatePipelineLayout(device_, &pl_desc); // Shader + size_t shader_len = 0; + const char* shader_code = + (const char*)GetAsset(AssetId::ASSET_SHADER_VISUAL_DEBUG, &shader_len); + #if defined(DEMO_CROSS_COMPILE_WIN32) WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; - wgsl_desc.code = kDebugShaderCode; + wgsl_desc.code = shader_code; WGPUShaderModuleDescriptor shader_desc = {}; shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain; #else WGPUShaderSourceWGSL wgsl_desc = {}; wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL; - wgsl_desc.code = {kDebugShaderCode, strlen(kDebugShaderCode)}; + wgsl_desc.code = {shader_code, shader_len}; WGPUShaderModuleDescriptor shader_desc = {}; shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain; #endif -- cgit v1.2.3