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 uint64_t info_hash = hash<64>(module_name);
24 for(const auto &kvp: spec_values)
26 info_hash = hash_update<64>(info_hash, kvp.first);
27 info_hash = hash_update<64>(info_hash, kvp.second);
30 Resources &res = Resources::get_global();
31 string name = format("_material_%016x.shader", info_hash);
32 Program *shprog = res.find<Program>(name);
36 const Module &module = res.get<Module>(module_name);
37 shprog = new Program(module, spec_values);
40 res.add(name, shprog);
51 void Material::set_debug_name(const string &name)
54 shdata.set_debug_name(name+" [UBO]");
60 Material::GenericLoader::TypeRegistry &Material::get_material_registry()
62 static GenericLoader::TypeRegistry registry;
63 static bool initialized = false;
67 registry.register_type<BasicMaterial>("basic");
68 registry.register_type<PbrMaterial>("pbr");
69 registry.register_type<UnlitMaterial>("unlit");
75 Material::Loader::Loader(Material &m, Collection &c):
76 CollectionObjectLoader(m, &c)
79 void Material::Loader::init_actions()
81 add("sampler", &Loader::sampler);
84 void Material::Loader::sampler(const string &name)
86 obj.sampler = &get_collection().get<Sampler>(name);