1 #include "basicmaterial.h"
8 BasicMaterial::BasicMaterial():
11 set_diffuse(Color(1.0f));
12 set_specular(Color(0.0f));
13 set_emission(Color(0.0f));
15 set_reflectivity(0.0f);
18 void BasicMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
20 module_name = "phong.glsl";
21 spec_values["use_diffuse_map"] = (diffuse.texture!=0);
22 bool use_specular = (specular.texture || specular.value.r || specular.value.g || specular.value.b);
23 spec_values["use_specular"] = use_specular;
24 spec_values["use_specular_map"] = (specular.texture!=0);
25 spec_values["use_shininess_map"] = (use_specular && shininess.texture!=0);
26 spec_values["use_normal_map"] = (normal.texture!=0);
27 bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
28 spec_values["use_emission"] = use_emission;
29 spec_values["use_emission_map"] = (emission.texture!=0);
30 spec_values["use_reflectivity"] = (reflectivity.value!=0 || reflectivity.texture!=0);
31 spec_values["use_reflectivity_map"] = (reflectivity.texture!=0);
32 spec_values["use_shadow_map"] = receive_shadows;
35 void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
37 attach_texture_to(diffuse.texture, texturing, tex_shdata, "diffuse_map");
38 attach_texture_to(specular.texture, texturing, tex_shdata, "specular_map");
39 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
40 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
41 attach_texture_to(shininess.texture, texturing, tex_shdata, "shininess_map");
42 attach_texture_to(reflectivity.texture, texturing, tex_shdata, "reflectivity_map");
45 void BasicMaterial::set_diffuse(const Color &color)
47 diffuse.value = color;
48 shdata.uniform("basic_material.diffuse", color);
51 void BasicMaterial::set_diffuse_map(const Texture *tex)
53 diffuse.texture = tex;
56 void BasicMaterial::set_specular(const Color &color)
58 specular.value = color;
59 shdata.uniform("basic_material.specular", color);
62 void BasicMaterial::set_specular_map(const Texture *tex)
64 specular.texture = tex;
67 void BasicMaterial::set_normal_map(const Texture *tex)
72 void BasicMaterial::set_emission(const Color &color)
74 emission.value = color;
75 shdata.uniform("basic_material.emission", color);
78 void BasicMaterial::set_emission_map(const Texture *tex)
80 emission.texture = tex;
83 void BasicMaterial::set_shininess(float value)
85 shininess.value = value;
86 shdata.uniform("basic_material.shininess", value);
89 void BasicMaterial::set_shininess_map(const Texture *tex)
91 shininess.texture = tex;
94 void BasicMaterial::set_reflectivity(float value)
96 reflectivity.value = value;
97 shdata.uniform("basic_material.reflectivity", value);
100 void BasicMaterial::set_reflectivity_map(const Texture *tex)
102 reflectivity.texture = tex;
105 void BasicMaterial::set_receive_shadows(bool s)
111 DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions;
113 BasicMaterial::Loader::Loader(BasicMaterial &m):
114 DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m)
116 set_actions(shared_actions);
119 BasicMaterial::Loader::Loader(BasicMaterial &m, Collection &c):
120 DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m, c)
122 set_actions(shared_actions);
125 void BasicMaterial::Loader::init_actions()
127 Material::PropertyLoader<BasicMaterial>::init_actions();
128 add_property("diffuse", &BasicMaterial::set_diffuse, &BasicMaterial::set_diffuse_map, true);
129 add_property("specular", &BasicMaterial::set_specular, &BasicMaterial::set_specular_map, false);
130 add_property("normal", &BasicMaterial::set_normal_map);
131 add_property("emission", &BasicMaterial::set_emission, &BasicMaterial::set_emission_map, false);
132 add_property("shininess", &BasicMaterial::set_shininess, &BasicMaterial::set_shininess_map);
133 add_property("reflectivity", &BasicMaterial::set_reflectivity, &BasicMaterial::set_reflectivity_map);
134 add("receive_shadows", &BasicMaterial::receive_shadows);