-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial.cpp
More file actions
executable file
·40 lines (37 loc) · 1.63 KB
/
material.cpp
File metadata and controls
executable file
·40 lines (37 loc) · 1.63 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
#include "material.h"
#include "vector3f.h"
namespace fst
{
Material::Material(const math::Vector3f& ambient, const math::Vector3f& diffuse, const math::Vector3f& specular, const math::Vector3f& mirror, float phong_exponent)
: m_ambient(ambient)
, m_diffuse(diffuse)
, m_specular(specular)
, m_mirror(mirror)
, m_phong_exponent(phong_exponent)
{}
math::Vector3f Material::computeBrdf(const math::Vector3f& wi, const math::Vector3f& wo, const math::Vector3f& normal, HitRecord& hit_Record) const
{
auto diffuse = math::max(math::dot(normal, wi), 0.0f);
auto specular = std::pow(math::max(math::dot(math::normalize(wo + wi), normal), 0.0f), m_phong_exponent);
if(hit_Record.text == true)
{
if (hit_Record.decal_mode == "replace_kd")
return m_specular * specular +
math::Vector3f(hit_Record.texture_color.x / 255, hit_Record.texture_color.y / 255,
hit_Record.texture_color.z / 255) * diffuse;
else if(hit_Record.decal_mode == "blend_kd")
{
return m_specular * specular + (m_diffuse + math::Vector3f(hit_Record.texture_color.x / 255, hit_Record.texture_color.y / 255,
hit_Record.texture_color.z / 255)) / 2 * diffuse;
}
else
{
return m_specular * specular;
}
}
else
{
return m_specular * specular + m_diffuse * diffuse;
}
}
}