X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Flight.cpp;h=3d3cba0a87127116068aa85900e24656e1f83841;hp=2825b81eaa745f70b9d5aa4ed6009e499c4dce5c;hb=a275d25eccad43716c5dcf91f8bc4af2a53c0445;hpb=a77629d781eeb789870470c5ebdbd4b691e1b138 diff --git a/source/materials/light.cpp b/source/materials/light.cpp index 2825b81e..3d3cba0a 100644 --- a/source/materials/light.cpp +++ b/source/materials/light.cpp @@ -16,7 +16,8 @@ Light::Light(): position(0, 0, 1, 0), spot_dir(0, 0, -1), spot_exp(0), - spot_cutoff(Geometry::Angle::straight()) + spot_cutoff(Geometry::Angle::straight()), + generation(0) { attenuation[0] = 1; attenuation[1] = 0; @@ -43,11 +44,13 @@ void Light::update_matrix() void Light::set_color(const Color &c) { color = c; + ++generation; } void Light::set_transmittance(const Color &t) { transmittance = t; + ++generation; } void Light::set_matrix(const Matrix &m) @@ -57,6 +60,7 @@ void Light::set_matrix(const Matrix &m) spot_dir = normalize(-matrix.column(2).slice<3>(0)); direction = (position.w ? spot_dir : normalize(-position.slice<3>(0))); update_matrix(); + ++generation; } void Light::set_position(const Vector4 &p) @@ -65,6 +69,7 @@ void Light::set_position(const Vector4 &p) if(!position.w) direction = normalize(-position.slice<3>(0)); update_matrix(); + ++generation; } void Light::set_spot_direction(const Vector3 &d) @@ -73,6 +78,7 @@ void Light::set_spot_direction(const Vector3 &d) if(position.w) direction = spot_dir; update_matrix(); + ++generation; } void Light::set_spot_exponent(float e) @@ -81,6 +87,7 @@ void Light::set_spot_exponent(float e) throw invalid_argument("Light::set_spot_exponent"); spot_exp = e; + ++generation; } void Light::set_spot_cutoff(const Geometry::Angle &c) @@ -89,11 +96,13 @@ void Light::set_spot_cutoff(const Geometry::Angle &c) throw invalid_argument("Light::set_spot_cutoff"); spot_cutoff = c; + ++generation; } void Light::disable_spot_cutoff() { set_spot_cutoff(Geometry::Angle::straight()); + ++generation; } void Light::set_attenuation(float c, float l, float q) @@ -101,13 +110,15 @@ void Light::set_attenuation(float c, float l, float q) attenuation[0] = c; attenuation[1] = l; attenuation[2] = q; + ++generation; } -void Light::update_shader_data(ProgramData &shdata, const Matrix &view_matrix, unsigned i) const +void Light::update_shader_data(ProgramData &shdata, unsigned i) const { string base = format("light_sources[%d]", i); - shdata.uniform(base+".position", view_matrix*position); + shdata.uniform(base+".position", position); shdata.uniform(base+".color", color.r*transmittance.r, color.g*transmittance.g, color.b*transmittance.b); + shdata.uniform(base+".enabled", 1); }