From 4c11957c4e26b2c369f0399c85bafcb6eb58edd4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 12 Apr 2021 17:40:04 +0300 Subject: [PATCH] Adjust specular calculation in the Phong shader Since the look vector points towards the surface, it makes more sense to calculate the reflected vector towards the light. The calculation is symmetric so the result is the same. --- shaderlib/phong.glsl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/shaderlib/phong.glsl b/shaderlib/phong.glsl index 482f895b..570024ab 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; -- 2.43.0