#include "Lighting.h" #include /* pow() */ Color Lighting::computePhong(const Material & material, const std::vector & lights, const Ray & viewRay, const Vector & surfacePoint, const Vector & surfaceNormal, const Color & ambientLight) { Color result = ambientLight; Vector viewDirection = -viewRay.getDirection(); double shininess = material.getShininess(); const Color & diffuseColor = material.getDiffuseColor(); const Color & specularColor = material.getSpecularColor(); for (std::vector::const_iterator it = lights.begin(); it != lights.end(); it++) { Vector directionToLight = (*it)->getPosition() - surfacePoint; directionToLight.normalize(); Vector reflectedLightDirection = directionToLight.reflect(surfaceNormal); /* calculate the diffuse term */ result += diffuseColor * (*it)->getDiffuseColor() * (directionToLight % surfaceNormal); /* calculate the specular term */ result += specularColor * (*it)->getSpecularColor() * pow(reflectedLightDirection % viewDirection, shininess); } return result; }