From 8827f22359f46643ad3893f642035fca9ead8714 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Tue, 23 Sep 2025 15:36:08 +0100 Subject: [PATCH] Sample each pixel multiple times --- src/camera.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/camera.c b/src/camera.c index 05f96d9..86669ea 100644 --- a/src/camera.c +++ b/src/camera.c @@ -8,6 +8,7 @@ #define MAX_ITER 10 #define MIN_T 1e-6 +#define NSAMPLES 100 static const vec3_t lightblue = { 0.4, 0.6, 1.0 }; static const vec3_t white = { 1.0, 1.0, 1.0 }; @@ -97,8 +98,15 @@ void camera_render( .orig = camera->pos, .dir = vec3_unit(pix), }; - const vec3_t col = trace(ray, scene, scene_count); - setpix(col, img_out->pix + (w * y + x)); + + vec3_t colour = black; + for (unsigned i = 0; i < NSAMPLES; ++i) { + const double weight = 1.0 / NSAMPLES; + const vec3_t sample = trace(ray, scene, scene_count); + colour = vec3_add(colour, vec3_scale(sample, weight)); + } + + setpix(colour, img_out->pix + (w * y + x)); } }