]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/phong.glsl
Some refactoring of light calculations in shaders
[libs/gl.git] / shaderlib / phong.glsl
index 004232acd503e4c76c607ca6206f2f4e228cdef1..ed091ce9a9374d0646ca900b9ca6210fd4be9dfb 100644 (file)
@@ -79,15 +79,15 @@ vec3 phong_ambient(vec3 surface_diffuse)
        return ambient_color.rgb*surface_diffuse;
 }
 
-vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 light_color, vec3 surface_diffuse, vec3 surface_specular, float shininess)
+vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess)
 {
        float diffuse_intensity = max(dot(light, normal), 0.0);
-       vec3 color = light_color*surface_diffuse*diffuse_intensity;
+       vec3 color = surface_diffuse*diffuse_intensity;
        if(use_specular)
        {
                vec3 reflected = reflect(look, normal);
                float specular_intensity = pow(max(dot(reflected, light), 0.0), shininess);
-               color += light_color*surface_specular*specular_intensity;
+               color += surface_specular*specular_intensity;
        }
        return color;
 }
@@ -98,9 +98,9 @@ vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_s
        for(int i=0; i<max_lights; ++i)
                if(light_sources[i].type!=0)
                {
-                       vec3 light = get_light_direction(i);
+                       IncomingLight incoming = get_incoming_light(i, world_vertex.xyz);
                        float shadow = get_shadow_factor(i);
-                       color += phong_one_light(light, normal, look, light_sources[i].color, surface_diffuse, surface_specular, shininess)*shadow;
+                       color += phong_one_light(incoming.direction, normal, look, surface_diffuse, surface_specular, shininess)*incoming.color*shadow;
                }
 
        if(use_emission)