| 23 | /// Scales an accumulated buffer by the sample count, storing each pixel in the corresponding `out` pixel. |
| 24 | #[kernel] |
| 25 | pub unsafe fn scale_buffer(fb: *const Vec3, out: *mut Vec3, samples: u32, view: Viewport) { |
| 26 | let idx_2d = thread::index_2d(); |
| 27 | if idx_2d.x >= view.bounds.x as u32 || idx_2d.y >= view.bounds.y as u32 { |
| 28 | return; |
| 29 | } |
| 30 | let idx = idx_2d.y as usize * view.bounds.x + idx_2d.x as usize; |
| 31 | let original = &*fb.add(idx); |
| 32 | let out = &mut *out.add(idx); |
| 33 | |
| 34 | let scale = 1.0 / samples as f32; |
| 35 | let scaled = original * scale; |
| 36 | *out = scaled; |
| 37 | } |
| 38 | |
| 39 | /// Postprocesses a (scaled) buffer into a final u8 buffer. |
| 40 | #[kernel] |