Skip to content
Snippets Groups Projects
GridSampler.cpp 480 B
Newer Older
Postea's avatar
Postea committed
#include "GridSampler.h"
Postea's avatar
Postea committed
namespace util {
GridSampler::GridSampler(const std::shared_ptr<Sampler>& sampler, size_t n)
Yoel's avatar
Yoel committed
    : sampler(sampler), n(std::ceil(std::sqrt(n))) {
Yoel's avatar
Yoel committed
Vec3 GridSampler::color(float x, float y) const {
	Vec3 color(0, 0, 0);
	for (int xi = 0; xi < n; xi++) {
		for (int yi = 0; yi < n; yi++) {
			float xs = x + (xi + 0.5) / n;
			float ys = y + (yi + 0.5) / n;
Yoel's avatar
Yoel committed
			color = color + sampler->color(xs, ys);
		}
	}
	return color / (n * n);
Yoel's avatar
Yoel committed
}  // namespace util