-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.h
36 lines (28 loc) · 923 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
//
// Created by Robin Leman on 2021-08-21.
// Based of : https://raytracing.github.io/books/RayTracingInOneWeekend.html
//
#ifndef COLOR_H
#define COLOR_H
#include "vec3.h"
#include <iostream>
void write_color(std::ostream& out, const color pixel_color, int samples_per_pixel)
{
double r = pixel_color.x();
double g = pixel_color.y();
double b = pixel_color.z();
const double scale = 1.0 / samples_per_pixel; // sqrt for gamma correction
r = sqrt(r * scale);
b = sqrt(b * scale);
g = sqrt(g * scale);
int ir = static_cast<int>(256 * clamp(r, 0, 0.9999));
int ig = static_cast<int>(256 * clamp(g, 0, 0.9999));
int ib = static_cast<int>(256 * clamp(b, 0, 0.9999));
out << ir << ' '<< ig << ' ' << ib << '\n';
}
vec3 blend(const double t, const color startColor, const color endColor)
{
return (1-t) * startColor + t * endColor;
}
#endif