From 3caba9694f6e6f0f8b51dcffd7619fa04fbe6c29 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 13 Apr 2022 14:42:59 +0800 Subject: Antialiasing. (not parallelized) --- aa.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 aa.h (limited to 'aa.h') diff --git a/aa.h b/aa.h new file mode 100644 index 0000000..d226fda --- /dev/null +++ b/aa.h @@ -0,0 +1,48 @@ +// +// Created by Keuin on 2022/4/13. +// + +#ifndef RT_AA_H +#define RT_AA_H + +#include "vec.h" +#include "viewport.h" +#include +#include + + +// Antialiasing viewport +template +class aa_viewport : public viewport { + unsigned samples; + std::vector> subviews; + +public: + aa_viewport(double width, double height, vec3d viewport_center, unsigned samples) : samples(samples) { + assert(samples >= 1); + subviews = std::vector>{samples, {width, height, viewport_center}}; + } + + virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) { +// // TODO threaded rendering +// std::vector workers{samples}; +// for (size_t i = 0; i < samples; ++i) { +// const auto &th = workers[i]; +// const auto &vw = subviews[i]; +// } + const auto seed = 123456789012345678ULL; + std::mt19937_64 seedgen{seed}; // generates seeds for workers + std::vector> images{}; + for (const auto &view: subviews) { + bias_ctx bc{seedgen()}; + images.push_back(view.render(world, viewpoint, image_width, image_height, bc)); + } + return bitmap::average(images); + } + +}; + +using aa_viewport8b = aa_viewport; + + +#endif //RT_AA_H -- cgit v1.2.3