3 #include <msp/core/algorithm.h>
17 zenith_direction(0, 0, 1),
18 horizon_angle(Geometry::Angle<float>::zero()),
19 fog_color(0.0f, 0.0f, 0.0f, 0.0f),
25 for(vector<Light *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
29 void Lighting::set_ambient(const Color &a)
34 void Lighting::set_sky_color(const Color &s)
39 void Lighting::set_zenith_direction(const Vector3 &d)
44 void Lighting::set_horizon_angle(const Geometry::Angle<float> &a)
49 void Lighting::set_fog_color(const Color &c)
54 void Lighting::set_fog_density(float d)
57 throw invalid_argument("Lighting::set_fog_density");
62 void Lighting::set_fog_half_distance(float d)
64 set_fog_density(-log(pow(0.5, 1.0/d)));
67 void Lighting::attach(const Light &l)
69 if(find(lights, &l)==lights.end())
73 void Lighting::detach(const Light &l)
75 vector<const Light *>::iterator i = find(lights, &l);
80 void Lighting::detach(unsigned i)
88 const Light *Lighting::get_attached_light(unsigned i) const
90 return i<lights.size() ? lights[i] : 0;
93 void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
95 shdata.uniform("ambient_color", ambient);
96 shdata.uniform("sky_color", sky_color);
97 shdata.uniform("world_zenith_dir", zenith_direction);
98 shdata.uniform("horizon_limit", horizon_angle.radians());
99 shdata.uniform("fog_color", fog_color);
100 shdata.uniform("fog_density", fog_density);
102 for(unsigned i=0; i<lights.size(); ++i)
104 lights[i]->update_shader_data(shdata, view_matrix, i);
108 DataFile::Loader::ActionMap Lighting::Loader::shared_actions;
110 Lighting::Loader::Loader(Lighting &l):
111 CollectionObjectLoader<Lighting>(l, 0)
113 set_actions(shared_actions);
116 Lighting::Loader::Loader(Lighting &l, Collection &c):
117 CollectionObjectLoader<Lighting>(l, &c)
119 set_actions(shared_actions);
122 void Lighting::Loader::init_actions()
124 add("ambient", &Loader::ambient);
125 add("fog_color", &Loader::fog_color);
126 add("fog_density", &Loader::fog_density);
127 add("fog_half_distance", &Loader::fog_half_distance);
128 add("horizon_angle", &Loader::horizon_angle);
129 add("light", &Loader::light);
130 add("light", &Loader::light_inline);
131 add("sky_color", &Loader::sky_color);
132 add("zenith_direction", &Loader::zenith_direction);
135 add("light", &Loader::light_inline_index);
138 void Lighting::Loader::ambient(float r, float g, float b)
140 obj.ambient = Color(r, g, b);
143 void Lighting::Loader::fog_color(float r, float g, float b)
145 obj.set_fog_color(Color(r, g, b));
148 void Lighting::Loader::fog_density(float d)
150 obj.set_fog_density(d);
153 void Lighting::Loader::fog_half_distance(float d)
155 obj.set_fog_half_distance(d);
158 void Lighting::Loader::horizon_angle(float a)
160 obj.set_horizon_angle(Geometry::Angle<float>::from_degrees(a));
163 void Lighting::Loader::light(const string &name)
165 obj.attach(get_collection().get<Light>(name));
168 void Lighting::Loader::light_inline()
170 RefPtr<Light> lgt = new Light;
173 obj.owned_data.push_back(lgt.release());
176 void Lighting::Loader::light_inline_index(unsigned)
181 void Lighting::Loader::sky_color(float r, float g, float b)
183 obj.set_sky_color(Color(r, g, b));
186 void Lighting::Loader::zenith_direction(float x, float y, float z)
188 obj.set_zenith_direction(Vector3(x, y, z));