]> git.tdb.fi Git - libs/gl.git/commitdiff
Move the receive_shadows flag to RenderPass
authorMikko Rasa <tdb@tdb.fi>
Mon, 19 Apr 2021 08:25:20 +0000 (11:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 19 Apr 2021 15:02:20 +0000 (18:02 +0300)
It doesn't seem so much a property of the surface itself as the
environment it's rendered in.

source/materials/basicmaterial.cpp
source/materials/basicmaterial.h
source/materials/material.cpp
source/materials/material.h
source/materials/pbrmaterial.cpp
source/materials/pbrmaterial.h
source/materials/renderpass.cpp
source/materials/renderpass.h

index 5ad694b685803e892032b24a0d199cda86befca7..30202a568f62a7964700f7f765cc3af84c3350f6 100644 (file)
@@ -16,8 +16,7 @@ const Tag BasicMaterial::texture_tags[] =
        Tag()
 };
 
-BasicMaterial::BasicMaterial():
-       receive_shadows(false)
+BasicMaterial::BasicMaterial()
 {
        set_diffuse(Color(1.0f));
        set_specular(Color(0.0f));
@@ -40,7 +39,6 @@ void BasicMaterial::fill_program_info(string &module_name, map<string, int> &spe
        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
@@ -134,11 +132,6 @@ 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;
 
@@ -163,7 +156,6 @@ 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 2b27b212b6e6f8430dc6e54202fd1a34803bef34..bf4a1c1c5d16bccbec28edbf0f63fd018041f338 100644 (file)
@@ -29,7 +29,6 @@ private:
        Property<Vector3> normal;
        Property<Color> emission;
        Property<float> reflectivity;
-       bool receive_shadows;
 
        static const Tag texture_tags[];
 
@@ -56,7 +55,6 @@ public:
        void set_shininess_map(const Texture *);
        void set_reflectivity(float);
        void set_reflectivity_map(const Texture *);
-       void set_receive_shadows(bool);
 };
 
 } // namespace GL
index 36d0958f5afb18aaa5270750f7c8e031193583a4..b737c03183b504b82592f5959cfd70e80ec10f77 100644 (file)
@@ -13,12 +13,15 @@ using namespace std;
 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);
index 278fc4dc0ee8ba7da8ce27fcd392d5c4bf0c2b46..8f387a43bfacfbdc4b2b5629d1a5a718f653a5cd 100644 (file)
@@ -97,7 +97,7 @@ protected:
 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;
 
index 92801204ee0ddb7764e543c271a916363591741a..7c73996fd2f7b8e91af2ab4eb27d08fd5592de70 100644 (file)
@@ -16,8 +16,7 @@ const Tag PbrMaterial::texture_tags[] =
        Tag()
 };
 
-PbrMaterial::PbrMaterial():
-       receive_shadows(false)
+PbrMaterial::PbrMaterial()
 {
        set_base_color(0.8f);
        set_metalness(0.0f);
@@ -36,7 +35,6 @@ void PbrMaterial::fill_program_info(string &module_name, map<string, int> &spec_
        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
@@ -124,11 +122,6 @@ void PbrMaterial::set_emission_map(const Texture *tex)
        emission.texture = tex;
 }
 
-void PbrMaterial::set_receive_shadows(bool s)
-{
-       receive_shadows = s;
-}
-
 
 DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
 
@@ -153,7 +146,6 @@ void PbrMaterial::Loader::init_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
index 00e5e1babc64ded6c83b1ff894f0f5a78a0e672b..3e9b26ade8d525aff7b08c4d399d34f36e5d8f0c 100644 (file)
@@ -29,7 +29,6 @@ private:
        Property<float> roughness;
        Property<float> occlusion;
        Property<Color> emission;
-       bool receive_shadows;
 
        static const Tag texture_tags[];
 
@@ -55,7 +54,6 @@ public:
        void set_occlusion_map(const Texture *);
        void set_emission(const Color &);
        void set_emission_map(const Texture *);
-       void set_receive_shadows(bool);
 };
 
 } // namespace GL
index 951cbb5d1557e5f16aad121b8bef7d10e4a78c46..35692a4eaa69d49e54666e5684ff46b04f03c324 100644 (file)
@@ -22,7 +22,8 @@ RenderPass::RenderPass():
        shprog_from_material(false),
        shdata(0),
        material(0),
-       back_faces(false)
+       back_faces(false),
+       receive_shadows(false)
 { }
 
 void RenderPass::set_material_textures()
@@ -37,9 +38,13 @@ void RenderPass::maybe_create_material_shader(DataFile::Collection *coll)
        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
@@ -125,6 +130,11 @@ int RenderPass::get_texture_index(const string &n) const
        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)
@@ -156,6 +166,7 @@ void RenderPass::Loader::init_actions()
        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);
index b5b9cfb5af107149f1b01e930193aedae33539ec..46fb7a3535a0bb51a2417e190e3cf3f3dd5a809e 100644 (file)
@@ -79,6 +79,7 @@ private:
        std::string material_slot;
        std::vector<TextureSlot> textures;
        bool back_faces;
+       bool receive_shadows;
 
 public:
        RenderPass();
@@ -102,6 +103,8 @@ public:
        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;
 };