-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlights.h
More file actions
73 lines (58 loc) · 2.72 KB
/
Copy pathlights.h
File metadata and controls
73 lines (58 loc) · 2.72 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "rng.h"
#include "scene.h"
#include "shapes.h"
#include "vector.h"
class Light {
public:
double intensity = 1;
Vector3 color = Vector3(1, 1, 1);
Vector3 position = Vector3();
mutable PCG32* rng = nullptr;
Light(Vector3 position, double intensity = 1, Vector3 color = Vector3(1, 1, 1)): position(position), intensity(intensity), color(color) {}
virtual Vector3 sample(Vector3 point, Vector3 normal, Scene& scene) const = 0;
virtual Vector3 sample(Vector3 point, Vector3 normal, Vector3 view, Scene& scene) const = 0;
virtual bool is_mirror_visible() const { return false; }
};
class PointLight : public Light {
public:
using Light::Light;
Vector3 sample(Vector3 point, Vector3 normal, Scene& scene) const override;
Vector3 sample(Vector3 point, Vector3 normal, Vector3 view, Scene& scene) const override;
};
class DirectionalLight : public Light {
public:
Vector3 direction;
DirectionalLight(Vector3 direction, double intensity = 1, Vector3 color = Vector3(1, 1, 1)): direction(direction.normalize()), Light(Vector3(0, 0, 0), intensity, color) {}
Vector3 sample(Vector3 point, Vector3 normal, Scene& scene) const override;
Vector3 sample(Vector3 point, Vector3 normal, Vector3 view, Scene& scene) const override;
};
class SphereLight : public Light {
public:
double radius = 1;
SphereLight(Vector3 position, double radius = 1, double intensity = 1, Vector3 color = Vector3(1, 1, 1)): Light(position, intensity, color), radius(radius) {}
Vector3 sample(Vector3 point, Vector3 normal, Scene& scene) const override;
Vector3 sample(Vector3 point, Vector3 normal, Vector3 view, Scene& scene) const override;
bool is_mirror_visible() const override { return true; }
private:
mutable Vector3 last_position = Vector3(0, 0, 0);
mutable double last_radius = 1;
mutable Sphere sphere = Sphere(Vector3(), 1);
mutable double surface_area = 0;
};
class BoxLight : public Light {
public:
Vector3 rotation = Vector3();
Vector3 halfsize = Vector3();
BoxLight(): Light(Vector3()) {}
BoxLight(Vector3 position, Vector3 halfsize, Vector3 rotation, double intensity = 1, Vector3 color = Vector3(1)): Light(position, intensity, color), rotation(rotation), halfsize(halfsize) {}
Vector3 sample(Vector3 point, Vector3 normal, Scene& scene) const override;
Vector3 sample(Vector3 point, Vector3 normal, Vector3 view, Scene& scene) const override;
bool is_mirror_visible() const override { return true; }
private:
mutable Vector3 last_position = Vector3();
mutable Vector3 last_rotation = Vector3();
mutable Vector3 last_halfsize = Vector3();
mutable Box box = Box(Vector3(), Vector3(), Vector3());
mutable double surface_area = 0;
};