summaryrefslogtreecommitdiff
path: root/viewport.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-13 23:31:47 +0800
committerKeuin <[email protected]>2022-04-13 23:31:47 +0800
commite46e1c4033b9d96325de3295eb442a5b1fa19f19 (patch)
tree27a3976278b006b9dc862ba9fdd7cde338ce43e4 /viewport.h
parent25ee3cfafea166f2dd155c07b5d43ba90d5bd994 (diff)
Global diffuse lighting. (gamma not corrected)
Some operations on pixel<T>. Make ray3 support copy semantic. Fix vec3 operands does not filter out vec3-vec3 as parameters. random_uv_gen generating random unit vectors.
Diffstat (limited to 'viewport.h')
-rw-r--r--viewport.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/viewport.h b/viewport.h
index 74bdfcd..30a22dd 100644
--- a/viewport.h
+++ b/viewport.h
@@ -44,6 +44,7 @@ template<typename T>
class viewport {
public:
virtual bitmap<T> render(const hitlist<T> &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0;
+
virtual ~viewport() = default;
};
@@ -64,7 +65,8 @@ public:
virtual bitmap<T>
render(const hitlist<T> &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<T> render(const hitlist<T> &world, vec3d viewpoint,
uint16_t image_width, uint16_t image_height,
- bias_ctx &bias) const {
+ bias_ctx &bias, uint64_t diffuse_seed) const {
bitmap<T> 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);
}
}