-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor.h
More file actions
45 lines (39 loc) · 1.01 KB
/
color.h
File metadata and controls
45 lines (39 loc) · 1.01 KB
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 "interval.h"
#include "vec3.h"
using color = vec3;
// approximation: gamma 2 inverse
inline float linear_to_gamma(float linear_intensity)
{
if (linear_intensity > 0)
{
return std::sqrt(linear_intensity);
}
return 0;
}
inline float to_sdr(float intensity)
{
static const interval sdr_range(0.000, 1.000);
return sdr_range.clamp(linear_to_gamma(intensity));
}
inline void write_color(std::vector<float>& out, const color& pixel_color)
{
// auto r = pixel_color.x();
// auto g = pixel_color.y();
// auto b = pixel_color.z();
//
// // PPM only support SDR. TODO: Use another format to achieve HDR
// unsigned char rbyte = to_sdr(r);
// unsigned char gbyte = to_sdr(g);
// unsigned char bbyte = to_sdr(b);
//
// // Write out color
// out.push_back(rbyte);
// out.push_back(gbyte);
// out.push_back(bbyte);
out.push_back(static_cast<float>(pixel_color.x()));
out.push_back(static_cast<float>(pixel_color.y()));
out.push_back(static_cast<float>(pixel_color.z()));
}
#endif