summaryrefslogtreecommitdiff
path: root/src/shaders/math/sdf_shapes.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-28 09:08:57 +0100
committerskal <pascal.massimino@gmail.com>2026-02-28 09:08:57 +0100
commit9ee410594a52cbc699b13de2bde4860d70c959a3 (patch)
treed56adf5931d488abcf3ac8e24a828d2d5b02e8cc /src/shaders/math/sdf_shapes.wgsl
parent6599a428cd69be6c66c5179e1f0fce42f561f935 (diff)
refactor: move common/shaders/ to src/shaders/
Relocates shared WGSL shaders under src/ where all source code lives, eliminating the top-level common/ directory. - Update asset references in workspaces/main/assets.txt and workspaces/test/assets.txt - Update docs: PROJECT_CONTEXT.md, ARCHITECTURE.md, WORKSPACE_SYSTEM.md, SHADER_REUSE_INVESTIGATION.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/shaders/math/sdf_shapes.wgsl')
-rw-r--r--src/shaders/math/sdf_shapes.wgsl30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/shaders/math/sdf_shapes.wgsl b/src/shaders/math/sdf_shapes.wgsl
new file mode 100644
index 0000000..2dfae3e
--- /dev/null
+++ b/src/shaders/math/sdf_shapes.wgsl
@@ -0,0 +1,30 @@
+// 3D SDF primitives
+fn sdSphere(p: vec3f, r: f32) -> f32 {
+ return length(p) - r;
+}
+
+fn sdBox(p: vec3f, b: vec3f) -> f32 {
+ let q = abs(p) - b;
+ return length(max(q, vec3f(0.0))) + min(max(q.x, max(q.y, q.z)), 0.0);
+}
+
+fn sdTorus(p: vec3f, t: vec2f) -> f32 {
+ let q = vec2f(length(p.xz) - t.x, p.y);
+ return length(q) - t.y;
+}
+
+fn sdPlane(p: vec3f, n: vec3f, h: f32) -> f32 {
+ return dot(p, n) + h;
+}
+
+// 2D SDF primitives
+fn sdBox2D(p: vec2f, b: vec2f) -> f32 {
+ let d = abs(p) - b;
+ return length(max(d, vec2f(0.0))) + min(max(d.x, d.y), 0.0);
+}
+
+// Approximate
+fn sdEllipse(p: vec2f, ab: vec2f) -> f32 {
+ let d = length(p / ab);
+ return length(p) * (1.0 - 1.0 / d);
+}