X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Fpbrmaterial.cpp;h=7c73996fd2f7b8e91af2ab4eb27d08fd5592de70;hb=cb7db94f7837e6a3be037d07575dc248177d9426;hp=bc7104cc652d485350614b5737b32e6a42771f80;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/materials/pbrmaterial.cpp b/source/materials/pbrmaterial.cpp index bc7104cc..7c73996f 100644 --- a/source/materials/pbrmaterial.cpp +++ b/source/materials/pbrmaterial.cpp @@ -5,8 +5,18 @@ using namespace std; namespace Msp { namespace GL { -PbrMaterial::PbrMaterial(): - receive_shadows(false) +const Tag PbrMaterial::texture_tags[] = +{ + Tag("base_color_map"), + Tag("normal_map"), + Tag("metalness_map"), + Tag("roughness_map"), + Tag("occlusion_map"), + Tag("emission_map"), + Tag() +}; + +PbrMaterial::PbrMaterial() { set_base_color(0.8f); set_metalness(0.0f); @@ -14,30 +24,21 @@ PbrMaterial::PbrMaterial(): set_emission(0.0f); } -string PbrMaterial::create_program_source() const -{ - string source = "import cooktorrance;\n"; - if(base_color.texture) - source += "const bool use_base_color_map = true;\n"; - if(normal.texture) - source += "const bool use_normal_map = true;\n"; - if(metalness.texture) - source += "const bool use_metalness_map = true;\n"; - if(roughness.texture) - source += "const bool use_roughness_map = true;\n"; - if(occlusion.texture) - source += "const bool use_occlusion_map = true;\n"; - if(emission.texture || emission.value.r || emission.value.g || emission.value.b) - { - source += "const bool use_emission = true;\n"; - if(emission.texture) - source += "const bool use_emission_map = true;\n"; - } - if(receive_shadows) - source += "const bool use_shadow_map = true;\n"; - return source; +void PbrMaterial::fill_program_info(string &module_name, map &spec_values) const +{ + module_name = "cooktorrance.glsl"; + spec_values["use_base_color_map"] = (base_color.texture!=0); + spec_values["use_normal_map"] = (normal.texture!=0); + spec_values["use_metalness_map"] = (metalness.texture!=0); + spec_values["use_roughness_map"] = (roughness.texture!=0); + spec_values["use_occlusion_map"] = (occlusion.texture!=0); + 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); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const { attach_texture_to(base_color.texture, texturing, tex_shdata, "base_color_map"); @@ -47,6 +48,25 @@ void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shda attach_texture_to(occlusion.texture, texturing, tex_shdata, "occlusion_map"); attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map"); } +#pragma GCC diagnostic pop + +const Texture *PbrMaterial::get_texture(Tag tag) const +{ + if(tag==texture_tags[0]) + return base_color.texture; + else if(tag==texture_tags[1]) + return normal.texture; + else if(tag==texture_tags[2]) + return metalness.texture; + else if(tag==texture_tags[3]) + return roughness.texture; + else if(tag==texture_tags[4]) + return occlusion.texture; + else if(tag==texture_tags[5]) + return emission.texture; + else + return 0; +} void PbrMaterial::set_base_color(const Color &color) { @@ -102,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; @@ -131,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