summaryrefslogtreecommitdiff
path: root/bitmap.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-12 11:01:32 +0800
committerKeuin <[email protected]>2022-04-12 11:01:32 +0800
commita97b38299d5f8297d15077160df5439d274bd571 (patch)
treeb2f86794894561a853a6873a37ea14e4f7e7387c /bitmap.h
parente83da6c36b39e6f8de35fc7e1c3caf8041cfe325 (diff)
Make object::hit provides hit time t.
Visualize normal vector at hit point. Add pixel<T>::from_normalized(const vec3d&) for visualizing normal vector.
Diffstat (limited to 'bitmap.h')
-rw-r--r--bitmap.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/bitmap.h b/bitmap.h
index 31b9053..09f3711 100644
--- a/bitmap.h
+++ b/bitmap.h
@@ -31,10 +31,15 @@ struct pixel {
* Create a pixel with given depth, from normalized color values.
* For example: for 8bit pixel, with (1, 0.5, 0.25), we get: (255, 127, 63).
*/
- static pixel<T> from_normalized(double r, double g, double b) {
+ static inline pixel<T> from_normalized(double r, double g, double b) {
const auto mod = (1ULL << (sizeof(T) * 8U)) - 1ULL;
return pixel<T>{.r = (T) (mod * r), .g = (T) (mod * g), .b = (T) (mod * b)};
}
+
+ // v3d must be a normalized vector
+ 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);
+ }
};
// Mix two colors a and b. Returns a*u + b*v