diff options
author | Keuin <[email protected]> | 2022-04-12 11:01:32 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-12 11:01:32 +0800 |
commit | a97b38299d5f8297d15077160df5439d274bd571 (patch) | |
tree | b2f86794894561a853a6873a37ea14e4f7e7387c /bitmap.h | |
parent | e83da6c36b39e6f8de35fc7e1c3caf8041cfe325 (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.h | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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 |