aboutsummaryrefslogtreecommitdiffstats
path: root/src/color.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2020-12-21 01:26:14 +0100
committerladevieq <ladevie.quentin@gmail.com>2020-12-21 01:26:14 +0100
commit92d66138f53645f3400f633c9821a6fa36f589e0 (patch)
treea23bc2f45afa5858095ba5525a61aad530fdddd6 /src/color.cpp
parent25ac4fd14409a0d82bbaaaf4018674c3bdd46b03 (diff)
Add lambertian reflection to spheres
Diffstat (limited to 'src/color.cpp')
-rw-r--r--src/color.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/color.cpp b/src/color.cpp
index 3cd3e60..565516f 100644
--- a/src/color.cpp
+++ b/src/color.cpp
@@ -2,10 +2,16 @@
#include "rt.hpp"
void write_color(std::ostream& out, const color& pixel_color, uint32_t samples_per_pixel) {
+ auto r = pixel_color.x;
+ auto g = pixel_color.y;
+ auto b = pixel_color.z;
+
auto scale = 1.0 / samples_per_pixel;
- auto scaled_color = pixel_color * scale;
+ r = sqrt(r * scale);
+ g = sqrt(g * scale);
+ b = sqrt(b * scale);
- out << static_cast<uint32_t>(256.0 * clamp(scaled_color.x, 0.0, 0.999)) << ' '
- << static_cast<uint32_t>(256.0 * clamp(scaled_color.y, 0.0, 0.999)) << ' '
- << static_cast<uint32_t>(256.0 * clamp(scaled_color.z, 0.0, 0.999)) << std::endl;
+ out << static_cast<uint32_t>(256.0 * clamp(r, 0.0, 0.999)) << ' '
+ << static_cast<uint32_t>(256.0 * clamp(g, 0.0, 0.999)) << ' '
+ << static_cast<uint32_t>(256.0 * clamp(b, 0.0, 0.999)) << std::endl;
}