15 sky_direction(0, 0, 1),
16 horizon_angle(Geometry::Angle<float>::zero())
19 void Lighting::set_ambient(const Color &a)
24 void Lighting::set_sky_color(const Color &s)
29 void Lighting::set_sky_direction(const Vector3 &d)
34 void Lighting::set_horizon_angle(const Geometry::Angle<float> &a)
39 void Lighting::attach(unsigned i, const Light &l)
41 if(i>=LightUnit::get_n_units())
42 throw out_of_range("Lighting::attach");
52 void Lighting::detach(unsigned i)
59 Light::unbind_from(i);
62 void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
64 shdata.uniform("ambient_color", ambient);
65 shdata.uniform("sky_color", sky_color);
66 shdata.uniform("eye_sky_dir", Vector3(view_matrix*Vector4(sky_direction, 0.0f)));
67 shdata.uniform("horizon_limit", horizon_angle.radians());
69 for(unsigned i=0; i<lights.size(); ++i)
71 lights[i]->update_shader_data(shdata, view_matrix, i);
74 void Lighting::bind() const
76 if(!set_current(this))
80 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &ambient.r);
81 for(unsigned i=0; i<lights.size(); ++i)
83 lights[i]->bind_to(i);
86 void Lighting::unbind()
88 const Lighting *old = current();
92 for(unsigned i=0; i<old->lights.size(); ++i)
94 Light::unbind_from(i);