-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.h
38 lines (28 loc) · 1.03 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
#ifndef COLOR_H
#define COLOR_H
#include "vec3.h"
void write_color(std::ofstream &fout , color &pixel_color , int samples_per_pixel){
/*
- samples_per_pixel = sampling rate (Hz)
- for each pixel #samples_per_pixel rays are passed through that pixel
- then color for each sample is averaged into a single color
- This effectively is supersample antialiasing
*/
double r = pixel_color.x;
double g = pixel_color.y;
double b = pixel_color.z;
/*
instead of adding fractional contribution of each sample each time a ray is passed through the pixel,
just add the resultant full color due to each sample ,
and then divide at the end by the number of samples when writing out the color
*/
/* gamma correction ,with gamma = 2 */
r = sqrt(r / samples_per_pixel);
g = sqrt(g / samples_per_pixel);
b = sqrt(b / samples_per_pixel);
fout << int(255.999 * clamp(r,0.0,0.999)) << ' '
<< int(255.999 * clamp(g,0.0,0.999)) << ' '
<< int(255.999 * clamp(b,0.0,0.999)) << '\n';
return;
}
#endif