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 string BasicMaterial::create_program_source() const
20 string source = "import phong;\n";
22 source += "const bool use_diffuse_map = true;\n";
23 if(specular.texture || specular.value.r || specular.value.g || specular.value.b)
25 source += "const bool use_specular = true;\n";
27 source += "const bool use_specular_map = true;\n";
29 source += "const bool use_shininess_map = true;\n";
32 source += "const bool use_normal_map = true;\n";
33 if(emission.texture || emission.value.r || emission.value.g || emission.value.b)
35 source += "const bool use_emission = true;\n";
37 source += "const bool use_emission_map = true;\n";
39 if(reflectivity.value || reflectivity.texture)
41 source += "const bool use_reflectivity = true;\n";
42 if (reflectivity.texture)
43 source += "const bool use_reflectivity_map = true;\n";
46 source += "const bool use_shadow_map = true;\n";
50 void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
52 attach_texture_to(diffuse.texture, texturing, tex_shdata, "diffuse_map");
53 attach_texture_to(specular.texture, texturing, tex_shdata, "specular_map");
54 attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
55 attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
56 attach_texture_to(shininess.texture, texturing, tex_shdata, "shininess_map");
57 attach_texture_to(reflectivity.texture, texturing, tex_shdata, "reflectivity_map");
60 void BasicMaterial::set_diffuse(const Color &color)
62 diffuse.value = color;
63 shdata.uniform("basic_material.diffuse", color);
66 void BasicMaterial::set_diffuse_map(const Texture *tex)
68 diffuse.texture = tex;
71 void BasicMaterial::set_specular(const Color &color)
73 specular.value = color;
74 shdata.uniform("basic_material.specular", color);
77 void BasicMaterial::set_specular_map(const Texture *tex)
79 specular.texture = tex;
82 void BasicMaterial::set_normal_map(const Texture *tex)
87 void BasicMaterial::set_emission(const Color &color)
89 emission.value = color;
90 shdata.uniform("basic_material.emission", color);
93 void BasicMaterial::set_emission_map(const Texture *tex)
95 emission.texture = tex;
98 void BasicMaterial::set_shininess(float value)
100 shininess.value = value;
101 shdata.uniform("basic_material.shininess", value);
104 void BasicMaterial::set_shininess_map(const Texture *tex)
106 shininess.texture = tex;
109 void BasicMaterial::set_reflectivity(float value)
111 reflectivity.value = value;
112 shdata.uniform("basic_material.reflectivity", value);
115 void BasicMaterial::set_reflectivity_map(const Texture *tex)
117 reflectivity.texture = tex;
120 void BasicMaterial::set_receive_shadows(bool s)
126 DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions;
128 BasicMaterial::Loader::Loader(BasicMaterial &m):
129 DerivedObjectLoader<BasicMaterial, Material::LoaderBase<BasicMaterial> >(m)
131 set_actions(shared_actions);
134 BasicMaterial::Loader::Loader(BasicMaterial &m, Collection &c):
135 DerivedObjectLoader<BasicMaterial, Material::LoaderBase<BasicMaterial> >(m, c)
137 set_actions(shared_actions);
140 void BasicMaterial::Loader::init_actions()
142 add_property("diffuse", &BasicMaterial::set_diffuse, &BasicMaterial::set_diffuse_map, true);
143 add_property("specular", &BasicMaterial::set_specular, &BasicMaterial::set_specular_map, false);
144 add_property("normal", &BasicMaterial::set_normal_map);
145 add_property("emission", &BasicMaterial::set_emission, &BasicMaterial::set_emission_map, false);
146 add_property("shininess", &BasicMaterial::set_shininess, &BasicMaterial::set_shininess_map);
147 add_property("reflectivity", &BasicMaterial::set_reflectivity, &BasicMaterial::set_reflectivity_map);
148 add("receive_shadows", &BasicMaterial::receive_shadows);