From 6b85f294821dcb8373adb2cc47f9c9b2b554fef9 Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 26 Jan 2023 14:49:38 -0500 Subject: multiplex functions --- src/sdf.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sdf.rs b/src/sdf.rs index c140d1b..2b0d297 100644 --- a/src/sdf.rs +++ b/src/sdf.rs @@ -221,9 +221,13 @@ pub enum R3ToR3 { #[only_if(params.max_depth >= 0)] Compose(Box, Box), /// f(x, y, z) = (f₁(x), f₂(y), f₃(z)) - #[prob(4)] + #[prob(3)] #[only_if(params.max_depth >= 0)] PerComponent(Box, Box, Box), + /// f(x) = (f₁(x), f₂(x), f₃(x)) + #[prob(3)] + #[only_if(params.max_depth >= 0)] + Multiplex(Box, Box, Box), /// a linear interpolation between two functions #[prob(4)] #[only_if(params.max_depth >= 0)] @@ -669,6 +673,23 @@ impl Function for R3ToR3 { ); output } + Multiplex(fx, fy, fz) => { + // we need to scale by 1/sqrt(3) to get a valid SDF + let a = var.next(); + write_str!( + code, + "vec3 {a} = {input} * (1.0 / sqrt(3.0));\n" + ); + let output = var.next(); + let x_output = fx.to_glsl(a, code, var); + let y_output = fy.to_glsl(a, code, var); + let z_output = fz.to_glsl(a, code, var); + write_str!( + code, + "vec3 {output} = vec3({x_output}, {y_output}, {z_output});\n" + ); + output + } Mix(a, b, t) => { let a_output = a.to_glsl(input, code, var); let b_output = b.to_glsl(input, code, var); -- cgit v1.2.3