diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index b70fb8f04..230af1736 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -8,6 +8,7 @@ uniform float shininess = 80.0; in vec3 transformedNormal; in vec3 lightDirection; +in vec3 cameraDirection; out vec4 color; @@ -25,7 +26,7 @@ void main() { /* Add specular color, if needed */ if(intensity != 0) { vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal); - float specularity = pow(max(0.0, dot(normalizedTransformedNormal, reflection)), shininess); + float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess); color.rgb += specularColor*specularity; } diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index 2a8ef00a0..5b73ccd79 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -9,6 +9,7 @@ in vec3 normal; out vec3 transformedNormal; out vec3 lightDirection; +out vec3 cameraDirection; void main() { /* Transformed vertex position */ @@ -21,6 +22,9 @@ void main() { /* Direction to the light */ lightDirection = normalize(light - transformedVertex); + /* Direction to the camera */ + cameraDirection = -transformedVertex; + /* Transform the vertex */ gl_Position = projectionMatrix*transformedVertex4; }