A full-time Systems software engineer.
impl Camera{
fn render(&self, world: &impl Hittable) {
let cap = self.image_width * self.image_height * 3;
let mut image_buf = vec![0; cap];
image_buf
.par_chunks_mut(self.image_width * 3)
.enumerate()
.for_each(|(row, line)| {
for (col, px) in line.as_chunks_mut::<3>().0.iter_mut().enumerate() {
let mut color = Color::default();
for _ in 0..self.pixel_sample_count {
color += self.get_ray(row, col).color(self.max_depth, world);
}
write_color_px(px, self.pixel_samples_scale * color);
}
});
write_image_data_to_disk(&image_buf, self.image_width, self.image_height);
}
}This snippet is from a raytracer I wrote a while back. We iterate over each row of the image buffer in a separate thread, cast a ray from each pixel position, compute pixel color, and write back into the buffer.