summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-15 19:35:52 -0500
committerpommicket <pommicket@gmail.com>2022-12-15 19:35:52 -0500
commit35cbbb40298389efcd2fe87a9c6458d49c1c567e (patch)
treed96318ef6945ab9775d5df5534fcbb7e1175fccb /src/main.rs
parentae29a61c9917da5ad9fbb7a24151bff506669ffb (diff)
add torus, box frame
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 41a6d7b..2c42e97 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,8 @@
@TODO:
- auto-select level set by sampling a bunch of points
- bring time back, w pause/rewind/adjust time speed (start out paused?)
-- Params instead of depth
+- Params instead of depth for GenRandom
+ - allow multiple endpoints (cube & sphere & ...)
- seed control (maybe save seeds to a file then let user go back&forth through past sdfs)
- fullscreen key
- mathematical analysis
@@ -17,6 +18,7 @@
-----
cool seeds:
+commit ae29a61c9917da5ad9fbb7a24151bff506669ffb
18413841503509874975
**17878446840930313726
*/
@@ -102,6 +104,22 @@ float smooth_min(float a, float b, float k) {
float h = max(k-abs(a-b), 0.0)/k;
return min(a, b) - h*h*h*k*(1.0/6.0);
}
+
+// thanks to https://iquilezles.org/articles/distfunctions/
+
+float sdf_box_frame( vec3 p, vec3 b, float e ) {
+ p = abs(p )-b;
+ vec3 q = abs(p+e)-e;
+ return min(min(
+ length(max(vec3(p.x,q.y,q.z),0.0))+min(max(p.x,max(q.y,q.z)),0.0),
+ length(max(vec3(q.x,p.y,q.z),0.0))+min(max(q.x,max(p.y,q.z)),0.0)),
+ length(max(vec3(q.x,q.y,p.z),0.0))+min(max(q.x,max(q.y,p.z)),0.0));
+}
+
+float sdf_torus(vec3 p, vec2 t) {
+ vec2 q = vec2(length(p.xy)-t.x,p.z);
+ return length(q)-t.y;
+}
",
);
my_sdf.to_glsl_function("sdf", &mut fshader_source);