16 zenith_direction(0, 0, 1),
17 horizon_angle(Geometry::Angle<float>::zero()),
18 fog_color(0.0f, 0.0f, 0.0f, 0.0f),
24 for(vector<Light *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
28 void Lighting::set_ambient(const Color &a)
33 void Lighting::set_sky_color(const Color &s)
38 void Lighting::set_zenith_direction(const Vector3 &d)
43 void Lighting::set_horizon_angle(const Geometry::Angle<float> &a)
48 void Lighting::set_fog_color(const Color &c)
53 void Lighting::set_fog_density(float d)
56 throw invalid_argument("Lighting::set_fog_density");
61 void Lighting::set_fog_half_distance(float d)
63 set_fog_density(-log(pow(0.5, 1.0/d)));
66 void Lighting::attach(unsigned i, const Light &l)
74 void Lighting::detach(unsigned i)
82 const Light *Lighting::get_attached_light(unsigned i) const
84 return i<lights.size() ? lights[i] : 0;
87 void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
89 shdata.uniform("ambient_color", ambient);
90 shdata.uniform("sky_color", sky_color);
91 shdata.uniform("eye_zenith_dir", view_matrix.block<3, 3>(0, 0)*zenith_direction);
92 shdata.uniform("horizon_limit", horizon_angle.radians());
93 shdata.uniform("fog_color", fog_color);
94 shdata.uniform("fog_density", fog_density);
96 // For backwards compatibility
97 shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*zenith_direction);
99 for(unsigned i=0; i<lights.size(); ++i)
101 lights[i]->update_shader_data(shdata, view_matrix, i);
105 Lighting::Loader::Loader(Lighting &l):
106 DataFile::ObjectLoader<Lighting>(l)
108 add("ambient", &Loader::ambient);
109 add("fog_color", &Loader::fog_color);
110 add("fog_density", &Loader::fog_density);
111 add("fog_half_distance", &Loader::fog_half_distance);
112 add("horizon_angle", &Loader::horizon_angle);
113 add("light", &Loader::light);
114 add("sky_color", &Loader::sky_color);
115 add("zenith_direction", &Loader::zenith_direction);
118 void Lighting::Loader::ambient(float r, float g, float b)
120 obj.ambient = Color(r, g, b);
123 void Lighting::Loader::fog_color(float r, float g, float b)
125 obj.set_fog_color(Color(r, g, b));
128 void Lighting::Loader::fog_density(float d)
130 obj.set_fog_density(d);
133 void Lighting::Loader::fog_half_distance(float d)
135 obj.set_fog_half_distance(d);
138 void Lighting::Loader::horizon_angle(float a)
140 obj.set_horizon_angle(Geometry::Angle<float>::from_degrees(a));
143 void Lighting::Loader::light(unsigned i)
145 RefPtr<Light> lgt = new Light;
148 obj.owned_data.push_back(lgt.release());
151 void Lighting::Loader::sky_color(float r, float g, float b)
153 obj.set_sky_color(Color(r, g, b));
156 void Lighting::Loader::zenith_direction(float x, float y, float z)
158 obj.set_zenith_direction(Vector3(x, y, z));