From 41391cd21cf35e979c1d2c88019b7425123500be Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 11 Jun 2020 22:05:19 +0300 Subject: [PATCH] Add a flag to BasicMaterial to enable shadow map --- source/basicmaterial.cpp | 11 ++++++++++- source/basicmaterial.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/basicmaterial.cpp b/source/basicmaterial.cpp index 858c65da..9c7714dc 100644 --- a/source/basicmaterial.cpp +++ b/source/basicmaterial.cpp @@ -5,7 +5,8 @@ using namespace std; namespace Msp { namespace GL { -BasicMaterial::BasicMaterial() +BasicMaterial::BasicMaterial(): + receive_shadows(false) { set_diffuse(Color(1.0f)); set_specular(Color(0.0f)); @@ -41,6 +42,8 @@ string BasicMaterial::create_program_source() const if (reflectivity.texture) source += "const bool use_reflectivity_map = true;\n"; } + if(receive_shadows) + source += "const bool use_shadow_map = true;\n"; return source; } @@ -114,6 +117,11 @@ void BasicMaterial::set_reflectivity_map(const Texture *tex) reflectivity.texture = tex; } +void BasicMaterial::set_receive_shadows(bool s) +{ + receive_shadows = s; +} + DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions; @@ -137,6 +145,7 @@ void BasicMaterial::Loader::init_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 diff --git a/source/basicmaterial.h b/source/basicmaterial.h index 5fca56a0..5d8d96ae 100644 --- a/source/basicmaterial.h +++ b/source/basicmaterial.h @@ -29,6 +29,7 @@ private: Property normal; Property emission; Property reflectivity; + bool receive_shadows; public: BasicMaterial(); @@ -50,6 +51,7 @@ public: void set_shininess_map(const Texture *); void set_reflectivity(float); void set_reflectivity_map(const Texture *); + void set_receive_shadows(bool); }; } // namespace GL -- 2.43.0