From: Mikko Rasa Date: Mon, 19 Apr 2021 08:25:20 +0000 (+0300) Subject: Move the receive_shadows flag to RenderPass X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=cb7db94f7837e6a3be037d07575dc248177d9426 Move the receive_shadows flag to RenderPass It doesn't seem so much a property of the surface itself as the environment it's rendered in. --- diff --git a/source/materials/basicmaterial.cpp b/source/materials/basicmaterial.cpp index 5ad694b6..30202a56 100644 --- a/source/materials/basicmaterial.cpp +++ b/source/materials/basicmaterial.cpp @@ -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 &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 diff --git a/source/materials/basicmaterial.h b/source/materials/basicmaterial.h index 2b27b212..bf4a1c1c 100644 --- a/source/materials/basicmaterial.h +++ b/source/materials/basicmaterial.h @@ -29,7 +29,6 @@ private: Property normal; Property emission; Property 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 diff --git a/source/materials/material.cpp b/source/materials/material.cpp index 36d0958f..b737c031 100644 --- a/source/materials/material.cpp +++ b/source/materials/material.cpp @@ -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 &extra_spec) const { string module_name; map spec_values; fill_program_info(module_name, spec_values); + for(map::const_iterator i=extra_spec.begin(); i!=extra_spec.end(); ++i) + spec_values[i->first] = i->second; + string info = module_name; for(map::const_iterator i=spec_values.begin(); i!=spec_values.end(); ++i) info += format(",%s:%d", i->first, i->second); diff --git a/source/materials/material.h b/source/materials/material.h index 278fc4dc..8f387a43 100644 --- a/source/materials/material.h +++ b/source/materials/material.h @@ -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::map()) const; protected: virtual void fill_program_info(std::string &, std::map &) const = 0; diff --git a/source/materials/pbrmaterial.cpp b/source/materials/pbrmaterial.cpp index 92801204..7c73996f 100644 --- a/source/materials/pbrmaterial.cpp +++ b/source/materials/pbrmaterial.cpp @@ -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 &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 diff --git a/source/materials/pbrmaterial.h b/source/materials/pbrmaterial.h index 00e5e1ba..3e9b26ad 100644 --- a/source/materials/pbrmaterial.h +++ b/source/materials/pbrmaterial.h @@ -29,7 +29,6 @@ private: Property roughness; Property occlusion; Property 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 diff --git a/source/materials/renderpass.cpp b/source/materials/renderpass.cpp index 951cbb5d..35692a4e 100644 --- a/source/materials/renderpass.cpp +++ b/source/materials/renderpass.cpp @@ -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 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::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); diff --git a/source/materials/renderpass.h b/source/materials/renderpass.h index b5b9cfb5..46fb7a35 100644 --- a/source/materials/renderpass.h +++ b/source/materials/renderpass.h @@ -79,6 +79,7 @@ private: std::string material_slot; std::vector 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; };