From e46e1c4033b9d96325de3295eb442a5b1fa19f19 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 13 Apr 2022 23:31:47 +0800 Subject: Global diffuse lighting. (gamma not corrected) Some operations on pixel. Make ray3 support copy semantic. Fix vec3 operands does not filter out vec3-vec3 as parameters. random_uv_gen generating random unit vectors. --- viewport.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'viewport.h') diff --git a/viewport.h b/viewport.h index 74bdfcd..30a22dd 100644 --- a/viewport.h +++ b/viewport.h @@ -44,6 +44,7 @@ template class viewport { public: virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0; + virtual ~viewport() = default; }; @@ -64,7 +65,8 @@ public: virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) override { bias_ctx bc{}; - return render(world, viewpoint, image_width, image_height, bc); + static constexpr uint64_t default_diffuse_seed = 123456789012345678ULL; + return render(world, viewpoint, image_width, image_height, bc, default_diffuse_seed); } /** @@ -75,8 +77,9 @@ public: */ virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height, - bias_ctx &bias) const { + bias_ctx &bias, uint64_t diffuse_seed) const { bitmap image{image_width, image_height}; + random_uv_gen_3d ruvg{diffuse_seed}; double bx, by; const auto r = center - viewpoint; const int img_hw = image_width / 2, img_hh = image_height / 2; @@ -94,8 +97,8 @@ public: .z=0.0 }; // offset on screen plane const auto dir = r + off; // direction vector from camera to current pixel on screen - const ray3d ray{viewpoint, dir}; // from camera to pixel (on the viewport) - const auto pixel = world.color(ray); + ray3d ray{viewpoint, dir}; // from camera to pixel (on the viewport) + const auto pixel = world.color(ray, ruvg); image.set(i + img_hw, -j + img_hh, pixel); } } -- cgit v1.2.3