]> git.tdb.fi Git - libs/gl.git/commitdiff
Redesign Light to only have a single color
authorMikko Rasa <tdb@tdb.fi>
Sat, 24 Apr 2021 11:59:22 +0000 (14:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Apr 2021 12:02:23 +0000 (15:02 +0300)
It makes little sense physically to have different diffuse and specular
colors.  The light exporter for Blender was already committed with this
new parameter name.

shaderlib/cooktorrance.glsl
shaderlib/msp_interface.glsl
shaderlib/phong.glsl
source/materials/light.cpp
source/materials/light.h

index 02d697b087c640572a2ed0ebad15fe655ff4f1d2..4315b9ec8b7a8328db3b8ead0661cf8ca4016c24 100644 (file)
@@ -140,7 +140,7 @@ vec3 cooktorrance_lighting(vec3 normal, vec3 look, vec3 base_color, float metaln
                light = normalize(eye_light_dir);
 
        float shadow = get_shadow_factor(0);
                light = normalize(eye_light_dir);
 
        float shadow = get_shadow_factor(0);
-       vec3 color = cooktorrance_one_light_direct(normal, look, light, light_sources[0].diffuse.rgb, base_color, metalness, roughness)*shadow;
+       vec3 color = cooktorrance_one_light_direct(normal, look, light, light_sources[0].color, base_color, metalness, roughness)*shadow;
 
        color *= get_occlusion_value();
 
 
        color *= get_occlusion_value();
 
index ed40aa4a18c0975a1829c93a45cc3fe6ecf2ea49..c4b27b1137e7d77886c15ee510ad0697478a3ff8 100644 (file)
@@ -1,8 +1,7 @@
 struct LightSourceParameters
 {
        vec4 position;
 struct LightSourceParameters
 {
        vec4 position;
-       vec4 diffuse;
-       vec4 specular;
+       vec3 color;
 };
 
 struct ClipPlane
 };
 
 struct ClipPlane
index 570024ab1b5aaa27f22c8796a05d2353c8349511..6b6de6ff17b3416219833202cfa9f626d384d5a5 100644 (file)
@@ -102,7 +102,7 @@ vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_s
 
        vec3 color = phong_ambient(surface_diffuse);
        float shadow = get_shadow_factor(0);
 
        vec3 color = phong_ambient(surface_diffuse);
        float shadow = get_shadow_factor(0);
-       color += phong_one_light(light, normal, look, light_sources[0].diffuse.rgb, surface_diffuse, surface_specular, shininess)*shadow;
+       color += phong_one_light(light, normal, look, light_sources[0].color, surface_diffuse, surface_specular, shininess)*shadow;
 
        if(use_emission)
                color += get_emission_color();
 
        if(use_emission)
                color += get_emission_color();
index e910411f276e27ebd305f507513177787caebb25..d84be2ac8dcc1a8542212df87c6f8063aebbaed2 100644 (file)
@@ -11,8 +11,7 @@ namespace Msp {
 namespace GL {
 
 Light::Light():
 namespace GL {
 
 Light::Light():
-       diffuse(1),
-       specular(1),
+       color(1),
        position(0, 0, 1, 0),
        spot_dir(0, 0, -1),
        spot_exp(0),
        position(0, 0, 1, 0),
        spot_dir(0, 0, -1),
        spot_exp(0),
@@ -40,14 +39,9 @@ void Light::update_matrix()
        matrix = Matrix::from_columns(columns);
 }
 
        matrix = Matrix::from_columns(columns);
 }
 
-void Light::set_diffuse(const Color &c)
+void Light::set_color(const Color &c)
 {
 {
-       diffuse = c;
-}
-
-void Light::set_specular(const Color &c)
-{
-       specular = c;
+       color = c;
 }
 
 void Light::set_matrix(const Matrix &m)
 }
 
 void Light::set_matrix(const Matrix &m)
@@ -107,8 +101,7 @@ void Light::update_shader_data(ProgramData &shdata, const Matrix &view_matrix, u
 {
        string base = format("light_sources[%d]", i);
        shdata.uniform(base+".position", view_matrix*position);
 {
        string base = format("light_sources[%d]", i);
        shdata.uniform(base+".position", view_matrix*position);
-       shdata.uniform(base+".diffuse", diffuse);
-       shdata.uniform(base+".specular", specular);
+       shdata.uniform(base+".color", color.r, color.g, color.b);
 }
 
 
 }
 
 
@@ -116,12 +109,15 @@ Light::Loader::Loader(Light &l):
        DataFile::ObjectLoader<Light>(l)
 {
        add("attenuation", &Loader::attenuation);
        DataFile::ObjectLoader<Light>(l)
 {
        add("attenuation", &Loader::attenuation);
-       add("diffuse", &Loader::diffuse);
+       add("color", &Loader::color);
        add("position", &Loader::position);
        add("position", &Loader::position);
-       add("specular", &Loader::specular);
        add("spot_direction", &Loader::spot_direction);
        add("spot_exponent", &Loader::spot_exponent);
        add("spot_cutoff", &Loader::spot_cutoff);
        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)
 }
 
 void Light::Loader::attenuation(float c, float l, float q)
@@ -129,9 +125,9 @@ void Light::Loader::attenuation(float c, float l, float q)
        obj.set_attenuation(c, l, q);
 }
 
        obj.set_attenuation(c, l, q);
 }
 
-void Light::Loader::diffuse(float r, float g, float b)
+void Light::Loader::color(float r, float g, float b)
 {
 {
-       obj.set_diffuse(Color(r, g, b));
+       obj.set_color(Color(r, g, b));
 }
 
 void Light::Loader::position(float x, float y, float z, float w)
 }
 
 void Light::Loader::position(float x, float y, float z, float w)
@@ -139,11 +135,6 @@ void Light::Loader::position(float x, float y, float z, float w)
        obj.set_position(Vector4(x, y, z, w));
 }
 
        obj.set_position(Vector4(x, y, z, w));
 }
 
-void Light::Loader::specular(float r, float g, float b)
-{
-       obj.set_specular(Color(r, g, b));
-}
-
 void Light::Loader::spot_direction(float x, float y, float z)
 {
        obj.set_spot_direction(Vector3(x, y, z));
 void Light::Loader::spot_direction(float x, float y, float z)
 {
        obj.set_spot_direction(Vector3(x, y, z));
index c7e281887651c7f3d5495f86c34960055d9429e9..d097d04ae435157ebb1c4ddd18cc2bd5857d37d0 100644 (file)
@@ -35,17 +35,15 @@ public:
 
        private:
                void attenuation(float, float, float);
 
        private:
                void attenuation(float, float, float);
-               void diffuse(float, float, float);
+               void color(float, float, float);
                void position(float, float, float, float);
                void position(float, float, float, float);
-               void specular(float, float, float);
                void spot_direction(float, float, float);
                void spot_exponent(float);
                void spot_cutoff(float);
        };
 
 private:
                void spot_direction(float, float, float);
                void spot_exponent(float);
                void spot_cutoff(float);
        };
 
 private:
-       Color diffuse;
-       Color specular;
+       Color color;
        Vector4 position;
        Vector3 spot_dir;
        Vector3 direction;
        Vector4 position;
        Vector3 spot_dir;
        Vector3 direction;
@@ -60,16 +58,16 @@ private:
        void update_matrix();
 
 public:
        void update_matrix();
 
 public:
-       /** Sets the diffuse (direction-independent) color of the Light.  Provided
-       to shaders with the name light_sources[i].diffuse. */
-       void set_diffuse(const Color &c);
+       /** Sets the color of the Light.  Provided
+       to shaders as light_sources[i].color. */
+       void set_color(const Color &);
 
 
-       /** Sets the specular (direction-dependent) color of the Light.  Provided to
-       shaders with the name light_sources[i].specular. */
-       void set_specular(const Color &c);
+       const Color &get_color() const { return color; }
 
 
-       const Color &get_diffuse() const { return diffuse; }
-       const Color &get_specular() const { return specular; }
+       DEPRECATED void set_diffuse(const Color &c) { set_color(c); }
+       DEPRECATED void set_specular(const Color &) { }
+       DEPRECATED const Color &get_diffuse() const { return color; }
+       DEPRECATED const Color &get_specular() const { return color; }
 
        /** Sets the postion and orientation of the Light from a matrix.  Negative Z
        axis is used as the spot direction, other axes are ignored. */
 
        /** Sets the postion and orientation of the Light from a matrix.  Negative Z
        axis is used as the spot direction, other axes are ignored. */