| 39 | /// Postprocesses a (scaled) buffer into a final u8 buffer. |
| 40 | #[kernel] |
| 41 | pub unsafe fn postprocess(fb: *const Vec3, out: *mut vek::Vec3<u8>, view: Viewport) { |
| 42 | let idx_2d = thread::index_2d(); |
| 43 | if idx_2d.x >= view.bounds.x as u32 || idx_2d.y >= view.bounds.y as u32 { |
| 44 | return; |
| 45 | } |
| 46 | let idx = idx_2d.y as usize * view.bounds.x + idx_2d.x as usize; |
| 47 | let original = &*fb.add(idx); |
| 48 | let out = &mut *out.add(idx); |
| 49 | // gamma=2.0 |
| 50 | let gamma_corrected = original.sqrt(); |
| 51 | |
| 52 | *out = (gamma_corrected * 255.0) |
| 53 | .clamped(Vec3::zero(), Vec3::broadcast(255.0)) |
| 54 | .numcast() |
| 55 | .unwrap(); |
| 56 | } |