diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-04 11:56:03 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-04 11:56:03 +0100 |
| commit | 2e34965e5e48175c5ee6016af1a858f7f3f02c1d (patch) | |
| tree | a41ea2fdc50a18183742bffaf0705b394f2be69f /assets/final/shaders/math | |
| parent | 0d29f340b9de8f6a14baa0a2c6f3c57b8d1458a5 (diff) | |
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.
Diffstat (limited to 'assets/final/shaders/math')
| -rw-r--r-- | assets/final/shaders/math/sdf_shapes.wgsl | 14 | ||||
| -rw-r--r-- | assets/final/shaders/math/sdf_utils.wgsl | 9 |
2 files changed, 23 insertions, 0 deletions
diff --git a/assets/final/shaders/math/sdf_shapes.wgsl b/assets/final/shaders/math/sdf_shapes.wgsl new file mode 100644 index 0000000..31bbe2d --- /dev/null +++ b/assets/final/shaders/math/sdf_shapes.wgsl @@ -0,0 +1,14 @@ +fn sdSphere(p: vec3<f32>, r: f32) -> f32 { + return length(p) - r; +} +fn sdBox(p: vec3<f32>, b: vec3<f32>) -> f32 { + let q = abs(p) - b; + return length(max(q, vec3<f32>(0.0))) + min(max(q.x, max(q.y, q.z)), 0.0); +} +fn sdTorus(p: vec3<f32>, t: vec2<f32>) -> f32 { + let q = vec2<f32>(length(p.xz) - t.x, p.y); + return length(q) - t.y; +} +fn sdPlane(p: vec3<f32>, n: vec3<f32>, h: f32) -> f32 { + return dot(p, n) + h; +} diff --git a/assets/final/shaders/math/sdf_utils.wgsl b/assets/final/shaders/math/sdf_utils.wgsl new file mode 100644 index 0000000..ce902bf --- /dev/null +++ b/assets/final/shaders/math/sdf_utils.wgsl @@ -0,0 +1,9 @@ +fn get_normal_basic(p: vec3<f32>, obj_type: f32) -> vec3<f32> { + if (obj_type == 1.0) { return normalize(p); } + let e = vec2<f32>(0.001, 0.0); + return normalize(vec3<f32>( + get_dist(p + e.xyy, obj_type) - get_dist(p - e.xyy, obj_type), + get_dist(p + e.yxy, obj_type) - get_dist(p - e.yxy, obj_type), + get_dist(p + e.yyx, obj_type) - get_dist(p - e.yyx, obj_type) + )); +} |
