summaryrefslogtreecommitdiff
path: root/common/shaders/render/scene_query_linear.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-13 08:34:24 +0100
committerskal <pascal.massimino@gmail.com>2026-02-13 08:34:24 +0100
commita109983c194c45ad85f0e481232bc605c7cfd85b (patch)
tree2b2fadb054fb8ea52d3e31fefdc4678d5a3ed7dc /common/shaders/render/scene_query_linear.wgsl
parent3ce45fcf073047d71ed0b2c88f4d6c5362f6b620 (diff)
Remediation: Implement shared common/shaders/ directory
Eliminates 36 duplicate shader files across workspaces. Structure: - common/shaders/{math,render,compute}/ - Shared utilities (20 files) - workspaces/*/shaders/ - Workspace-specific only Changes: - Created common/shaders/ with math, render, compute subdirectories - Moved 20 common shaders from workspaces to common/ - Removed duplicates from test workspace - Updated assets.txt: ../../common/shaders/ references - Enhanced asset_packer.cc: filesystem path normalization for ../ resolution Implementation: Option 1 from SHADER_REUSE_INVESTIGATION.md - Single source of truth for common code - Workspace references via relative paths - Path normalization in asset packer handoff(Claude): Common shader directory implemented
Diffstat (limited to 'common/shaders/render/scene_query_linear.wgsl')
-rw-r--r--common/shaders/render/scene_query_linear.wgsl56
1 files changed, 56 insertions, 0 deletions
diff --git a/common/shaders/render/scene_query_linear.wgsl b/common/shaders/render/scene_query_linear.wgsl
new file mode 100644
index 0000000..0497a40
--- /dev/null
+++ b/common/shaders/render/scene_query_linear.wgsl
@@ -0,0 +1,56 @@
+#include "math/sdf_shapes"
+#include "math/sdf_utils"
+
+fn get_dist(p: vec3<f32>, obj_params: vec4<f32>) -> f32 {
+ let obj_type = obj_params.x;
+ if (obj_type == 1.0) { return length(p) - 1.0; } // Unit Sphere
+ if (obj_type == 2.0) { return sdBox(p, vec3<f32>(1.0)); } // Unit Box
+ if (obj_type == 3.0) { return sdTorus(p, vec2<f32>(1.0, 0.4)); } // Unit Torus
+ if (obj_type == 4.0) { return sdPlane(p, vec3<f32>(0.0, 1.0, 0.0), 0.0); }
+ if (obj_type == 5.0) { return sdBox(p, obj_params.yzw); } // MESH AABB
+ return 100.0;
+}
+
+fn map_scene(p: vec3<f32>, skip_idx: u32) -> f32 {
+
+ var d = 1000.0;
+
+ let num_objects = arrayLength(&object_data.objects);
+
+ for (var i = 0u; i < num_objects; i++) {
+
+ if (i == skip_idx) { continue; }
+
+ let obj = object_data.objects[i];
+
+ let q = (obj.inv_model * vec4<f32>(p, 1.0)).xyz;
+
+
+
+ // Extract scale factors from the model matrix
+
+ let sx = length(obj.model[0].xyz);
+
+ let sy = length(obj.model[1].xyz);
+
+ let sz = length(obj.model[2].xyz);
+
+
+
+ var s = min(sx, min(sy, sz));
+
+ if (obj.params.x == 4.0) {
+
+ s = sy; // Plane normal is (0,1,0) in local space
+
+ }
+
+
+
+ d = min(d, get_dist(q, obj.params) * s);
+
+ }
+
+ return d;
+
+}