Skip to content

Commit

Permalink
Make the camera a render argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Oom committed May 11, 2024
1 parent fea9df3 commit 0d1f834
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions pathtracer-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>,
Expand All @@ -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();
Expand Down Expand Up @@ -179,7 +186,6 @@ fn main() {
max_bounces: args.max_bounces,
scene,
kdtree,
camera,
};

thread::scope(|s| {
Expand All @@ -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::<Vec<_>>();
Expand Down
4 changes: 2 additions & 2 deletions tracing/src/pathtracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub struct Pathtracer {
pub max_bounces: u8,
pub scene: Scene,
pub kdtree: KdTree,
pub camera: Pinhole,
}

struct Pixel<'a> {
Expand Down Expand Up @@ -141,6 +140,7 @@ impl Pathtracer {
pub fn render(
&self,
iteration: u16,
camera: &Pinhole,
ray_logger: &mut RayLogger,
buffer: &mut ImageBuffer,
rng: &mut SmallRng,
Expand All @@ -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,
Expand Down

0 comments on commit 0d1f834

Please sign in to comment.