From 31407cad9a70a8f230486a0234179b2a3cd75780 Mon Sep 17 00:00:00 2001 From: altunenes Date: Sat, 11 May 2024 01:56:00 +0300 Subject: [PATCH] add controls for mandelbulb --- shaders/mandelbulb.wgsl | 16 +++++------ src/mandelbulb.rs | 62 ++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/shaders/mandelbulb.wgsl b/shaders/mandelbulb.wgsl index 4abea26..b790a45 100644 --- a/shaders/mandelbulb.wgsl +++ b/shaders/mandelbulb.wgsl @@ -52,11 +52,11 @@ fn osc(minValue: f32, maxValue: f32, interval: f32, pauseDuration: f32, currentT } } fn mandelbulb(pos: vec3, u_time: TimeUniform) -> f32 { - let dynamicPower: f32 = osc(8.0, 8.0, 20.0, 5.0, u_time.time); + let dynamicPower: f32 = osc(params.iter, params.iter, 20.0, 5.0, u_time.time); var z: vec3 = pos; var dr: f32 = 1.0; var r: f32 = 0.0; - let influence: f32 = 5.05; + let influence: f32 = params.bound; for (var i: i32 = 0; i < MAX_STEPS; i = i + 1) { r = length(z); if (r > BAILOUT) { @@ -80,7 +80,7 @@ fn mandelbulb(pos: vec3, u_time: TimeUniform) -> f32 { return 0.5 * log(r) * r / dr; } fn normal(p: vec3, u_time: TimeUniform) -> vec3 { - let eps: f32 = osc(0.0001, 0.0001, 5.0, 0.0, u_time.time); + let eps: f32 = osc(params.tt, params.tt, 5.0, 0.0, u_time.time); let e: vec3 = vec3(eps, eps, eps); let d: f32 = mandelbulb(p, u_time); @@ -105,9 +105,9 @@ fn getBackground(uv: vec2) -> vec3 { } fn colorize(pos: vec3, normal: vec3, dist: f32, viewDir: vec3, lightDir: vec3) -> vec3 { - let lightTone: vec3 = vec3(1.95, 0.9, 0.85); - let middleTone: vec3 = vec3(0.75, 0.7, 0.65); - let darkTone: vec3 = vec3(1.7, 1.7, 0.1); + let lightTone: vec3 = vec3(params.lambda, params.theta, params.alpha); + let middleTone: vec3 = vec3(params.sigma, params.gamma, params.blue); + let darkTone: vec3 = vec3(params.a, params.b, params.c); let fresnel: f32 = pow(1.0 - max(dot(normal, viewDir), 0.0), 2.0); let fresnelColor: vec3 = mix(lightTone, darkTone, fresnel); @@ -120,7 +120,7 @@ fn colorize(pos: vec3, normal: vec3, dist: f32, viewDir: vec3, li let vibrantColor: vec3 = vec3(0.7, 0.8, 0.1) + 0.1 * colorShift; let branchFactor: f32 = length(pos) % 5.0; - let branchColor: vec3 = vec3(2.0, 3.0, 0.7) * (0.3 + 0.45 * sin(branchFactor * 12.283185)); + let branchColor: vec3 = vec3(params.d, params.e, params.f) * (0.3 + 0.45 * sin(branchFactor * 12.283185)); var combinedColor: vec3 = mix(fresnelColor, depthColor, 0.1); combinedColor = mix(combinedColor, vibrantColor, 0.3); @@ -145,7 +145,7 @@ fn calculateLighting(n: vec3, lightDir: vec3, viewDir: vec3, refl let spec: f32 = pow(max(dot(viewDir, reflectDir), 0.0), SHININESS); let shadow: f32 = smoothstep(0.3, 1.0, diff); diff *= shadow; - let POWER2: f32 = osc(0.1, 0.1, 10.0, 3.0, u_time.time); + let POWER2: f32 = osc(params.g, params.g, 10.0, 3.0, u_time.time); return vec3(POWER2) + diff + SPECULAR_COEFF * spec; } fn dynamicRayMarch(ro: vec3, rd: vec3, minDist: f32, maxDist: f32, u_time: TimeUniform) -> f32 { diff --git a/src/mandelbulb.rs b/src/mandelbulb.rs index 329851a..dc87ae3 100644 --- a/src/mandelbulb.rs +++ b/src/mandelbulb.rs @@ -56,23 +56,23 @@ fn update(app: &App, model: &mut Model, update: Update) { model.settings.show_ui = !model.settings.show_ui; } egui::Window::new("Shader Settings").show(&ctx, |ui| { - ui.add(egui::Slider::new(&mut model.settings.lambda, 0.0..=8.0).text("l")); - ui.add(egui::Slider::new(&mut model.settings.theta, -1.0..=1.0).text("t")); - ui.add(egui::Slider::new(&mut model.settings.alpha, -1.0..=1.0).text("a")); - ui.add(egui::Slider::new(&mut model.settings.sigma, 0.0..=2.0).text("r")); - ui.add(egui::Slider::new(&mut model.settings.gamma, 0.0..=2.0).text("g")); - ui.add(egui::Slider::new(&mut model.settings.blue, 0.0..=3.0).text("b")); - ui.add(egui::Slider::new(&mut model.settings.a, 0.0..=15.0).text("e1")); - ui.add(egui::Slider::new(&mut model.settings.b, 0.0..=1.0).text("r")); - ui.add(egui::Slider::new(&mut model.settings.c, 0.0..=1.0).text("g")); - ui.add(egui::Slider::new(&mut model.settings.d, 0.0..=1.0).text("b")); - // ui.add(egui::Slider::new(&mut model.settings.g, 1.0..=8.00).text("e5")); - ui.add(egui::Slider::new(&mut model.settings.e, 0.002..=3.0).text("c1")); - //ui.add(egui::Slider::new(&mut model.settings.f, 0.002..=3.0).text("c2")); - ui.add(egui::Slider::new(&mut model.settings.iter, -10.0..=10.0).text("iter")); - ui.add(egui::Slider::new(&mut model.settings.bound, 0.0..=5.0).text("time")); + ui.add(egui::Slider::new(&mut model.settings.lambda, 0.0..=10.0).text("color1")); + ui.add(egui::Slider::new(&mut model.settings.theta, 0.0..=10.0).text("color2")); + ui.add(egui::Slider::new(&mut model.settings.alpha, 0.0..=10.0).text("color3")); + ui.add(egui::Slider::new(&mut model.settings.sigma, 0.0..=10.0).text("color4")); + ui.add(egui::Slider::new(&mut model.settings.gamma, 0.0..=10.0).text("color5")); + ui.add(egui::Slider::new(&mut model.settings.blue, 0.0..=10.0).text("color6")); + ui.add(egui::Slider::new(&mut model.settings.a, 0.0..=10.0).text("color7")); + ui.add(egui::Slider::new(&mut model.settings.b, 0.0..=10.0).text("color8")); + ui.add(egui::Slider::new(&mut model.settings.c, 0.0..=10.0).text("color9")); + ui.add(egui::Slider::new(&mut model.settings.d, 0.0..=100.0).text("bcolor1")); + ui.add(egui::Slider::new(&mut model.settings.g, 1.0..=100.00).text("bcolor2")); + ui.add(egui::Slider::new(&mut model.settings.e, 0.002..=100.0).text("bcolor3")); + ui.add(egui::Slider::new(&mut model.settings.f, 0.1..=100.0).text("color")); + ui.add(egui::Slider::new(&mut model.settings.iter, 0.0..=12.0).text("POWER")); + ui.add(egui::Slider::new(&mut model.settings.bound, 0.0..=15.0).text("Branch")); ui.add(egui::Slider::new(&mut model.settings.aa, 1.0..=4.0).text("AA")); - //ui.add(egui::Slider::new(&mut model.settings.tt, 1.0..=250.0).text("speed")); + ui.add(egui::Slider::new(&mut model.settings.tt, 0.00001..=0.1).text("epsilon")); }); let params_data = [model.settings.lambda, model.settings.theta,model.settings.alpha, model.settings.sigma,model.settings.gamma,model.settings.blue,model.settings.aa,model.settings.iter,model.settings.bound,model.settings.tt,model.settings.a,model.settings.b,model.settings.c,model.settings.d,model.settings.e,model.settings.f,model.settings.g]; let params_bytes = bytemuck::cast_slice(¶ms_data); @@ -166,23 +166,23 @@ fn model(app: &App) -> Model { }); let settings = Settings { lambda: 2.0, - theta:0.0, - alpha:0.0, - sigma:0.5, - gamma:0.5, - blue:0.5, + theta:0.9, + alpha:0.85, + sigma:0.75, + gamma:0.7, + blue:0.65, show_ui:true, aa: 2.0, - iter:0.0, - bound:0.5, - tt:18.0, - a:1.0, - b:0.0, - c:0.5, - d:1.0, - e:0.75, - f:2.0, - g:1.0, + iter:8.0, + bound:5.05, + tt:0.0001, + a:1.7, + b:1.7, + c:0.1, + d:2.0, + e:3.0, + f:0.7, + g:0.1, }; let params_data = [settings.lambda, settings.theta, settings.alpha,settings.sigma,settings.gamma,settings.blue,settings.aa,settings.iter,settings.bound,settings.tt,settings.a,settings.b,settings.c,settings.d,settings.e,settings.f,settings.g]; let params_bytes = bytemuck::cast_slice(¶ms_data);