]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a flag to BasicMaterial to enable shadow map
authorMikko Rasa <tdb@tdb.fi>
Thu, 11 Jun 2020 19:05:19 +0000 (22:05 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 11 Jun 2020 19:06:49 +0000 (22:06 +0300)
source/basicmaterial.cpp
source/basicmaterial.h

index 858c65daf56e8a31e5cdb9c22f1ab0da3f43ae57..9c7714dc1861d1974adc4d20fac8aa9b565d3a37 100644 (file)
@@ -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
index 5fca56a0300127e54fd7f0b06be52bb4e97586e1..5d8d96ae5273d05e7a3106d409e5b4d40b7be450 100644 (file)
@@ -29,6 +29,7 @@ private:
        Property<Vector3> normal;
        Property<Color> emission;
        Property<float> 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