1 #include <msp/core/hash.h>
2 #include <msp/strings/format.h>
3 #include "basicmaterial.h"
4 #include "pbrmaterial.h"
7 #include "unlitmaterial.h"
14 const Program *Material::create_compatible_shader(const map<string, int> &extra_spec) const
17 map<string, int> spec_values;
18 fill_program_info(module_name, spec_values);
20 for(const auto &kvp: extra_spec)
21 spec_values[kvp.first] = kvp.second;
23 string info = module_name;
24 for(const auto &kvp: spec_values)
25 info += format(",%s:%d", kvp.first, kvp.second);
27 Resources &res = Resources::get_global();
28 string name = format("_material_%016x.shader", hash64(info));
29 Program *shprog = res.find<Program>(name);
33 const Module &module = res.get<Module>(module_name);
34 shprog = new Program(module, spec_values);
37 res.add(name, shprog);
48 void Material::set_debug_name(const string &name)
51 shdata.set_debug_name(name+" [UBO]");
57 Material::GenericLoader::TypeRegistry &Material::get_material_registry()
59 static GenericLoader::TypeRegistry registry;
60 static bool initialized = false;
64 registry.register_type<BasicMaterial>("basic");
65 registry.register_type<PbrMaterial>("pbr");
66 registry.register_type<UnlitMaterial>("unlit");
72 Material::Loader::Loader(Material &m, Collection &c):
73 CollectionObjectLoader(m, &c)
76 void Material::Loader::init_actions()
78 add("sampler", &Loader::sampler);
81 void Material::Loader::sampler(const string &name)
83 obj.sampler = &get_collection().get<Sampler>(name);