summaryrefslogtreecommitdiff
path: root/assets/final/shaders/math/sdf_utils.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-06 01:38:51 +0100
committerskal <pascal.massimino@gmail.com>2026-02-06 01:38:51 +0100
commitae4b03ef6f5ef07dcc80affd6877d17fceee7d29 (patch)
treeab57453a320c90c76eeda3ca291e382ec6413a86 /assets/final/shaders/math/sdf_utils.wgsl
parent3581fa88300f0208c83f0f687b18479979dad035 (diff)
feat(perf): Add toggle for GPU BVH and fix fallback
Completed Task #18-B. - Implemented GPU-side BVH traversal for scene queries, improving performance. - Added a --no-bvh command-line flag to disable the feature for debugging and performance comparison. - Fixed a shader compilation issue where the non-BVH fallback path failed to render objects.
Diffstat (limited to 'assets/final/shaders/math/sdf_utils.wgsl')
-rw-r--r--assets/final/shaders/math/sdf_utils.wgsl8
1 files changed, 8 insertions, 0 deletions
diff --git a/assets/final/shaders/math/sdf_utils.wgsl b/assets/final/shaders/math/sdf_utils.wgsl
index ce902bf..502ba5b 100644
--- a/assets/final/shaders/math/sdf_utils.wgsl
+++ b/assets/final/shaders/math/sdf_utils.wgsl
@@ -7,3 +7,11 @@ fn get_normal_basic(p: vec3<f32>, obj_type: f32) -> vec3<f32> {
get_dist(p + e.yyx, obj_type) - get_dist(p - e.yyx, obj_type)
));
}
+
+// Distance to an Axis-Aligned Bounding Box
+fn aabb_sdf(p: vec3<f32>, min_p: vec3<f32>, max_p: vec3<f32>) -> f32 {
+ let center = (min_p + max_p) * 0.5;
+ let extent = (max_p - min_p) * 0.5;
+ let q = abs(p - center) - extent;
+ return length(max(q, vec3<f32>(0.0))) + min(max(q.x, max(q.y, q.z)), 0.0);
+}