2 #include <msp/gl/extensions/msp_legacy_features.h>
17 sky_direction(0, 0, 1),
18 horizon_angle(Geometry::Angle<float>::zero())
21 void Lighting::set_ambient(const Color &a)
26 void Lighting::set_sky_color(const Color &s)
31 void Lighting::set_sky_direction(const Vector3 &d)
36 void Lighting::set_horizon_angle(const Geometry::Angle<float> &a)
41 void Lighting::attach(unsigned i, const Light &l)
51 void Lighting::detach(unsigned i)
58 Light::unbind_from(i);
61 const Light *Lighting::get_attached_light(unsigned i) const
63 return i<lights.size() ? lights[i] : 0;
66 void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
68 shdata.uniform("ambient_color", ambient);
69 shdata.uniform("sky_color", sky_color);
70 shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*sky_direction);
71 shdata.uniform("horizon_limit", horizon_angle.radians());
73 for(unsigned i=0; i<lights.size(); ++i)
75 lights[i]->update_shader_data(shdata, view_matrix, i);
78 void Lighting::bind() const
80 static Require _req(MSP_legacy_features);
81 if(lights.size()>LightUnit::get_n_units())
82 throw invalid_operation("Lighting::bind");
84 if(!set_current(this))
88 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &ambient.r);
89 for(unsigned i=0; i<lights.size(); ++i)
91 lights[i]->bind_to(i);
94 void Lighting::unbind()
96 const Lighting *old = current();
100 for(unsigned i=0; i<old->lights.size(); ++i)
102 Light::unbind_from(i);
104 disable(GL_LIGHTING);