+ // surface normal at hit point of object
+ Vec3f normal = ray.hit()->GetNormal(ray);
+ // turn to fron if angle < 90°
+ if(normal.dot(ray.direction()) < 0) {
+ normal = normal * -1;
+ }
+ // direction of reflection
+ Vec3f refl_dir = ray.direction() - normal * 2 * (normal % ray.direction());
+ refl_dir.normalize();
+
+ // ambient color term - radiance is 1 since we have point light
+ Vec3f amb_color = m_ambient_color * m_ka * 1.0f;
+
+ Vec3f intensity, light_dir;
+
+ // diffuse and specular color for each light source
+ Vec3f diff_sum;
+ Vec3f spec_sum;
+ for(std::vector<Light*>::iterator it = m_scene->m_lights.begin();
+ it != m_scene->m_lights.end(); it++) {
+ Ray light_ray;
+ (*it)->Illuminate(light_ray, intensity);
+ diff_sum += intensity * light_ray.direction().dot(normal);
+ spec_sum += intensity * light_ray.direction().dot(refl_dir);
+ }
+ Vec3f diff_color = m_diffuse_color * m_kd * diff_sum;
+ Vec3f spec_color = m_specular_color * m_ks * spec_sum;
+
+ return amb_color + diff_color + spec_sum;