summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-26 10:23:45 -0500
committerpommicket <pommicket@gmail.com>2023-01-26 10:23:45 -0500
commitaaf92471dc68766faf401ce4bdbb2a271e68c964 (patch)
tree0e7f546bcbdb6f7d1a3f56a428775af9d98974b1
parente19ea7642088db06067b99e6ccd1532df190a9a6 (diff)
RToR, PerComponent
-rw-r--r--src/main.rs3
-rw-r--r--src/sdf.rs24
2 files changed, 24 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 9ac7191..9627936 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,6 @@
/*
@TODO:
-- RnToRn functions (& add back in RToR)
- - also add PerComponent(Box<RToR>,Box<RToR>,Box<RToR>) in R3ToR3
- documentation
-- GenRandom integers (just use 0..u32::MAX and add a modulus)
- is it the function generation or the shader compililng that's slow for large functions?
- record a cool video
*/
diff --git a/src/sdf.rs b/src/sdf.rs
index 1f98958..ad545b6 100644
--- a/src/sdf.rs
+++ b/src/sdf.rs
@@ -198,6 +198,9 @@ pub enum R3ToR3 {
Compose(Box<R3ToR3>, Box<R3ToR3>),
#[prob(4)]
#[only_if(params.max_depth >= 0)]
+ PerComponent(Box<RToR>, Box<RToR>, Box<RToR>),
+ #[prob(4)]
+ #[only_if(params.max_depth >= 0)]
Mix(Box<R3ToR3>, Box<R3ToR3>, Constant),
#[prob(0.5)]
Translate(Constant3),
@@ -238,6 +241,8 @@ pub enum RToR {
Compose(Box<RToR>, Box<RToR>),
#[prob(0)]
Subtract(Constant),
+ #[prob(2)]
+ NToN(Box<RnToRn>)
}
#[derive(GenRandom, Debug, Serialize, Deserialize)]
@@ -547,6 +552,9 @@ impl Function for RToR {
let a_output = a.to_glsl(input, code, var);
b.to_glsl(a_output, code, var)
}
+ NToN(f) => {
+ f.to_glsl(input, code, var, 1)
+ }
}
}
}
@@ -569,6 +577,22 @@ impl Function for R3ToR3 {
let a_output = a.to_glsl(input, code, var);
b.to_glsl(a_output, code, var)
}
+ PerComponent(fx, fy, fz) => {
+ let x_input = var.next();
+ let y_input = var.next();
+ let z_input = var.next();
+ let output = var.next();
+ write_str!(code,
+ "float {x_input} = {input}.x;\n
+ float {y_input} = {input}.y;\n
+ float {z_input} = {input}.z;\n");
+ let x_output = fx.to_glsl(x_input, code, var);
+ let y_output = fy.to_glsl(y_input, code, var);
+ let z_output = fz.to_glsl(z_input, 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);