1 #include "pbrmaterial.h"
8 const Tag PbrMaterial::texture_tags[] =
10 Tag("base_color_map"),
19 PbrMaterial::PbrMaterial()
27 void PbrMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
29 module_name = "cooktorrance.glsl";
30 spec_values["use_base_color_map"] = (base_color.texture!=0);
31 spec_values["use_normal_map"] = (normal.texture!=0);
32 spec_values["use_metalness_map"] = (metalness.texture!=0);
33 spec_values["use_roughness_map"] = (roughness.texture!=0);
34 spec_values["use_occlusion_map"] = (occlusion.texture!=0);
35 bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
36 spec_values["use_emission"] = use_emission;
37 spec_values["use_emission_map"] = (emission.texture!=0);
40 #pragma GCC diagnostic push
41 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
42 void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
44 attach_texture_to(base_color.texture, texturing, tex_shdata, "base_color_map");
45 attach_texture_to(metalness.texture, texturing, tex_shdata, "metalness_map");
46 attach_texture_to(roughness.texture, texturing, tex_shdata, "roughness_map");
47 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
48 attach_texture_to(occlusion.texture, texturing, tex_shdata, "occlusion_map");
49 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
51 #pragma GCC diagnostic pop
53 const Texture *PbrMaterial::get_texture(Tag tag) const
55 if(tag==texture_tags[0])
56 return base_color.texture;
57 else if(tag==texture_tags[1])
58 return normal.texture;
59 else if(tag==texture_tags[2])
60 return metalness.texture;
61 else if(tag==texture_tags[3])
62 return roughness.texture;
63 else if(tag==texture_tags[4])
64 return occlusion.texture;
65 else if(tag==texture_tags[5])
66 return emission.texture;
71 void PbrMaterial::set_base_color(const Color &color)
73 base_color.value = color;
74 shdata.uniform("pbr_material.base_color", color);
77 void PbrMaterial::set_base_color_map(const Texture *tex)
79 base_color.texture = tex;
82 void PbrMaterial::set_normal_map(const Texture *tex)
87 void PbrMaterial::set_metalness(float value)
89 metalness.value = value;
90 shdata.uniform("pbr_material.metalness", value);
93 void PbrMaterial::set_metalness_map(const Texture *tex)
95 metalness.texture = tex;
98 void PbrMaterial::set_roughness(float value)
100 roughness.value = value;
101 shdata.uniform("pbr_material.roughness", value);
104 void PbrMaterial::set_roughness_map(const Texture *tex)
106 roughness.texture = tex;
109 void PbrMaterial::set_occlusion_map(const Texture *tex)
111 occlusion.texture = tex;
114 void PbrMaterial::set_emission(const Color &color)
116 emission.value = color;
117 shdata.uniform("pbr_material.emission", color);
120 void PbrMaterial::set_emission_map(const Texture *tex)
122 emission.texture = tex;
126 DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
128 PbrMaterial::Loader::Loader(PbrMaterial &m):
129 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m)
131 set_actions(shared_actions);
134 PbrMaterial::Loader::Loader(PbrMaterial &m, Collection &c):
135 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m, c)
137 set_actions(shared_actions);
140 void PbrMaterial::Loader::init_actions()
142 Material::PropertyLoader<PbrMaterial>::init_actions();
143 add_property("base_color", &PbrMaterial::set_base_color, &PbrMaterial::set_base_color_map, true);
144 add_property("normal", &PbrMaterial::set_normal_map);
145 add_property("metalness", &PbrMaterial::set_metalness, &PbrMaterial::set_metalness_map);
146 add_property("roughness", &PbrMaterial::set_roughness, &PbrMaterial::set_roughness_map);
147 add_property("occlusion", &PbrMaterial::set_occlusion_map);
148 add_property("emission", &PbrMaterial::set_emission, &PbrMaterial::set_emission_map, false);