-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.h
More file actions
38 lines (32 loc) · 1.07 KB
/
Copy pathbackground.h
File metadata and controls
38 lines (32 loc) · 1.07 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
#pragma once
#include "vector.h"
#include <cmath>
class Background {
public:
virtual Vector3 sample(Vector3 direction) const = 0;
};
class SolidColorBackground: public Background {
public:
Vector3 color;
double intensity;
SolidColorBackground(Vector3 color = Vector3(1, 1, 1), double intensity = 1): color(color), intensity(intensity) {};
Vector3 sample(Vector3 direction) const override {
return color * intensity;
};
};
class PanoramaBackground: public Background {
public:
Vector3** texture = nullptr;
Vector3 texture_dim = Vector3();
double intensity;
PanoramaBackground(Vector3** texture, Vector3 texture_dim, double intensity = 1): texture(texture), texture_dim(texture_dim), intensity(intensity) {}
Vector3 sample(Vector3 direction) const override {
double theta = atan2(direction.z, direction.x);
double phi = acos(direction.y);
double u = (theta + M_PI) / (2 * M_PI);
double v = phi / M_PI;
int x = u * texture_dim.x;
int y = v * texture_dim.y;
return texture[y][x];
}
};