From 35cbbb40298389efcd2fe87a9c6458d49c1c567e Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 15 Dec 2022 19:35:52 -0500 Subject: add torus, box frame --- src/main.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/main.rs') 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); -- cgit v1.2.3