From 5f9a664b0f0955cf3e49b5da9ce6d5835cf5f73f Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 14 Apr 2022 20:55:49 +0800 Subject: Make hitlist no longer a generic class (but hitlist::color(...) is now a generic member function). --- aa.h | 2 +- hitlist.h | 4 +--- main_simple_scanner.cpp | 2 +- viewport.h | 8 ++++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/aa.h b/aa.h index ed3bc7f..2c4c4e4 100644 --- a/aa.h +++ b/aa.h @@ -27,7 +27,7 @@ public: delete subviews; } - virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) { + virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) { const unsigned hwcc = std::thread::hardware_concurrency(); std::cerr << "Rendering with " << hwcc << " thread(s)." << std::endl; diff --git a/hitlist.h b/hitlist.h index 02c942a..8625cb5 100644 --- a/hitlist.h +++ b/hitlist.h @@ -28,7 +28,6 @@ //#define DIFFUSE_HEMI // Diffuse with hemispherical scattering, i.e. using a normalized random vector within the hemisphere // A world, T is color depth -template class hitlist { std::vector> objects; @@ -43,6 +42,7 @@ public: } // Given a ray, compute the color. + template pixel color(ray3d r, random_uv_gen_3d &ruvg, uint_fast32_t max_recursion_depth = 64) const { assert(r.decay() == 1.0); while (max_recursion_depth-- > 0) { @@ -114,6 +114,4 @@ public: } }; -using hitlist8b = hitlist; - #endif //RT_HITLIST_H diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp index 67a41d9..806fcfe 100644 --- a/main_simple_scanner.cpp +++ b/main_simple_scanner.cpp @@ -35,7 +35,7 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport } else { vp = new aa_viewport{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}, samples}; } - hitlist world; + hitlist world; world.add_object(std::make_shared( vec3d{0, -100.5, -1}, 100)); // the earth diff --git a/viewport.h b/viewport.h index 1e3eaf0..85d17f5 100644 --- a/viewport.h +++ b/viewport.h @@ -43,7 +43,7 @@ public: template class viewport { public: - virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0; + virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0; virtual ~viewport() = default; }; @@ -61,7 +61,7 @@ public: half_width(width / 2.0), half_height(height / 2.0), center(viewport_center) {} virtual bitmap - render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) override { + render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) override { bias_ctx bc{}; static constexpr uint64_t default_diffuse_seed = 123456789012345678ULL; return render(world, viewpoint, image_width, image_height, bc, default_diffuse_seed); @@ -73,7 +73,7 @@ public: * @param by bias on y axis (0.0 <= by < 1.0) * @return */ - virtual bitmap render(const hitlist &world, vec3d viewpoint, + virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height, bias_ctx &bias, uint64_t diffuse_seed) const { bitmap image{image_width, image_height}; @@ -96,7 +96,7 @@ public: }; // offset on screen plane const auto dir = r + off; // direction vector from camera to current pixel on screen ray3d ray{viewpoint, dir}; // from camera to pixel (on the viewport) - const auto pixel = world.color(ray, ruvg); + const auto pixel = world.color(ray, ruvg); image.set(i + img_hw, -j + img_hh, pixel); } } -- cgit v1.2.3