Size the box to the SDF

This commit is contained in:
2025-06-23 23:22:11 +01:00
parent 094203bcfb
commit 5725d92c0b
3 changed files with 23 additions and 3 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ layout(location = 0) in vec3 position;
layout(location = 0) out vec4 pos; layout(location = 0) out vec4 pos;
void main() { void main() {
pos = vec4(position, 1.); pos = vec4((position * pc.dimensions) + pc.lowest_corner, 1.);
vec4 worldview = camera_uniforms.view * pc.world * pos; vec4 worldview = camera_uniforms.view * pc.world * pos;
gl_Position = camera_uniforms.proj * worldview; gl_Position = camera_uniforms.proj * worldview;
} }
+2
View File
@@ -3,6 +3,8 @@
layout(push_constant)uniform PushConstantData{ layout(push_constant)uniform PushConstantData{
mat4 world; mat4 world;
vec3 dimensions;
vec3 lowest_corner;
}pc; }pc;
layout(set=0,binding=0)uniform Lights{ layout(set=0,binding=0)uniform Lights{
+19 -1
View File
@@ -92,6 +92,7 @@ mod ssa;
mod instruction_set; mod instruction_set;
mod interpreter; mod interpreter;
use crate::interpreter::Interpreter;
fn main() -> Result<(), impl Error> { fn main() -> Result<(), impl Error> {
CombinedLogger::init(vec![ CombinedLogger::init(vec![
@@ -957,7 +958,7 @@ impl App {
}, },
); );
rcx.recreate_pipelines = false; rcx.recreate_pipelines = false;
if (rcx.new_object_start.is_some()) { if rcx.new_object_start.is_some() {
let end = Instant::now(); let end = Instant::now();
info!( info!(
"Object recreation took {} milliseconds", "Object recreation took {} milliseconds",
@@ -1021,6 +1022,8 @@ impl App {
let pc = implicit_vs::PushConstantData { let pc = implicit_vs::PushConstantData {
world: Mat4::IDENTITY.to_cols_array_2d(), world: Mat4::IDENTITY.to_cols_array_2d(),
dimensions: Vec3::ONE.to_array().into(),
lowest_corner: Vec3::ZERO.into(),
}; };
let uniform_data = implicit_vs::Camera { let uniform_data = implicit_vs::Camera {
@@ -1157,6 +1160,21 @@ impl App {
) )
* Mat4::from_scale(csg.scale * 2.0)) * Mat4::from_scale(csg.scale * 2.0))
.to_cols_array_2d(); .to_cols_array_2d();
let mut interpreter = Interpreter::new(csg);
let highest_corner = Vec3::new(
10000.0 - interpreter.scene(Vec3::new(10000.0, 0.0, 0.0)),
10000.0 - interpreter.scene(Vec3::new(0.0, 10000.0, 0.0)),
10000.0 - interpreter.scene(Vec3::new(0.0, 0.0, 10000.0)),
);
let lowest_corner = Vec3::new(
-10000.0 + interpreter.scene(Vec3::new(-10000.0, 0.0, 0.0)),
-10000.0 + interpreter.scene(Vec3::new(0.0, -10000.0, 0.0)),
-10000.0 + interpreter.scene(Vec3::new(0.0, 0.0, -10000.0)),
);
push_constants.dimensions = (highest_corner - lowest_corner).to_array().into();
push_constants.lowest_corner = lowest_corner.into();
builder builder
.push_constants(rcx.implicit_pipeline.layout().clone(), 0, push_constants) .push_constants(rcx.implicit_pipeline.layout().clone(), 0, push_constants)
.unwrap(); .unwrap();