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);
17 set_alpha_feather(1.0f);
20 const Program *Material::create_compatible_shader(const map<string, int> &extra_spec) const
23 map<string, int> spec_values;
25 spec_values["use_alpha_cutoff"] = true;
27 fill_program_info(module_name, spec_values);
29 for(const auto &kvp: extra_spec)
30 spec_values[kvp.first] = kvp.second;
32 uint64_t info_hash = hash<64>(module_name);
33 for(const auto &kvp: spec_values)
35 info_hash = hash_update<64>(info_hash, kvp.first);
36 info_hash = hash_update<64>(info_hash, kvp.second);
39 Resources &res = Resources::get_global();
40 string name = format("_material_%016x.shader", info_hash);
41 Program *shprog = res.find<Program>(name);
45 const Module &module = res.get<Module>(module_name);
46 shprog = new Program(module, spec_values);
49 res.add(name, shprog);
60 void Material::set_alpha_cutoff(float a)
63 shdata.uniform("alpha_cutoff.cutoff", a);
66 void Material::set_alpha_feather(float f)
69 shdata.uniform("alpha_cutoff.feather", f);
72 void Material::set_debug_name(const string &name)
75 shdata.set_debug_name(name+" [UBO]");
81 Material::GenericLoader::TypeRegistry &Material::get_material_registry()
83 static GenericLoader::TypeRegistry registry;
84 static bool initialized = false;
88 registry.register_type<BasicMaterial>("basic");
89 registry.register_type<PbrMaterial>("pbr");
90 registry.register_type<UnlitMaterial>("unlit");
96 Material::Loader::Loader(Material &m, Collection &c):
97 CollectionObjectLoader(m, &c)
100 void Material::Loader::init_actions()
102 add("alpha_cutoff", &Loader::alpha_cutoff);
103 add("alpha_cutoff", &Loader::alpha_cutoff_feather);
104 add("sampler", &Loader::sampler);
107 void Material::Loader::alpha_cutoff(float a)
109 obj.set_alpha_cutoff(a);
112 void Material::Loader::alpha_cutoff_feather(float a, float f)
114 obj.set_alpha_cutoff(a);
115 obj.set_alpha_feather(f);
118 void Material::Loader::sampler(const string &name)
120 obj.sampler = &get_collection().get<Sampler>(name);