summaryrefslogtreecommitdiff
path: root/bitmap.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 /bitmap.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 'bitmap.h')
-rw-r--r--bitmap.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/bitmap.h b/bitmap.h
index 1e35395..5b07914 100644
--- a/bitmap.h
+++ b/bitmap.h
@@ -44,8 +44,30 @@ struct pixel {
static inline pixel<T> from_normalized(const vec3d &v3d) {
return from_normalized(v3d.x / 2.0 + 0.5, v3d.y / 2.0 + 0.5, v3d.z / 2.0 + 0.5);
}
+
+ static inline pixel<T> black() {
+ return pixel<T>{(T) 0, (T) 0, (T) 0};
+ }
};
+template<
+ typename T,
+ typename S,
+ typename = typename std::enable_if<std::is_arithmetic<S>::value, S>::type
+>
+pixel<T> operator*(const pixel<T> &pixel, S scale) {
+ return ::pixel < T > {.r=(T) (pixel.r * scale), .g=(T) (pixel.g * scale), .b=(T) (pixel.b * scale)};
+}
+
+template<
+ typename T,
+ typename S,
+ typename = typename std::enable_if<std::is_arithmetic<S>::value, S>::type
+>
+pixel<T> operator*(S scale, const pixel <T> &pixel) {
+ return ::pixel < T > {.r=(T) (pixel.r * scale), .g=(T) (pixel.g * scale), .b=(T) (pixel.b * scale)};
+}
+
// Mix two colors a and b. Returns a*u + b*v
template<typename T>
inline pixel<T> mix(const pixel<T> &a, const pixel<T> &b, double u, double v) {
@@ -93,7 +115,7 @@ public:
bitmap<T> result{images[0].width, images[0].height};
const auto m = images.size();
const auto n = images[0].content.size();
- uintmax_t acc_r, acc_g, acc_b;
+ uint_fast32_t acc_r, acc_g, acc_b;
for (size_t i = 0; i < n; ++i) {
acc_r = 0;
acc_g = 0;
@@ -103,7 +125,7 @@ public:
acc_g += images[j].content[i].g;
acc_b += images[j].content[i].b;
}
- result.content[i] = pixel<T>{(T) (acc_r / m), (T) (acc_g / m), (T) (acc_b / m)};
+ result.content[i] = pixel<T>{(T) (1.0 * acc_r / m), (T) (1.0 * acc_g / m), (T) (1.0 * acc_b / m)};
}
return result;
}