toytracer/color.h
2020-06-06 14:57:55 +02:00

26 lines
622 B
C++

#ifndef COLOR_H
#define COLOR_H
#include <iostream>
#include <cmath>
#include "vec3.h"
#include "util.h"
void write_color(std::ostream &out, Color pixel_color, int sample_per_pixel) {
auto r = pixel_color.x();
auto g = pixel_color.y();
auto b = pixel_color.z();
auto scale = 1.0 / sample_per_pixel;
r = std::sqrt(scale * r);
g = std::sqrt(scale * g);
b = std::sqrt(scale * b);
out << static_cast<int>(256 * clamp(r, 0.0, 0.999)) << " "
<< static_cast<int>(256 * clamp(g, 0.0, 0.999)) << " "
<< static_cast<int>(256 * clamp(b, 0.0, 0.999)) << "\n";
}
#endif // COLOR_H