From 2e34965e5e48175c5ee6016af1a858f7f3f02c1d Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 4 Feb 2026 11:56:03 +0100 Subject: feat(gpu): Implement recursive WGSL composition and modularize shaders (Task #50) - Updated ShaderComposer to support recursive #include "snippet_name" with cycle detection. - Extracted granular WGSL snippets: math/sdf_shapes, math/sdf_utils, render/shadows, render/scene_query, render/lighting_utils. - Refactored Renderer3D to use #include in shaders, simplifying C++ dependency lists. - Fixed WGPUShaderSourceWGSL usage on macOS to correctly handle composed shader strings. - Added comprehensive unit tests for recursive composition in test_shader_composer. - Verified system stability with test_3d_render and full test suite. - Marked Task #50 as recurrent for future code hygiene. --- assets/final/shaders/render/lighting_utils.wgsl | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 assets/final/shaders/render/lighting_utils.wgsl (limited to 'assets/final/shaders/render/lighting_utils.wgsl') diff --git a/assets/final/shaders/render/lighting_utils.wgsl b/assets/final/shaders/render/lighting_utils.wgsl new file mode 100644 index 0000000..d2fd2e2 --- /dev/null +++ b/assets/final/shaders/render/lighting_utils.wgsl @@ -0,0 +1,6 @@ +fn calculate_lighting(color: vec3, normal: vec3, pos: vec3, shadow: f32) -> vec3 { + let light_dir = normalize(vec3(1.0, 1.0, 1.0)); + let diffuse = max(dot(normal, light_dir), 0.0); + let lighting = diffuse * (0.1 + 0.9 * shadow) + 0.1; // Ambient + Shadowed Diffuse + return color * lighting; +} -- cgit v1.2.3