3 #include <msp/core/algorithm.h>
4 #include <msp/datafile/collection.h>
5 #include <msp/fs/utils.h>
6 #include <msp/strings/format.h>
18 set_fog_color(Color(0.0f, 0.0f, 0.0f, 0.0f));
19 set_fog_density(0.0f);
22 void Lighting::set_ambient(const Color &a)
25 shdata.uniform("ambient_color", ambient);
28 void Lighting::set_fog_color(const Color &c)
31 shdata.uniform("fog_color", fog_color);
34 void Lighting::set_fog_density(float d)
37 throw invalid_argument("Lighting::set_fog_density");
40 shdata.uniform("fog_density", fog_density);
43 void Lighting::set_fog_half_distance(float d)
45 set_fog_density(-log(pow(0.5, 1.0/d)));
48 void Lighting::attach(const Light &l)
50 if(find_member(lights, &l, &AttachedLight::light)==lights.end())
54 void Lighting::detach(const Light &l)
56 auto i = find_member(lights, &l, &AttachedLight::light);
61 const ProgramData &Lighting::get_shader_data() const
63 for(unsigned i=0; i<lights.size(); ++i)
64 if(lights[i].light->get_generation()!=lights[i].generation)
66 lights[i].light->update_shader_data(shdata, i);
67 lights[i].generation = lights[i].light->get_generation();
73 void Lighting::set_debug_name(const string &name)
76 shdata.set_debug_name(name+" [UBO]");
83 DataFile::Loader::ActionMap Lighting::Loader::shared_actions;
85 Lighting::Loader::Loader(Lighting &l):
86 CollectionObjectLoader<Lighting>(l, 0)
88 set_actions(shared_actions);
91 Lighting::Loader::Loader(Lighting &l, Collection &c):
92 CollectionObjectLoader<Lighting>(l, &c)
94 set_actions(shared_actions);
97 void Lighting::Loader::init_actions()
99 add("ambient", &Loader::ambient);
100 add("fog_color", &Loader::fog_color);
101 add("fog_density", &Loader::fog_density);
102 add("fog_half_distance", &Loader::fog_half_distance);
103 add("light", &Loader::light);
104 add("light", &Loader::light_inline);
107 void Lighting::Loader::ambient(float r, float g, float b)
109 obj.set_ambient(Color(r, g, b));
112 void Lighting::Loader::fog_color(float r, float g, float b)
114 obj.set_fog_color(Color(r, g, b));
117 void Lighting::Loader::fog_density(float d)
119 obj.set_fog_density(d);
122 void Lighting::Loader::fog_half_distance(float d)
124 obj.set_fog_half_distance(d);
127 void Lighting::Loader::light(const string &name)
129 obj.attach(get_collection().get<Light>(name));
132 void Lighting::Loader::light_inline()
134 RefPtr<Light> lgt = new Light;
136 get_collection().add(format("%s/%d.light", FS::basename(get_source()), obj.lights.size()), lgt.get());
137 obj.attach(*lgt.release());