-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterial.cpp
More file actions
81 lines (67 loc) · 3.19 KB
/
Material.cpp
File metadata and controls
81 lines (67 loc) · 3.19 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
74
75
76
77
78
79
80
81
#include "Material.h"
Material::Material(
float absorption_wavelength, float absorption_width, float absorption_strength,
float reflection_wavelength, float reflection_width, float reflection_strength,
float transmission_strength, float shininess) : InstanceAttribute(sizeof(Material::Array), (GLvoid*) &properties) {
glm::vec3 absorption_rgb = get_RGB(absorption_wavelength, absorption_width, absorption_strength);
glm::vec3 reflection_rgb = get_RGB(reflection_wavelength, reflection_width, reflection_strength);
properties.absorption_rgb_[0] = absorption_rgb.x;
properties.absorption_rgb_[1] = absorption_rgb.y;
properties.absorption_rgb_[2] = absorption_rgb.z;
properties.reflection_rgb_[0] = reflection_rgb.x;
properties.reflection_rgb_[1] = reflection_rgb.y;
properties.reflection_rgb_[2] = reflection_rgb.z;
properties.transmission_strength_ = transmission_strength;
properties.shininess_ = shininess;
}
Material::Material(float r, float g, float b) : InstanceAttribute(sizeof(Material::Array), (GLvoid*) &properties) {
properties.reflection_rgb_[0] = r;
properties.reflection_rgb_[1] = g;
properties.reflection_rgb_[2] = b;
}
Material::Material() : InstanceAttribute(sizeof(Material::Array), (GLvoid*) &properties,
"MaterialAbsorption:fff,MaterialReflection:fff,MaterialTransmission:f,MaterialShininess:f.") {
// Not touching properties (leaving everything default)
}
//TODO A texture can define different material properties at different points of an object
// This can be extended to normalmapping, but maybe this sould be done in a subclass of Material
//Material(Texture texture);
Material::~Material() {
}
glm::vec3 Material::get_RGB(float wavelength, float width, float strength) {
return Light::hsv_to_rgb(
Light::wavelength_to_hue(glm::clamp(wavelength, 380.0f, 750.0f)),
glm::clamp(1.0f - width, 0.0f, 1.0f),
glm::clamp(strength, 0.0f, 1.0f)
);
}
// SETTER
//TODO None of the setters works (buffer update must be missing...)
void Material::absorb(float absorption_wavelength, float absorption_width, float absorption_strength) {
glm::vec3 absorption_rgb = get_RGB(absorption_wavelength, absorption_width, absorption_strength);
properties.absorption_rgb_[0] = absorption_rgb.x;
properties.absorption_rgb_[1] = absorption_rgb.y;
properties.absorption_rgb_[2] = absorption_rgb.z;
InstanceAttribute::has_changed_ = true;
}
void Material::reflect(float reflection_wavelength, float reflection_width, float reflection_strength) {
glm::vec3 reflection_rgb = get_RGB(reflection_wavelength, reflection_width, reflection_strength);
properties.reflection_rgb_[0] = reflection_rgb.x;
properties.reflection_rgb_[1] = reflection_rgb.y;
properties.reflection_rgb_[2] = reflection_rgb.z;
InstanceAttribute::has_changed_ = true;
}
void Material::reflectRGB(float r, float g, float b) {
properties.reflection_rgb_[0] = r;
properties.reflection_rgb_[1] = g;
properties.reflection_rgb_[2] = b;
InstanceAttribute::has_changed_ = true;
}
void Material::transmit(float transmission_strength) {
properties.transmission_strength_ = transmission_strength;
InstanceAttribute::has_changed_ = true;
}
void Material::shine(float shininess) {
properties.shininess_ = shininess;
InstanceAttribute::has_changed_ = true;
}