-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial.hpp
150 lines (134 loc) · 3.43 KB
/
material.hpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef H_MATERIAL
#define H_MATERIAL
// forward declarations
struct Ray;
struct HitRecord;
// includes
#include "./texture.hpp"
namespace mtl {
class Material {
private:
// material properties
const txr::Texture* att;
const txr::Texture* emit;
const bool is_fuzzy;
const Vec3f fuzz;
const float refl;
const float ior;
const bool transparent;
public:
// constructor
Material(
const txr::Texture* att, // attenuation color
const txr::Texture* emit, // emittance color
const float& fuzz, // fuzz of reflections
const float& refl, // reflectance probability
const float& ior, // index of refraction
const bool& transparent // is the material transparent
);
// build the scatter ray and return
// false when there is no scatter ray
virtual bool scatter(
const HitRecord& h, // the hitrecord of the in ray
Ray& scatter // output scatter ray
) const;
// method that returns the
// attenuation color of a ray
virtual Vec3f attenuation(const HitRecord& h) const;
// method that returns the
// emittance color
virtual Vec3f emittance(const HitRecord& h) const;
};
// lambertian material has
// perfect diffuse properties
class Lambertian : public Material {
public:
Lambertian(const txr::Texture* att);
};
// specular material
class Specular : public Material {
public:
Specular(
const txr::Texture* att,
const float& index
);
};
// specular material
class Metallic : public Material {
public:
Metallic(
const txr::Texture* att,
const float& fuzz
);
};
// transparent material
class Dielectric : public Material {
public:
Dielectric(
const txr::Texture* att,
const float& index
);
};
// light material
class Light : public Material {
public:
Light(const txr::Texture* emit);
// light material never scatter
// thus the scatter function should
// always return false
virtual bool scatter(
const HitRecord& h,
Ray& scatter
) const;
};
/*
* Debug Materials
*/
class Debug : public Material {
public:
// constructor
Debug(void);
// override scatter function
// and make debugging materials
// never generate secondary rays
virtual bool scatter(
const HitRecord& h,
Ray& scatter
) const;
// debug materials only need to
// define an emittance function
virtual Vec3f emittance(const HitRecord& h) const = 0;
};
// normal material visualizing the
// surface normal
class Normal : public Debug {
public:
// emittance color is proportional to the
// surface normal vector at intersection
virtual Vec3f emittance(const HitRecord& h) const;
};
// depth material showing the
// distance to the intersection
// point as gray-scale color value
class Depth : public Debug {
private:
float min_dist, max_dist;
public:
// constructor
Depth(
const float& min_dist,
const float& max_dist
);
// emittance is the distance to intersection
virtual Vec3f emittance(const HitRecord& h) const;
};
// cosine material visualizing the angle
// between incident ray and surface normal
class Cosine : public Debug {
public:
// return cosine angle between incident ray direction
// and surface normal as gray-scale color vector
virtual Vec3f emittance(const HitRecord& h) const;
};
};
#endif // H_MATERIAL