added scaling with sane default

This commit is contained in:
TÁNCZOS Vilmos Zsombor 2025-06-01 00:17:27 +02:00
parent 3528c56be5
commit 540713daae
2 changed files with 12 additions and 3 deletions

View file

@ -14,13 +14,17 @@ struct VoluMaterial {
max_steps: i32,
ray_epsilon: f32,
normal_epsilon: f32,
scale: f32,
}
@group(2) @binding(100)
var<storage, read> volu_material: VoluMaterial;
fn mandelbulb_sdf(p: vec3<f32>) -> f32 {
var z = p;
let scale = volu_material.scale;
let p_scaled = p / scale;
var z = p_scaled;
var dr = 1.0;
var r = 0.0;
let power = volu_material.power;
@ -44,10 +48,10 @@ fn mandelbulb_sdf(p: vec3<f32>) -> f32 {
sin(new_theta) * cos(new_phi),
sin(new_theta) * sin(new_phi),
cos(new_theta)
) + p;
) + p_scaled;
}
return 0.5 * log(max(r, 0.001)) * r / dr;
return 0.5 * log(max(r, 0.001)) * r / dr * scale;
}
fn mandelbulb_normal(p: vec3<f32>) -> vec3<f32> {

View file

@ -28,6 +28,7 @@ struct MandelbulbSettings {
max_steps: i32,
ray_epsilon: f32,
normal_epsilon: f32,
scale: f32,
}
impl Default for MandelbulbSettings {
@ -39,6 +40,7 @@ impl Default for MandelbulbSettings {
max_steps: 128,
ray_epsilon: 0.001,
normal_epsilon: 0.001,
scale: 0.7,
}
}
}
@ -63,6 +65,7 @@ fn update_volu_material(
max_steps,
ray_epsilon,
normal_epsilon,
scale,
} = *settings;
let volu_storage = MandelbulbStorage {
@ -74,6 +77,7 @@ fn update_volu_material(
max_steps,
ray_epsilon,
normal_epsilon,
scale,
};
buffer.set_data(volu_storage);
@ -114,4 +118,5 @@ pub struct MandelbulbStorage {
max_steps: i32,
ray_epsilon: f32,
normal_epsilon: f32,
scale: f32,
}