Sample each pixel multiple times

This commit is contained in:
Camden Dixie O'Brien
2025-09-23 15:35:26 +01:00
parent 790882417a
commit d07ccec5ba

View File

@@ -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));
}
}