Browse Source

Finally fixed light intensity computation bug in PhongShader.

Both vectors passed to dot() (and thus also reflect()) must be
normalized to achieve desired result.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
5c9310605a
  1. 9
      src/Shaders/PhongShader.frag

9
src/Shaders/PhongShader.frag

@ -18,14 +18,17 @@ void main() {
/* Ambient color */ /* Ambient color */
color.rgb = ambientColor*lightAmbientColor; color.rgb = ambientColor*lightAmbientColor;
vec3 normalizedTransformedNormal = normalize(transformedNormal);
vec3 normalizedLightDirection = normalize(lightDirection);
/* Add diffuse color */ /* Add diffuse color */
float intensity = max(0.0, dot(transformedNormal, lightDirection)); float intensity = max(0.0, dot(normalizedTransformedNormal, normalizedLightDirection));
color.rgb += diffuseColor*lightDiffuseColor*intensity; color.rgb += diffuseColor*lightDiffuseColor*intensity;
/* Add specular color, if needed */ /* Add specular color, if needed */
if(intensity != 0) { if(intensity != 0) {
vec3 reflection = reflect(-lightDirection, transformedNormal); vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal);
float specularity = pow(max(0.0, dot(transformedNormal, reflection)), shininess); float specularity = pow(max(0.0, dot(normalizedTransformedNormal, reflection)), shininess);
color.rgb += specularColor*lightSpecularColor*specularity; color.rgb += specularColor*lightSpecularColor*specularity;
} }

Loading…
Cancel
Save