1 #include <msp/core/hash.h>
2 #include <msp/strings/format.h>
3 #include "basicmaterial.h"
4 #include "pbrmaterial.h"
7 #include "splatmaterial.h"
8 #include "unlitmaterial.h"
17 set_alpha_cutoff(0.0f);
18 set_alpha_feather(1.0f);
21 const Program *Material::create_compatible_shader(const map<string, int> &extra_spec) const
24 map<string, int> spec_values;
26 spec_values["use_alpha_cutoff"] = true;
28 fill_program_info(module_name, spec_values);
30 for(const auto &kvp: extra_spec)
31 spec_values[kvp.first] = kvp.second;
33 uint64_t info_hash = hash<64>(module_name);
34 for(const auto &kvp: spec_values)
36 info_hash = hash_update<64>(info_hash, kvp.first);
37 info_hash = hash_update<64>(info_hash, kvp.second);
40 Resources &res = Resources::get_global();
41 string name = format("_material_%016x.shader", info_hash);
42 Program *shprog = res.find<Program>(name);
46 const Module &module = res.get<Module>(module_name);
47 shprog = new Program(module, spec_values);
50 res.add(name, shprog);
61 void Material::set_alpha_cutoff(float a)
64 shdata.uniform("alpha_cutoff.cutoff", a);
67 void Material::set_alpha_feather(float f)
70 shdata.uniform("alpha_cutoff.feather", f);
73 void Material::set_debug_name(const string &name)
76 shdata.set_debug_name(name+" [UBO]");
82 Material::GenericLoader::TypeRegistry &Material::get_material_registry()
84 static GenericLoader::TypeRegistry registry;
85 static bool initialized = false;
89 registry.register_type<BasicMaterial>("basic");
90 registry.register_type<PbrMaterial>("pbr");
91 registry.register_type<SplatMaterial>("splat");
92 registry.register_type<UnlitMaterial>("unlit");
98 Material::Loader::Loader(Material &m, Collection &c):
99 CollectionObjectLoader(m, &c)
102 void Material::Loader::init_actions()
104 add("alpha_cutoff", &Loader::alpha_cutoff);
105 add("alpha_cutoff", &Loader::alpha_cutoff_feather);
106 add("sampler", &Loader::sampler);
109 void Material::Loader::alpha_cutoff(float a)
111 obj.set_alpha_cutoff(a);
114 void Material::Loader::alpha_cutoff_feather(float a, float f)
116 obj.set_alpha_cutoff(a);
117 obj.set_alpha_feather(f);
120 void Material::Loader::sampler(const string &name)
122 obj.sampler = &get_collection().get<Sampler>(name);