1 #include "pbrmaterial.h"
8 const Tag PbrMaterial::texture_tags[] =
10 Tag("base_color_map"),
19 PbrMaterial::PbrMaterial():
20 receive_shadows(false)
28 void PbrMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
30 module_name = "cooktorrance.glsl";
31 spec_values["use_base_color_map"] = (base_color.texture!=0);
32 spec_values["use_normal_map"] = (normal.texture!=0);
33 spec_values["use_metalness_map"] = (metalness.texture!=0);
34 spec_values["use_roughness_map"] = (roughness.texture!=0);
35 spec_values["use_occlusion_map"] = (occlusion.texture!=0);
36 bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
37 spec_values["use_emission"] = use_emission;
38 spec_values["use_emission_map"] = (emission.texture!=0);
39 spec_values["use_shadow_map"] = receive_shadows;
42 #pragma GCC diagnostic push
43 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44 void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
46 attach_texture_to(base_color.texture, texturing, tex_shdata, "base_color_map");
47 attach_texture_to(metalness.texture, texturing, tex_shdata, "metalness_map");
48 attach_texture_to(roughness.texture, texturing, tex_shdata, "roughness_map");
49 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
50 attach_texture_to(occlusion.texture, texturing, tex_shdata, "occlusion_map");
51 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
53 #pragma GCC diagnostic pop
55 const Texture *PbrMaterial::get_texture(Tag tag) const
57 if(tag==texture_tags[0])
58 return base_color.texture;
59 else if(tag==texture_tags[1])
60 return normal.texture;
61 else if(tag==texture_tags[2])
62 return metalness.texture;
63 else if(tag==texture_tags[3])
64 return roughness.texture;
65 else if(tag==texture_tags[4])
66 return occlusion.texture;
67 else if(tag==texture_tags[5])
68 return emission.texture;
73 void PbrMaterial::set_base_color(const Color &color)
75 base_color.value = color;
76 shdata.uniform("pbr_material.base_color", color);
79 void PbrMaterial::set_base_color_map(const Texture *tex)
81 base_color.texture = tex;
84 void PbrMaterial::set_normal_map(const Texture *tex)
89 void PbrMaterial::set_metalness(float value)
91 metalness.value = value;
92 shdata.uniform("pbr_material.metalness", value);
95 void PbrMaterial::set_metalness_map(const Texture *tex)
97 metalness.texture = tex;
100 void PbrMaterial::set_roughness(float value)
102 roughness.value = value;
103 shdata.uniform("pbr_material.roughness", value);
106 void PbrMaterial::set_roughness_map(const Texture *tex)
108 roughness.texture = tex;
111 void PbrMaterial::set_occlusion_map(const Texture *tex)
113 occlusion.texture = tex;
116 void PbrMaterial::set_emission(const Color &color)
118 emission.value = color;
119 shdata.uniform("pbr_material.emission", color);
122 void PbrMaterial::set_emission_map(const Texture *tex)
124 emission.texture = tex;
127 void PbrMaterial::set_receive_shadows(bool s)
133 DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
135 PbrMaterial::Loader::Loader(PbrMaterial &m):
136 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m)
138 set_actions(shared_actions);
141 PbrMaterial::Loader::Loader(PbrMaterial &m, Collection &c):
142 DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m, c)
144 set_actions(shared_actions);
147 void PbrMaterial::Loader::init_actions()
149 Material::PropertyLoader<PbrMaterial>::init_actions();
150 add_property("base_color", &PbrMaterial::set_base_color, &PbrMaterial::set_base_color_map, true);
151 add_property("normal", &PbrMaterial::set_normal_map);
152 add_property("metalness", &PbrMaterial::set_metalness, &PbrMaterial::set_metalness_map);
153 add_property("roughness", &PbrMaterial::set_roughness, &PbrMaterial::set_roughness_map);
154 add_property("occlusion", &PbrMaterial::set_occlusion_map);
155 add_property("emission", &PbrMaterial::set_emission, &PbrMaterial::set_emission_map, false);
156 add("receive_shadows", &PbrMaterial::receive_shadows);