diff options
author | pommicket <pommicket@gmail.com> | 2023-01-26 14:49:38 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-01-26 14:49:38 -0500 |
commit | 6b85f294821dcb8373adb2cc47f9c9b2b554fef9 (patch) | |
tree | bd45818cf56bd2145c30d89e4450de144d26de3d /src | |
parent | afe515fd6dab94573b0bd9c6a1e0b64a0796883b (diff) |
multiplex functions
Diffstat (limited to 'src')
-rw-r--r-- | src/sdf.rs | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -221,9 +221,13 @@ pub enum R3ToR3 { #[only_if(params.max_depth >= 0)] Compose(Box<R3ToR3>, Box<R3ToR3>), /// f(x, y, z) = (f₁(x), f₂(y), f₃(z)) - #[prob(4)] + #[prob(3)] #[only_if(params.max_depth >= 0)] PerComponent(Box<RToR>, Box<RToR>, Box<RToR>), + /// f(x) = (f₁(x), f₂(x), f₃(x)) + #[prob(3)] + #[only_if(params.max_depth >= 0)] + Multiplex(Box<R3ToR>, Box<R3ToR>, Box<R3ToR>), /// 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); |