1 #include "basicmaterial.h"
8 const Tag BasicMaterial::texture_tags[] =
15 Tag("reflectivity_map"),
19 BasicMaterial::BasicMaterial()
21 set_diffuse(Color(1.0f));
22 set_specular(Color(0.0f));
23 set_emission(Color(0.0f));
25 set_reflectivity(0.0f);
28 void BasicMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
30 module_name = "phong.glsl";
31 spec_values["use_diffuse_map"] = (diffuse.texture!=0);
32 bool use_specular = (specular.texture || specular.value.r || specular.value.g || specular.value.b);
33 spec_values["use_specular"] = use_specular;
34 spec_values["use_specular_map"] = (specular.texture!=0);
35 spec_values["use_shininess_map"] = (use_specular && shininess.texture!=0);
36 spec_values["use_normal_map"] = (normal.texture!=0);
37 bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
38 spec_values["use_emission"] = use_emission;
39 spec_values["use_emission_map"] = (emission.texture!=0);
40 spec_values["use_reflectivity"] = (reflectivity.value!=0 || reflectivity.texture!=0);
41 spec_values["use_reflectivity_map"] = (reflectivity.texture!=0);
44 #pragma GCC diagnostic push
45 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
46 void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
48 attach_texture_to(diffuse.texture, texturing, tex_shdata, "diffuse_map");
49 attach_texture_to(specular.texture, texturing, tex_shdata, "specular_map");
50 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
51 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
52 attach_texture_to(shininess.texture, texturing, tex_shdata, "shininess_map");
53 attach_texture_to(reflectivity.texture, texturing, tex_shdata, "reflectivity_map");
55 #pragma GCC diagnostic pop
57 const Texture *BasicMaterial::get_texture(Tag tag) const
59 if(tag==texture_tags[0])
60 return diffuse.texture;
61 else if(tag==texture_tags[1])
62 return specular.texture;
63 else if(tag==texture_tags[2])
64 return shininess.texture;
65 else if(tag==texture_tags[3])
66 return normal.texture;
67 else if(tag==texture_tags[4])
68 return emission.texture;
69 else if(tag==texture_tags[5])
70 return reflectivity.texture;
75 void BasicMaterial::set_diffuse(const Color &color)
77 diffuse.value = color;
78 shdata.uniform("basic_material.diffuse", color);
81 void BasicMaterial::set_diffuse_map(const Texture *tex)
83 diffuse.texture = tex;
86 void BasicMaterial::set_specular(const Color &color)
88 specular.value = color;
89 shdata.uniform("basic_material.specular", color);
92 void BasicMaterial::set_specular_map(const Texture *tex)
94 specular.texture = tex;
97 void BasicMaterial::set_normal_map(const Texture *tex)
102 void BasicMaterial::set_emission(const Color &color)
104 emission.value = color;
105 shdata.uniform("basic_material.emission", color);
108 void BasicMaterial::set_emission_map(const Texture *tex)
110 emission.texture = tex;
113 void BasicMaterial::set_shininess(float value)
115 shininess.value = value;
116 shdata.uniform("basic_material.shininess", value);
119 void BasicMaterial::set_shininess_map(const Texture *tex)
121 shininess.texture = tex;
124 void BasicMaterial::set_reflectivity(float value)
126 reflectivity.value = value;
127 shdata.uniform("basic_material.reflectivity", value);
130 void BasicMaterial::set_reflectivity_map(const Texture *tex)
132 reflectivity.texture = tex;
136 DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions;
138 BasicMaterial::Loader::Loader(BasicMaterial &m):
139 DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m)
141 set_actions(shared_actions);
144 BasicMaterial::Loader::Loader(BasicMaterial &m, Collection &c):
145 DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m, c)
147 set_actions(shared_actions);
150 void BasicMaterial::Loader::init_actions()
152 Material::PropertyLoader<BasicMaterial>::init_actions();
153 add_property("diffuse", &BasicMaterial::set_diffuse, &BasicMaterial::set_diffuse_map, true);
154 add_property("specular", &BasicMaterial::set_specular, &BasicMaterial::set_specular_map, false);
155 add_property("normal", &BasicMaterial::set_normal_map);
156 add_property("emission", &BasicMaterial::set_emission, &BasicMaterial::set_emission_map, false);
157 add_property("shininess", &BasicMaterial::set_shininess, &BasicMaterial::set_shininess_map);
158 add_property("reflectivity", &BasicMaterial::set_reflectivity, &BasicMaterial::set_reflectivity_map);