diff --git a/kdtree-tester-cli/src/ray_bouncer.rs b/kdtree-tester-cli/src/ray_bouncer.rs index 9a96c4a..03b2e87 100644 --- a/kdtree-tester-cli/src/ray_bouncer.rs +++ b/kdtree-tester-cli/src/ray_bouncer.rs @@ -27,8 +27,8 @@ impl RayBouncer { ray: &Ray, t_range: RangeInclusive, ) -> Option { - let indices = 0u32..self.scene.geometries.len() as u32; - intersect_closest_geometry(&self.scene.geometries, indices, ray, t_range) + let indices = 0u32..self.scene.geometries().len() as u32; + intersect_closest_geometry(self.scene.geometries(), indices, ray, t_range) } fn checked_ray_intersect( @@ -38,7 +38,7 @@ impl RayBouncer { ) -> CheckedIntersection { let kdtree = self .kdtree - .intersect(&self.scene.geometries, ray, t_range.clone()); + .intersect(self.scene.geometries(), ray, t_range.clone()); let reference = self.reference_ray_intersect(ray, t_range); CheckedIntersection { ray: ray.clone(), @@ -76,7 +76,7 @@ impl RayBouncer { let incoming_fails = self .scene - .lights + .lights() .iter() .filter_map(|light| { let shadow_ray = Ray::between(point_above, sample_light(light, &mut rng)); diff --git a/kdtree-tester-cli/src/ray_tester.rs b/kdtree-tester-cli/src/ray_tester.rs index da4185e..8ebc4a1 100644 --- a/kdtree-tester-cli/src/ray_tester.rs +++ b/kdtree-tester-cli/src/ray_tester.rs @@ -19,10 +19,10 @@ pub(crate) fn kdtree_ray_tester( let scene = Scene::read_obj_file_with_print_logging(&input); println!("Building kdtree..."); - let kdtree = build_kdtree(&scene.geometries, &sah); + let kdtree = build_kdtree(scene.geometries(), &sah); println!("Testing up to {} rays...", size.x * size.y * bounces); - let camera = Pinhole::new(scene.cameras[0].clone(), size.as_uvec2()); + let camera = Pinhole::new(scene.cameras()[0].clone(), size.as_uvec2()); let bouncer = RayBouncer { scene, kdtree, diff --git a/pathtracer-cli/src/main.rs b/pathtracer-cli/src/main.rs index 8faf20e..9a4b48a 100644 --- a/pathtracer-cli/src/main.rs +++ b/pathtracer-cli/src/main.rs @@ -159,7 +159,7 @@ fn main() { println!("Building kdtree..."); let kdtree = build_kdtree( - &scene.geometries, + scene.geometries(), &SahCost { traverse_cost: args.traverse_cost, intersect_cost: args.intersect_cost, @@ -172,7 +172,7 @@ fn main() { "Rendering {} px image with {} thread(s) and {} total iteration(s)...", args.size, args.threads, total_iterations, ); - let camera = Pinhole::new(scene.cameras[0].clone(), args.size.as_uvec2()); + let camera = Pinhole::new(scene.cameras()[0].clone(), args.size.as_uvec2()); let pathtracer = Pathtracer { max_bounces: args.max_bounces, scene, diff --git a/pathtracer-gui/src/main.rs b/pathtracer-gui/src/main.rs index c1ae033..107e82b 100644 --- a/pathtracer-gui/src/main.rs +++ b/pathtracer-gui/src/main.rs @@ -30,7 +30,7 @@ fn main() { println!("Building kdtree..."); let kdtree = build_kdtree( - &scene.geometries, + scene.geometries(), &SahCost { traverse_cost: args.traverse_cost, intersect_cost: args.intersect_cost, @@ -45,7 +45,7 @@ fn main() { }; miniquad::start(Conf::default(), move || { - let camera = pathtracer.scene.cameras[0].clone(); + let camera = pathtracer.scene.cameras()[0].clone(); Box::new(Stage::new(pathtracer, camera)) }); } diff --git a/scene/src/lib.rs b/scene/src/lib.rs index 7b950db..33a4fbc 100644 --- a/scene/src/lib.rs +++ b/scene/src/lib.rs @@ -45,12 +45,12 @@ struct TriangleProperties { } pub struct Scene { - pub geometries: Vec, + geometries: Vec, properties: Vec, materials: Vec, - pub cameras: Vec, - pub lights: Vec, - pub environment: Vec3, + cameras: Vec, + lights: Vec, + environment: Vec3, } fn blend_from_mtl(image_directory: &Path, material: &mtl::Material) -> Material { @@ -182,6 +182,26 @@ impl Scene { scene } + #[inline] + pub fn geometries(&self) -> &[Geometry] { + &self.geometries + } + + #[inline] + pub fn cameras(&self) -> &[Camera] { + &self.cameras + } + + #[inline] + pub fn lights(&self) -> &[SphericalLight] { + &self.lights + } + + #[inline] + pub fn environment(&self) -> Vec3 { + self.environment + } + #[inline] pub fn get_material(&self, index: u32) -> &Material { &self.materials[self.properties[index as usize].material_index] diff --git a/tracing/src/pathtracer.rs b/tracing/src/pathtracer.rs index 42b7c20..a855244 100644 --- a/tracing/src/pathtracer.rs +++ b/tracing/src/pathtracer.rs @@ -28,7 +28,7 @@ impl Pathtracer { for bounce in 1..=self.max_bounces { let intersection = self .kdtree - .intersect(&self.scene.geometries, &ray, 0.0..=f32::MAX); + .intersect(self.scene.geometries(), &ray, 0.0..=f32::MAX); ray_logger .log_ray( &intersection @@ -39,7 +39,7 @@ impl Pathtracer { ) .unwrap(); if intersection.is_none() { - return accumulated_radiance + accumulated_transport * self.scene.environment; + return accumulated_radiance + accumulated_transport * self.scene.environment(); } let intersection = intersection.unwrap(); let intersection_index = intersection.index; @@ -60,14 +60,14 @@ impl Pathtracer { let incoming_radiance: Vec3 = self .scene - .lights + .lights() .iter() .map(|light| { // TODO: Offset should depend on incoming direction, not only surface normal. let shadow_ray = Ray::between(point_above, sample_light(light, rng)); let intersection = self.kdtree - .intersect(&self.scene.geometries, &shadow_ray, 0.0..=1.0); + .intersect(self.scene.geometries(), &shadow_ray, 0.0..=1.0); ray_logger .log_shadow(&shadow_ray, bounce, intersection.is_some()) .unwrap();