+ lights[i] = 0;
+}
+
+const Light *Lighting::get_attached_light(unsigned i) const
+{
+ return i<lights.size() ? lights[i] : 0;
+}
+
+void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
+{
+ shdata.uniform("ambient_color", ambient);
+ shdata.uniform("sky_color", sky_color);
+ shdata.uniform("eye_zenith_dir", view_matrix.block<3, 3>(0, 0)*zenith_direction);
+ shdata.uniform("horizon_limit", horizon_angle.radians());
+ shdata.uniform("fog_color", fog_color);
+ shdata.uniform("fog_density", fog_density);
+
+ // For backwards compatibility
+ shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*zenith_direction);
+
+ for(unsigned i=0; i<lights.size(); ++i)
+ if(lights[i])
+ lights[i]->update_shader_data(shdata, view_matrix, i);
+}
+
+
+Lighting::Loader::Loader(Lighting &l):
+ DataFile::ObjectLoader<Lighting>(l)
+{
+ add("ambient", &Loader::ambient);
+ add("fog_color", &Loader::fog_color);
+ add("fog_density", &Loader::fog_density);
+ add("fog_half_distance", &Loader::fog_half_distance);
+ add("horizon_angle", &Loader::horizon_angle);
+ add("light", &Loader::light);
+ add("sky_color", &Loader::sky_color);
+ add("zenith_direction", &Loader::zenith_direction);