-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.h
45 lines (31 loc) · 1.12 KB
/
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
38
39
40
41
42
43
44
45
#ifndef COLOR_H
#define COLOR_H
#include "vec3.h"
#include <iostream>
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;
//Gamma = 2
r = sqrt(scale * r);
g = sqrt(scale * g);
b = sqrt(scale * b);
//Write translated (0-255) value of each color component
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';
}
color writeColor(color pixelColor, int samplesPerPixel){
auto r = pixelColor.x();
auto g = pixelColor.y();
auto b = pixelColor.z();
auto scale = 1.0 / samplesPerPixel;
//Gamma = 2
r = sqrt(scale * r);
g = sqrt(scale * g);
b = sqrt(scale * b);
//Write translated (0-255) value of each color component
return color(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)));
}
#endif