1 #include "pbrmaterial.h"
8 PbrMaterial::PbrMaterial():
17 void PbrMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
19 module_name = "cooktorrance.glsl";
20 spec_values["use_base_color_map"] = (base_color.texture!=0);
21 spec_values["use_normal_map"] = (normal.texture!=0);
22 spec_values["use_metalness_map"] = (metalness.texture!=0);
23 spec_values["use_roughness_map"] = (roughness.texture!=0);
24 spec_values["use_occlusion_map"] = (occlusion.texture!=0);
25 bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
26 spec_values["use_emission"] = use_emission;
27 spec_values["use_emission_map"] = (emission.texture!=0);
28 spec_values["use_shadow_map"] = receive_shadows;
31 void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
33 attach_texture_to(base_color.texture, texturing, tex_shdata, "base_color_map");
34 attach_texture_to(metalness.texture, texturing, tex_shdata, "metalness_map");
35 attach_texture_to(roughness.texture, texturing, tex_shdata, "roughness_map");
36 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
37 attach_texture_to(occlusion.texture, texturing, tex_shdata, "occlusion_map");
38 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
41 void PbrMaterial::set_base_color(const Color &color)
43 base_color.value = color;
44 shdata.uniform("pbr_material.base_color", color);
47 void PbrMaterial::set_base_color_map(const Texture *tex)
49 base_color.texture = tex;
52 void PbrMaterial::set_normal_map(const Texture *tex)
57 void PbrMaterial::set_metalness(float value)
59 metalness.value = value;
60 shdata.uniform("pbr_material.metalness", value);
63 void PbrMaterial::set_metalness_map(const Texture *tex)
65 metalness.texture = tex;
68 void PbrMaterial::set_roughness(float value)
70 roughness.value = value;
71 shdata.uniform("pbr_material.roughness", value);
74 void PbrMaterial::set_roughness_map(const Texture *tex)
76 roughness.texture = tex;
79 void PbrMaterial::set_occlusion_map(const Texture *tex)
81 occlusion.texture = tex;
84 void PbrMaterial::set_emission(const Color &color)
86 emission.value = color;
87 shdata.uniform("pbr_material.emission", color);
90 void PbrMaterial::set_emission_map(const Texture *tex)
92 emission.texture = tex;
95 void PbrMaterial::set_receive_shadows(bool s)
101 DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
103 PbrMaterial::Loader::Loader(PbrMaterial &m):
104 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m)
106 set_actions(shared_actions);
109 PbrMaterial::Loader::Loader(PbrMaterial &m, Collection &c):
110 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m, c)
112 set_actions(shared_actions);
115 void PbrMaterial::Loader::init_actions()
117 Material::PropertyLoader<PbrMaterial>::init_actions();
118 add_property("base_color", &PbrMaterial::set_base_color, &PbrMaterial::set_base_color_map, true);
119 add_property("normal", &PbrMaterial::set_normal_map);
120 add_property("metalness", &PbrMaterial::set_metalness, &PbrMaterial::set_metalness_map);
121 add_property("roughness", &PbrMaterial::set_roughness, &PbrMaterial::set_roughness_map);
122 add_property("occlusion", &PbrMaterial::set_occlusion_map);
123 add_property("emission", &PbrMaterial::set_emission, &PbrMaterial::set_emission_map, false);
124 add("receive_shadows", &PbrMaterial::receive_shadows);