-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.h
37 lines (26 loc) · 885 Bytes
/
Color.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include "Vec3.h"
#include <iostream>
inline double LinearToGamma(double linearComponent){
return sqrt(linearComponent);
}
inline Color LinearToGamma(Color color){
return Color(LinearToGamma(color.x()),LinearToGamma(color.y()), LinearToGamma(color.z()));
}
void WriteColor(std::ostream &out, Color pixelColor, int samplesPerPixel){
auto r = pixelColor.x();
auto g = pixelColor.y();
auto b = pixelColor.z();
auto scale = 1.0 / samplesPerPixel;
r *= scale;
g *= scale;
b *= scale;
//Applying linear to gamma
r = LinearToGamma(r);
g = LinearToGamma(g);
b = LinearToGamma(b);
static const Interval intensity(0.000, 0.999);
out << static_cast<int>(256 * intensity.Clamp(r)) << ' '
<< static_cast<int>(256 * intensity.Clamp(g)) << ' '
<< static_cast<int>(256 * intensity.Clamp(b)) << '\n';
}