| 85 | } |
| 86 | |
| 87 | pub fn final_image(&mut self, cur_sample: usize) -> (&[Vec3<u8>], Duration) { |
| 88 | let start = std::time::Instant::now(); |
| 89 | |
| 90 | let Self { |
| 91 | accumulated_buffer, |
| 92 | out_buffer, |
| 93 | .. |
| 94 | } = self; |
| 95 | |
| 96 | out_buffer |
| 97 | .par_iter_mut() |
| 98 | .zip(accumulated_buffer.par_iter()) |
| 99 | .for_each(|(px, acc)| { |
| 100 | let scaled = acc / cur_sample as f32; |
| 101 | let gamma_corrected = scaled.sqrt(); |
| 102 | |
| 103 | *px = (gamma_corrected * 255.0) |
| 104 | .clamped(Vec3::zero(), Vec3::broadcast(255.0)) |
| 105 | .numcast() |
| 106 | .unwrap(); |
| 107 | }); |
| 108 | |
| 109 | (&self.out_buffer, start.elapsed()) |
| 110 | } |
| 111 | |
| 112 | pub fn render(&mut self) -> Duration { |
| 113 | // rustc has some problems with borrows even though it should be fine in this case, |