Sample each pixel multiple times
This commit is contained in:
12
src/camera.c
12
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user