X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Flight.cpp;h=7c78b393fc32431b43904ed1dcdd14409446bb94;hb=5008778dbb1840bf7c6d479800d2b932f8386fb2;hp=d84be2ac8dcc1a8542212df87c6f8063aebbaed2;hpb=615f1717f32064a7adb2b848e8646c2c3cf11f61;p=libs%2Fgl.git diff --git a/source/materials/light.cpp b/source/materials/light.cpp index d84be2ac..7c78b393 100644 --- a/source/materials/light.cpp +++ b/source/materials/light.cpp @@ -1,8 +1,6 @@ #include #include #include "light.h" -#include "matrix.h" -#include "misc.h" #include "programdata.h" using namespace std; @@ -12,10 +10,12 @@ namespace GL { Light::Light(): color(1), + transmittance(1), 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; @@ -42,6 +42,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) @@ -51,6 +58,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) @@ -59,6 +67,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) @@ -67,6 +76,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) @@ -75,6 +85,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) @@ -83,11 +94,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) @@ -95,13 +108,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+".color", color.r, color.g, color.b); + 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); } @@ -114,10 +129,6 @@ Light::Loader::Loader(Light &l): add("spot_direction", &Loader::spot_direction); add("spot_exponent", &Loader::spot_exponent); add("spot_cutoff", &Loader::spot_cutoff); - - // Deprecated - add("diffuse", &Loader::color); - add("specular"); } void Light::Loader::attenuation(float c, float l, float q)