Tag()
};
-BasicMaterial::BasicMaterial():
- receive_shadows(false)
+BasicMaterial::BasicMaterial()
{
set_diffuse(Color(1.0f));
set_specular(Color(0.0f));
spec_values["use_emission_map"] = (emission.texture!=0);
spec_values["use_reflectivity"] = (reflectivity.value!=0 || reflectivity.texture!=0);
spec_values["use_reflectivity_map"] = (reflectivity.texture!=0);
- spec_values["use_shadow_map"] = receive_shadows;
}
#pragma GCC diagnostic push
reflectivity.texture = tex;
}
-void BasicMaterial::set_receive_shadows(bool s)
-{
- receive_shadows = s;
-}
-
DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions;
add_property("emission", &BasicMaterial::set_emission, &BasicMaterial::set_emission_map, false);
add_property("shininess", &BasicMaterial::set_shininess, &BasicMaterial::set_shininess_map);
add_property("reflectivity", &BasicMaterial::set_reflectivity, &BasicMaterial::set_reflectivity_map);
- add("receive_shadows", &BasicMaterial::receive_shadows);
}
} // namespace GL
Property<Vector3> normal;
Property<Color> emission;
Property<float> reflectivity;
- bool receive_shadows;
static const Tag texture_tags[];
void set_shininess_map(const Texture *);
void set_reflectivity(float);
void set_reflectivity_map(const Texture *);
- void set_receive_shadows(bool);
};
} // namespace GL
namespace Msp {
namespace GL {
-const Program *Material::create_compatible_shader(DataFile::Collection &coll) const
+const Program *Material::create_compatible_shader(DataFile::Collection &coll, const map<string, int> &extra_spec) const
{
string module_name;
map<string, int> spec_values;
fill_program_info(module_name, spec_values);
+ for(map<string, int>::const_iterator i=extra_spec.begin(); i!=extra_spec.end(); ++i)
+ spec_values[i->first] = i->second;
+
string info = module_name;
for(map<string, int>::const_iterator i=spec_values.begin(); i!=spec_values.end(); ++i)
info += format(",%s:%d", i->first, i->second);
public:
virtual ~Material() { }
- virtual const Program *create_compatible_shader(DataFile::Collection &) const;
+ virtual const Program *create_compatible_shader(DataFile::Collection &, const std::map<std::string, int> & = std::map<std::string, int>()) const;
protected:
virtual void fill_program_info(std::string &, std::map<std::string, int> &) const = 0;
Tag()
};
-PbrMaterial::PbrMaterial():
- receive_shadows(false)
+PbrMaterial::PbrMaterial()
{
set_base_color(0.8f);
set_metalness(0.0f);
bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
spec_values["use_emission"] = use_emission;
spec_values["use_emission_map"] = (emission.texture!=0);
- spec_values["use_shadow_map"] = receive_shadows;
}
#pragma GCC diagnostic push
emission.texture = tex;
}
-void PbrMaterial::set_receive_shadows(bool s)
-{
- receive_shadows = s;
-}
-
DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
add_property("roughness", &PbrMaterial::set_roughness, &PbrMaterial::set_roughness_map);
add_property("occlusion", &PbrMaterial::set_occlusion_map);
add_property("emission", &PbrMaterial::set_emission, &PbrMaterial::set_emission_map, false);
- add("receive_shadows", &PbrMaterial::receive_shadows);
}
} // namespace GL
Property<float> roughness;
Property<float> occlusion;
Property<Color> emission;
- bool receive_shadows;
static const Tag texture_tags[];
void set_occlusion_map(const Texture *);
void set_emission(const Color &);
void set_emission_map(const Texture *);
- void set_receive_shadows(bool);
};
} // namespace GL
shprog_from_material(false),
shdata(0),
material(0),
- back_faces(false)
+ back_faces(false),
+ receive_shadows(false)
{ }
void RenderPass::set_material_textures()
if(shprog && !shprog_from_material)
return;
+ map<string, int> extra_spec;
+ if(receive_shadows)
+ extra_spec["use_shadow_map"] = true;
+
if(coll)
{
- shprog = material->create_compatible_shader(*coll);
+ shprog = material->create_compatible_shader(*coll, extra_spec);
shprog.keep();
}
else
return (shprog && i!=textures.end() ? shprog->get_uniform_binding(i->tag) : -1);
}
+void RenderPass::set_receive_shadows(bool rs)
+{
+ receive_shadows = rs;
+}
+
void RenderPass::apply(Renderer &renderer) const
{
for(vector<TextureSlot>::const_iterator i=textures.begin(); i!=textures.end(); ++i)
add("material", &Loader::material);
add("material_slot", &RenderPass::material_slot);
add("back_faces",&RenderPass::back_faces);
+ add("receive_shadows", &RenderPass::receive_shadows);
add("texture", &Loader::texture);
add("uniforms", &Loader::uniforms);
add("uniform_slot", &Loader::uniform_slot);
std::string material_slot;
std::vector<TextureSlot> textures;
bool back_faces;
+ bool receive_shadows;
public:
RenderPass();
DEPRECATED int get_texture_index(const std::string &) const;
void set_back_faces(bool);
bool get_back_faces() const { return back_faces; }
+ void set_receive_shadows(bool);
+ bool get_receive_shadows() const { return receive_shadows; }
void apply(Renderer &) const;
};