diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-03 08:18:13 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-03 08:18:13 +0100 |
| commit | f32afcbeffa0e8b947457c67c73566da4ebf33cc (patch) | |
| tree | 8860e7c319b687871e6b9692dc0053eb4b1d583d /src/3d/visual_debug.cc | |
| parent | 7cbebea3a0cce82f3a756c26ab0e1323bbf1d169 (diff) | |
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.
Diffstat (limited to 'src/3d/visual_debug.cc')
| -rw-r--r-- | src/3d/visual_debug.cc | 41 |
1 files changed, 8 insertions, 33 deletions
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 <cstdio> #include <cstring> -// Simple shader for drawing colored lines -static const char* kDebugShaderCode = R"( -struct Uniforms { - viewProj : mat4x4<f32>, -} -@group(0) @binding(0) var<uniform> uniforms : Uniforms; - -struct VertexInput { - @location(0) position : vec3<f32>, - @location(1) color : vec3<f32>, -} - -struct VertexOutput { - @builtin(position) position : vec4<f32>, - @location(0) color : vec3<f32>, -} - -@vertex -fn vs_main(in : VertexInput) -> VertexOutput { - var out : VertexOutput; - out.position = uniforms.viewProj * vec4<f32>(in.position, 1.0); - out.color = in.color; - return out; -} - -@fragment -fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> { - return vec4<f32>(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 |
