1 #include "pbrmaterial.h"
8 PbrMaterial::PbrMaterial():
17 string PbrMaterial::create_program_source() const
19 string source = "import cooktorrance;\n";
20 if(base_color.texture)
21 source += "const bool use_base_color_map = true;\n";
23 source += "const bool use_normal_map = true;\n";
25 source += "const bool use_metalness_map = true;\n";
27 source += "const bool use_roughness_map = true;\n";
29 source += "const bool use_occlusion_map = true;\n";
30 if(emission.texture || emission.value.r || emission.value.g || emission.value.b)
32 source += "const bool use_emission = true;\n";
34 source += "const bool use_emission_map = true;\n";
37 source += "const bool use_shadow_map = true;\n";
41 void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
43 attach_texture_to(base_color.texture, texturing, tex_shdata, "base_color_map");
44 attach_texture_to(metalness.texture, texturing, tex_shdata, "metalness_map");
45 attach_texture_to(roughness.texture, texturing, tex_shdata, "roughness_map");
46 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
47 attach_texture_to(occlusion.texture, texturing, tex_shdata, "occlusion_map");
48 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
51 void PbrMaterial::set_base_color(const Color &color)
53 base_color.value = color;
54 shdata.uniform("pbr_material.base_color", color);
57 void PbrMaterial::set_base_color_map(const Texture *tex)
59 base_color.texture = tex;
62 void PbrMaterial::set_normal_map(const Texture *tex)
67 void PbrMaterial::set_metalness(float value)
69 metalness.value = value;
70 shdata.uniform("pbr_material.metalness", value);
73 void PbrMaterial::set_metalness_map(const Texture *tex)
75 metalness.texture = tex;
78 void PbrMaterial::set_roughness(float value)
80 roughness.value = value;
81 shdata.uniform("pbr_material.roughness", value);
84 void PbrMaterial::set_roughness_map(const Texture *tex)
86 roughness.texture = tex;
89 void PbrMaterial::set_occlusion_map(const Texture *tex)
91 occlusion.texture = tex;
94 void PbrMaterial::set_emission(const Color &color)
96 emission.value = color;
97 shdata.uniform("pbr_material.emission", color);
100 void PbrMaterial::set_emission_map(const Texture *tex)
102 emission.texture = tex;
105 void PbrMaterial::set_receive_shadows(bool s)
111 DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
113 PbrMaterial::Loader::Loader(PbrMaterial &m):
114 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m)
116 set_actions(shared_actions);
119 PbrMaterial::Loader::Loader(PbrMaterial &m, Collection &c):
120 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m, c)
122 set_actions(shared_actions);
125 void PbrMaterial::Loader::init_actions()
127 Material::PropertyLoader<PbrMaterial>::init_actions();
128 add_property("base_color", &PbrMaterial::set_base_color, &PbrMaterial::set_base_color_map, true);
129 add_property("normal", &PbrMaterial::set_normal_map);
130 add_property("metalness", &PbrMaterial::set_metalness, &PbrMaterial::set_metalness_map);
131 add_property("roughness", &PbrMaterial::set_roughness, &PbrMaterial::set_roughness_map);
132 add_property("occlusion", &PbrMaterial::set_occlusion_map);
133 add_property("emission", &PbrMaterial::set_emission, &PbrMaterial::set_emission_map, false);
134 add("receive_shadows", &PbrMaterial::receive_shadows);