1 #include "basicmaterial.h"
8 const Tag BasicMaterial::texture_tags[] =
15 Tag("reflectivity_map"),
19 BasicMaterial::BasicMaterial():
20 receive_shadows(false)
22 set_diffuse(Color(1.0f));
23 set_specular(Color(0.0f));
24 set_emission(Color(0.0f));
26 set_reflectivity(0.0f);
29 void BasicMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
31 module_name = "phong.glsl";
32 spec_values["use_diffuse_map"] = (diffuse.texture!=0);
33 bool use_specular = (specular.texture || specular.value.r || specular.value.g || specular.value.b);
34 spec_values["use_specular"] = use_specular;
35 spec_values["use_specular_map"] = (specular.texture!=0);
36 spec_values["use_shininess_map"] = (use_specular && shininess.texture!=0);
37 spec_values["use_normal_map"] = (normal.texture!=0);
38 bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
39 spec_values["use_emission"] = use_emission;
40 spec_values["use_emission_map"] = (emission.texture!=0);
41 spec_values["use_reflectivity"] = (reflectivity.value!=0 || reflectivity.texture!=0);
42 spec_values["use_reflectivity_map"] = (reflectivity.texture!=0);
43 spec_values["use_shadow_map"] = receive_shadows;
46 #pragma GCC diagnostic push
47 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
48 void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
50 attach_texture_to(diffuse.texture, texturing, tex_shdata, "diffuse_map");
51 attach_texture_to(specular.texture, texturing, tex_shdata, "specular_map");
52 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
53 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
54 attach_texture_to(shininess.texture, texturing, tex_shdata, "shininess_map");
55 attach_texture_to(reflectivity.texture, texturing, tex_shdata, "reflectivity_map");
57 #pragma GCC diagnostic pop
59 const Texture *BasicMaterial::get_texture(Tag tag) const
61 if(tag==texture_tags[0])
62 return diffuse.texture;
63 else if(tag==texture_tags[1])
64 return specular.texture;
65 else if(tag==texture_tags[2])
66 return shininess.texture;
67 else if(tag==texture_tags[3])
68 return normal.texture;
69 else if(tag==texture_tags[4])
70 return emission.texture;
71 else if(tag==texture_tags[5])
72 return reflectivity.texture;
77 void BasicMaterial::set_diffuse(const Color &color)
79 diffuse.value = color;
80 shdata.uniform("basic_material.diffuse", color);
83 void BasicMaterial::set_diffuse_map(const Texture *tex)
85 diffuse.texture = tex;
88 void BasicMaterial::set_specular(const Color &color)
90 specular.value = color;
91 shdata.uniform("basic_material.specular", color);
94 void BasicMaterial::set_specular_map(const Texture *tex)
96 specular.texture = tex;
99 void BasicMaterial::set_normal_map(const Texture *tex)
101 normal.texture = tex;
104 void BasicMaterial::set_emission(const Color &color)
106 emission.value = color;
107 shdata.uniform("basic_material.emission", color);
110 void BasicMaterial::set_emission_map(const Texture *tex)
112 emission.texture = tex;
115 void BasicMaterial::set_shininess(float value)
117 shininess.value = value;
118 shdata.uniform("basic_material.shininess", value);
121 void BasicMaterial::set_shininess_map(const Texture *tex)
123 shininess.texture = tex;
126 void BasicMaterial::set_reflectivity(float value)
128 reflectivity.value = value;
129 shdata.uniform("basic_material.reflectivity", value);
132 void BasicMaterial::set_reflectivity_map(const Texture *tex)
134 reflectivity.texture = tex;
137 void BasicMaterial::set_receive_shadows(bool s)
143 DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions;
145 BasicMaterial::Loader::Loader(BasicMaterial &m):
146 DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m)
148 set_actions(shared_actions);
151 BasicMaterial::Loader::Loader(BasicMaterial &m, Collection &c):
152 DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m, c)
154 set_actions(shared_actions);
157 void BasicMaterial::Loader::init_actions()
159 Material::PropertyLoader<BasicMaterial>::init_actions();
160 add_property("diffuse", &BasicMaterial::set_diffuse, &BasicMaterial::set_diffuse_map, true);
161 add_property("specular", &BasicMaterial::set_specular, &BasicMaterial::set_specular_map, false);
162 add_property("normal", &BasicMaterial::set_normal_map);
163 add_property("emission", &BasicMaterial::set_emission, &BasicMaterial::set_emission_map, false);
164 add_property("shininess", &BasicMaterial::set_shininess, &BasicMaterial::set_shininess_map);
165 add_property("reflectivity", &BasicMaterial::set_reflectivity, &BasicMaterial::set_reflectivity_map);
166 add("receive_shadows", &BasicMaterial::receive_shadows);