X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fphong.glsl;h=7d8dc295bc93ad95f26ef3d01143c63ec7d3ecb7;hb=e92de029768eef5f0fd744329e589161b46d0762;hp=482f895b44e3e80e50e92586a5c2144319b110c7;hpb=a3c33df71e507380100069ad7ef802b61de351bb;p=libs%2Fgl.git diff --git a/shaderlib/phong.glsl b/shaderlib/phong.glsl index 482f895b..7d8dc295 100644 --- a/shaderlib/phong.glsl +++ b/shaderlib/phong.glsl @@ -85,10 +85,8 @@ vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 light_color, vec3 vec3 color = light_color*surface_diffuse*diffuse_intensity; if(use_specular) { - /* The light vector points towards the light, so reflected will point - towards the surface - but so does the look vector. */ - vec3 reflected = reflect(light, normal); - float specular_intensity = pow(max(dot(reflected, look), 0.0), shininess); + vec3 reflected = reflect(look, normal); + float specular_intensity = pow(max(dot(reflected, light), 0.0), shininess); color += light_color*surface_specular*specular_intensity; } return color; @@ -96,15 +94,11 @@ vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 light_color, vec3 vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess) { - vec3 light; - if(use_normal_map) - light = normalize(tbn_light_dir); - else - light = normalize(eye_light_dir); + vec3 light = normalize(world_light_dir); 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(); @@ -117,18 +111,8 @@ vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_s void main() { - vec3 normal; - vec3 look; - if(use_normal_map) - { - normal = get_fragment_normal(); - look = normalize(tbn_look_dir); - } - else - { - normal = normalize(eye_normal); - look = normalize(eye_look_dir); - } + vec3 normal = get_fragment_normal(); + vec3 look = normalize(world_look_dir); vec4 surface_diffuse = get_diffuse_color(); vec3 surface_specular = get_specular_color();