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 void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
63 shdata.uniform("ambient_color", ambient);
64 shdata.uniform("sky_color", sky_color);
65 shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*sky_direction);
66 shdata.uniform("horizon_limit", horizon_angle.radians());
68 for(unsigned i=0; i<lights.size(); ++i)
70 lights[i]->update_shader_data(shdata, view_matrix, i);
73 void Lighting::bind() const
75 static Require _req(MSP_legacy_features);
76 if(lights.size()>LightUnit::get_n_units())
77 throw invalid_operation("Lighting::bind");
79 if(!set_current(this))
83 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &ambient.r);
84 for(unsigned i=0; i<lights.size(); ++i)
86 lights[i]->bind_to(i);
89 void Lighting::unbind()
91 const Lighting *old = current();
95 for(unsigned i=0; i<old->lights.size(); ++i)
97 Light::unbind_from(i);