16 sky_direction(0, 0, 1),
17 horizon_angle(Geometry::Angle<float>::zero())
20 void Lighting::set_ambient(const Color &a)
25 void Lighting::set_sky_color(const Color &s)
30 void Lighting::set_sky_direction(const Vector3 &d)
35 void Lighting::set_horizon_angle(const Geometry::Angle<float> &a)
40 void Lighting::attach(unsigned i, const Light &l)
50 void Lighting::detach(unsigned i)
57 Light::unbind_from(i);
60 void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
62 shdata.uniform("ambient_color", ambient);
63 shdata.uniform("sky_color", sky_color);
64 shdata.uniform("eye_sky_dir", Vector3(view_matrix*Vector4(sky_direction, 0.0f)));
65 shdata.uniform("horizon_limit", horizon_angle.radians());
67 for(unsigned i=0; i<lights.size(); ++i)
69 lights[i]->update_shader_data(shdata, view_matrix, i);
72 void Lighting::bind() const
74 if(lights.size()>LightUnit::get_n_units())
75 throw invalid_operation("Lighting::bind");
77 if(!set_current(this))
81 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &ambient.r);
82 for(unsigned i=0; i<lights.size(); ++i)
84 lights[i]->bind_to(i);
87 void Lighting::unbind()
89 const Lighting *old = current();
93 for(unsigned i=0; i<old->lights.size(); ++i)
95 Light::unbind_from(i);