1 #include <msp/core/hash.h>
2 #include <msp/strings/format.h>
3 #include "basicmaterial.h"
4 #include "pbrmaterial.h"
7 #include "unlitmaterial.h"
16 set_alpha_cutoff(0.0f);
19 const Program *Material::create_compatible_shader(const map<string, int> &extra_spec) const
22 map<string, int> spec_values;
24 spec_values["use_alpha_cutoff"] = true;
26 fill_program_info(module_name, spec_values);
28 for(const auto &kvp: extra_spec)
29 spec_values[kvp.first] = kvp.second;
31 uint64_t info_hash = hash<64>(module_name);
32 for(const auto &kvp: spec_values)
34 info_hash = hash_update<64>(info_hash, kvp.first);
35 info_hash = hash_update<64>(info_hash, kvp.second);
38 Resources &res = Resources::get_global();
39 string name = format("_material_%016x.shader", info_hash);
40 Program *shprog = res.find<Program>(name);
44 const Module &module = res.get<Module>(module_name);
45 shprog = new Program(module, spec_values);
48 res.add(name, shprog);
59 void Material::set_alpha_cutoff(float a)
62 shdata.uniform("alpha_cutoff", a);
65 void Material::set_debug_name(const string &name)
68 shdata.set_debug_name(name+" [UBO]");
74 Material::GenericLoader::TypeRegistry &Material::get_material_registry()
76 static GenericLoader::TypeRegistry registry;
77 static bool initialized = false;
81 registry.register_type<BasicMaterial>("basic");
82 registry.register_type<PbrMaterial>("pbr");
83 registry.register_type<UnlitMaterial>("unlit");
89 Material::Loader::Loader(Material &m, Collection &c):
90 CollectionObjectLoader(m, &c)
93 void Material::Loader::init_actions()
95 add("alpha_cutoff", &Loader::alpha_cutoff);
96 add("sampler", &Loader::sampler);
99 void Material::Loader::alpha_cutoff(float a)
101 obj.set_alpha_cutoff(a);
104 void Material::Loader::sampler(const string &name)
106 obj.sampler = &get_collection().get<Sampler>(name);