Skip to content

Commit

Permalink
add controls for mandelbulb
Browse files Browse the repository at this point in the history
  • Loading branch information
altunenes committed May 10, 2024
1 parent 807dc50 commit 31407ca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions shaders/mandelbulb.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ fn osc(minValue: f32, maxValue: f32, interval: f32, pauseDuration: f32, currentT
}
}
fn mandelbulb(pos: vec3<f32>, 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<f32> = 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) {
Expand All @@ -80,7 +80,7 @@ fn mandelbulb(pos: vec3<f32>, u_time: TimeUniform) -> f32 {
return 0.5 * log(r) * r / dr;
}
fn normal(p: vec3<f32>, u_time: TimeUniform) -> vec3<f32> {
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<f32> = vec3<f32>(eps, eps, eps);

let d: f32 = mandelbulb(p, u_time);
Expand All @@ -105,9 +105,9 @@ fn getBackground(uv: vec2<f32>) -> vec3<f32> {
}

fn colorize(pos: vec3<f32>, normal: vec3<f32>, dist: f32, viewDir: vec3<f32>, lightDir: vec3<f32>) -> vec3<f32> {
let lightTone: vec3<f32> = vec3<f32>(1.95, 0.9, 0.85);
let middleTone: vec3<f32> = vec3<f32>(0.75, 0.7, 0.65);
let darkTone: vec3<f32> = vec3<f32>(1.7, 1.7, 0.1);
let lightTone: vec3<f32> = vec3<f32>(params.lambda, params.theta, params.alpha);
let middleTone: vec3<f32> = vec3<f32>(params.sigma, params.gamma, params.blue);
let darkTone: vec3<f32> = vec3<f32>(params.a, params.b, params.c);

let fresnel: f32 = pow(1.0 - max(dot(normal, viewDir), 0.0), 2.0);
let fresnelColor: vec3<f32> = mix(lightTone, darkTone, fresnel);
Expand All @@ -120,7 +120,7 @@ fn colorize(pos: vec3<f32>, normal: vec3<f32>, dist: f32, viewDir: vec3<f32>, li
let vibrantColor: vec3<f32> = vec3<f32>(0.7, 0.8, 0.1) + 0.1 * colorShift;

let branchFactor: f32 = length(pos) % 5.0;
let branchColor: vec3<f32> = vec3<f32>(2.0, 3.0, 0.7) * (0.3 + 0.45 * sin(branchFactor * 12.283185));
let branchColor: vec3<f32> = vec3<f32>(params.d, params.e, params.f) * (0.3 + 0.45 * sin(branchFactor * 12.283185));

var combinedColor: vec3<f32> = mix(fresnelColor, depthColor, 0.1);
combinedColor = mix(combinedColor, vibrantColor, 0.3);
Expand All @@ -145,7 +145,7 @@ fn calculateLighting(n: vec3<f32>, lightDir: vec3<f32>, viewDir: vec3<f32>, 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<f32>(POWER2) + diff + SPECULAR_COEFF * spec;
}
fn dynamicRayMarch(ro: vec3<f32>, rd: vec3<f32>, minDist: f32, maxDist: f32, u_time: TimeUniform) -> f32 {
Expand Down
62 changes: 31 additions & 31 deletions src/mandelbulb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params_data);
Expand Down Expand Up @@ -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(&params_data);
Expand Down

0 comments on commit 31407ca

Please sign in to comment.