diff options
author | Keuin <[email protected]> | 2022-04-13 14:42:59 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-13 14:42:59 +0800 |
commit | 3caba9694f6e6f0f8b51dcffd7619fa04fbe6c29 (patch) | |
tree | 0975252facef9f71931dee7bbd526bcfccf49ad4 /main_simple_scanner.cpp | |
parent | 4ad345447384ae9327cab0977b95d0b67f8bde57 (diff) |
Antialiasing. (not parallelized)
Diffstat (limited to 'main_simple_scanner.cpp')
-rw-r--r-- | main_simple_scanner.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp index bcec163..eaaa8b7 100644 --- a/main_simple_scanner.cpp +++ b/main_simple_scanner.cpp @@ -13,15 +13,21 @@ #include "viewport.h" #include "hitlist.h" #include "sphere.h" +#include "aa.h" #define DEMO_BALL void generate_image(uint16_t image_width, uint16_t image_height, double viewport_width, double focal_length, - double sphere_z, double sphere_r, const std::string &caption = "", unsigned caption_scale = 1) { + double sphere_z, double sphere_r, unsigned samples, const std::string &caption = "", + unsigned caption_scale = 1) { + if (samples == 1) { + std::cerr << "Antialiasing is disabled." << std::endl; + } else { + std::cerr << "Antialiasing Samples: " << samples << std::endl; + } double r = 1.0 * image_width / image_height; - basic_viewport8b vp{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}}; + aa_viewport8b vp{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}, samples}; hitlist8b world; - bias_ctx bias{}; world.add_object(std::make_shared<sphere>( vec3d{0, -100.5, -1}, 100)); // the earth @@ -29,7 +35,7 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport timer tm; tm.start_measure(); auto image = vp.render(world, vec3d::zero(), - image_width, image_height, bias); // camera position as the coordinate origin + image_width, image_height); // camera position as the coordinate origin tm.stop_measure(); if (!caption.empty()) { image.print(caption, @@ -44,22 +50,24 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport } int main(int argc, char **argv) { - if (argc != 7 && argc != 8) { - printf("Usage: %s <image_width> <image_height> <viewport_width> <focal_length> <sphere_z> <sphere_r>\n", + if (argc != 8 && argc != 9) { + printf("Usage: %s <image_width> <image_height> <viewport_width> <focal_length> <sphere_z> <sphere_r> <samples> [<caption>]\n", argv[0]); return 0; } #ifndef NDEBUG std::cerr << "Notice: assertion is enabled." << std::endl; #endif - std::string iw{argv[1]}, ih{argv[2]}, vw{argv[3]}, fl{argv[4]}, sz{argv[5]}, sr{argv[6]}, cap{}; - if (argc == 8) { + std::string iw{argv[1]}, ih{argv[2]}, vw{argv[3]}, fl{argv[4]}, + sz{argv[5]}, sr{argv[6]}, sp{argv[7]}, cap{}; + if (argc == 9) { // with caption - cap = std::string{argv[7]}; + cap = std::string{argv[8]}; } const auto image_width = std::stoul(iw); generate_image(image_width, std::stoul(ih), std::stod(vw), std::stod(fl), - std::stod(sz), std::stod(sr), cap, + std::stod(sz), std::stod(sr), + std::stoul(sp), cap, std::max((int) (1.0 * image_width * 0.015 / 8), 1)); }
\ No newline at end of file |