mirror of
https://github.com/Manoj-HV30/multithreaded-raytracer.git
synced 2026-05-16 19:35:24 +00:00
38 lines
944 B
C++
38 lines
944 B
C++
#ifndef COLOR_H
|
|
#define COLOR_H
|
|
#include "interval.h"
|
|
|
|
#include "vec3.h"
|
|
|
|
#include <iostream>
|
|
|
|
using color = vec3;
|
|
inline double linear_to_gamma(double linear_component)
|
|
{
|
|
if (linear_component > 0)
|
|
return std::sqrt(linear_component);
|
|
|
|
return 0;
|
|
}
|
|
inline void write_color(std::ostream& out, const color& pixel_color) {
|
|
auto r = pixel_color.x();
|
|
auto g = pixel_color.y();
|
|
auto b = pixel_color.z();
|
|
|
|
// Apply a linear to gamma transform for gamma 2
|
|
r = linear_to_gamma(r);
|
|
g = linear_to_gamma(g);
|
|
b = linear_to_gamma(b);
|
|
|
|
// Translate the [0,1] component values to the byte range [0,255].
|
|
static const interval intensity(0.000, 0.999);
|
|
int rbyte = int(256 * intensity.clamp(r));
|
|
int gbyte = int(256 * intensity.clamp(g));
|
|
int bbyte = int(256 * intensity.clamp(b));
|
|
|
|
// Write out the pixel color components.
|
|
out << rbyte << ' ' << gbyte << ' ' << bbyte << '\n';
|
|
}
|
|
|
|
#endif
|