-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial.hpp
87 lines (72 loc) · 2.16 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
// Homepage: https://github.com/ananthvk/cpp-raytracer
#pragma once
#include "colors.hpp"
#include "commons.hpp"
struct MaterialInteraction
{
// true if this interaction produces other rays which have to be processed
bool additional_rays;
// Additional rays produced due to this interaction
Ray ray;
// Color due to this material
color attenuation;
};
// An abstract class for any material
class Material
{
public:
virtual MaterialInteraction interact(const RayParams params,
const Intersection &intersect) const = 0;
virtual ~Material() {}
};
class LambertianDiffuse : public Material
{
public:
// By default the color of the material is gray, (0.5, 0.5, 0.5)
LambertianDiffuse();
LambertianDiffuse(const color &albedo);
MaterialInteraction interact(const RayParams params,
const Intersection &intersect) const override;
private:
// Albedo or color of this material
color albedo;
};
class NormalShader : public Material
{
public:
MaterialInteraction interact(const RayParams params,
const Intersection &intersect) const override
{
// Shade the normals
MaterialInteraction interaction;
auto v = 0.5 * (intersect.local_normal + vec3(1, 1, 1));
interaction.additional_rays = false;
interaction.attenuation = v;
return interaction;
}
};
class Metal : public Material
{
public:
// By default the color of the material is gray
Metal();
Metal(const color &albedo, double fuzziness = 0.0);
MaterialInteraction interact(const RayParams params,
const Intersection &intersect) const override;
private:
// Albedo or color of this material
color albedo;
double fuzziness;
};
class Glass : public Material
{
public:
Glass();
Glass(const color &albedo, double r_index = 1.5);
MaterialInteraction interact(const RayParams params,
const Intersection &intersect) const override;
private:
// Albedo or color of this material
color albedo;
double r_index;
};