diff --git a/pathtracer-cli/src/main.rs b/pathtracer-cli/src/main.rs index fee0c878..ba2817ad 100644 --- a/pathtracer-cli/src/main.rs +++ b/pathtracer-cli/src/main.rs @@ -98,6 +98,7 @@ fn create_ray_logger(thread: u32) -> RayLogger { fn worker_thread( thread: u32, pathtracer: &Pathtracer, + camera: &Pinhole, size: Size, iterations: u32, tx: &Sender, @@ -107,7 +108,13 @@ fn worker_thread( let mut ray_logger = create_ray_logger(thread); for iteration in 0..iterations { let t1 = Instant::now(); - pathtracer.render(iteration as u16, &mut ray_logger, &mut buffer, &mut rng); + pathtracer.render( + iteration as u16, + camera, + &mut ray_logger, + &mut buffer, + &mut rng, + ); let t2 = Instant::now(); let duration = t2 - t1; tx.send(duration).unwrap(); @@ -179,7 +186,6 @@ fn main() { max_bounces: args.max_bounces, scene, kdtree, - camera, }; thread::scope(|s| { @@ -189,8 +195,16 @@ fn main() { .map(|i| { let tx = tx.clone(); let pathtracer = &pathtracer; + let camera = &camera; s.spawn(move || { - worker_thread(i, pathtracer, args.size, args.iterations_per_thread, &tx) + worker_thread( + i, + pathtracer, + camera, + args.size, + args.iterations_per_thread, + &tx, + ) }) }) .collect::>(); diff --git a/tracing/src/pathtracer.rs b/tracing/src/pathtracer.rs index 8a6c1717..fd1baa73 100644 --- a/tracing/src/pathtracer.rs +++ b/tracing/src/pathtracer.rs @@ -16,7 +16,6 @@ pub struct Pathtracer { pub max_bounces: u8, pub scene: Scene, pub kdtree: KdTree, - pub camera: Pinhole, } struct Pixel<'a> { @@ -141,6 +140,7 @@ impl Pathtracer { pub fn render( &self, iteration: u16, + camera: &Pinhole, ray_logger: &mut RayLogger, buffer: &mut ImageBuffer, rng: &mut SmallRng, @@ -151,7 +151,7 @@ impl Pathtracer { let pixel_center = Vector2::new(x as f32, y as f32) + uniform_sample_unit_square(rng); let scene_direction = pixel_center.component_div(&buffer_size); - let ray = self.camera.ray(scene_direction.x, scene_direction.y); + let ray = camera.ray(scene_direction.x, scene_direction.y); let mut pixel = Pixel { iteration, x: x as u16,