From 3f225bde7ff4fcd3d1157d287521aca1365baa79 Mon Sep 17 00:00:00 2001 From: Jonathan Flueren Date: Tue, 13 Sep 2022 23:30:17 +0200 Subject: [PATCH] Viking room first tries --- obj/viking_room.obj | 5 +---- src/main.rs | 54 +++++++++++++++++++++++++++++++-------------- src/material.rs | 4 ++-- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/obj/viking_room.obj b/obj/viking_room.obj index 7cc74b1..5f99714 100644 --- a/obj/viking_room.obj +++ b/obj/viking_room.obj @@ -1,7 +1,4 @@ -# Blender v2.82 (sub 7) OBJ File: '' -# www.blender.org -mtllib viking_room.mtl -o mesh_all1_Texture1_0 + v -0.573651 0.001530 0.713748 v -0.573651 0.151382 -0.000154 v -0.573651 0.164474 0.619081 diff --git a/src/main.rs b/src/main.rs index 6f6eb77..3fa4450 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,17 +67,17 @@ fn main() { // Image let aspect_ratio = 10.0 / 7.5; //16.0 / 9.0; - let image_width = 400; + let image_width = 600; let image_height = (image_width as f64 / aspect_ratio) as u32; - let samples_per_pixel = 100_u32; - let max_depth = 50; + let samples_per_pixel = 1_u32; + let max_depth = 30; let antialiasing_threshold = 0.2; // at what diff between two colors will a pixel be antialiased - let vfov = 40.0; - let lookfrom = Point3::new(2.0, 0.8, 3.0); - let lookat = Point3::new(0.0, 0.0, 0.0); + let vfov = 43.0; + let lookfrom = Point3::new(2.0, 1.0, 1.0); + let lookat = Point3::new(0.0, 0.2, 0.0); let vup = Vec3::new(0.0, 1.0, 0.0); - let dist_to_focus = 3.0; + let dist_to_focus = 1.0; let aperture = 0.0; // disable depth of field // limit rayon multithreading thread count @@ -88,7 +88,7 @@ fn main() { // World eprintln!("[1/4] Loading meshes from file..."); - let world = from_obj("obj/suzanne.obj"); + let world = from_obj("obj/viking_room.obj"); // let world = random_world(); // Camera @@ -137,6 +137,26 @@ fn main() { .collect(); bar.finish_and_clear(); + // no antialiasing + if samples_per_pixel == 1_u32 { + eprintln!("[4/4] Exporting image to disk..."); + (0..image_height).into_iter().rev().for_each(|j| { + (0..image_width).into_iter().for_each(|i| { + color::put_color( + &mut image, + &color_lines[(image_height - j - 1) as usize][i as usize], + i, + image_height - j - 1, + 1, + ); + }) + }); + + image.save(default_file).unwrap(); + + return; + } + eprintln!("[3/4] Antialiasing image..."); let mut antialiasing: Vec> = Vec::new(); let mut antialiasing_counter = 0; @@ -262,13 +282,13 @@ fn from_obj(path: &str) -> HittableList { ))); */ - let material = Arc::new(Lambertian::new(&Color::new( - 77.0 / 255.0, - 77.0 / 255.0, - 118.0 / 255.0, - ))); + //let material = Arc::new(Lambertian::new(&Color::new( + // 77.0 / 255.0, + // 77.0 / 255.0, + // 118.0 / 255.0, + //))); //let material = Arc::new(Dielectric::new(2.0)); - //let material = Arc::new(Metal::new(&Color::new(0.9, 0.9, 0.7), 1.0)); + let material = Arc::new(Metal::new(&Color::new(0.7, 0.7, 0.8), 0.0)); //let material = Arc::new(Rainbow::new()); let cornell_box = tobj::load_obj(path, &tobj::OFFLINE_RENDERING_LOAD_OPTIONS); @@ -337,18 +357,18 @@ fn from_obj(path: &str) -> HittableList { world.add(Box::::new(Triangle::new( Point3::new( mesh.positions[3 * index_a] as f64, - mesh.positions[3 * index_a + 1] as f64, mesh.positions[3 * index_a + 2] as f64, + mesh.positions[3 * index_a + 1] as f64, ), Point3::new( mesh.positions[3 * index_b] as f64, - mesh.positions[3 * index_b + 1] as f64, mesh.positions[3 * index_b + 2] as f64, + mesh.positions[3 * index_b + 1] as f64, ), Point3::new( mesh.positions[3 * index_c] as f64, - mesh.positions[3 * index_c + 1] as f64, mesh.positions[3 * index_c + 2] as f64, + mesh.positions[3 * index_c + 1] as f64, ), normal_avg, material.clone(), diff --git a/src/material.rs b/src/material.rs index 2b90b45..409e928 100644 --- a/src/material.rs +++ b/src/material.rs @@ -77,7 +77,7 @@ impl Material for Metal { *scattered = Ray::new(rec.p, reflected + self.fuzz * Vec3::random_in_unit_sphere()); *attenuation = self.albedo.clone(); - return Vec3::dot(scattered.direction(), rec.normal) > 0.0; + return true;//Vec3::dot(scattered.direction(), rec.normal) > 0.0; } } @@ -97,7 +97,7 @@ impl Material for Mirror { ) -> bool { if utility::random_f64() > 0.8 { // Reflektiert - let reflected = Vec3::reflect(&Vec3::unit_vector(r_in.direction()), &rec.normal); + let reflected = Vec3::reflect(&r_in.direction(), &rec.normal); *scattered = Ray::new(rec.p, reflected); *attenuation = self.albedo.clone();