+ int max_s = (lights[i]->IsArea()) ? n_area_rays : 1;
+ Vec3f color_l(0.0f,0.0f,0.0f);
+ for(int s = 0; s < max_s; ++s)
+ {
+
+ if(lights[i]->Illuminate(shadow_ray, intensity))
+ {
+ // check for occluders
+ if(m_scene->Occluded(shadow_ray))
+ {
+ continue;
+ }
+
+ float IdotN = shadow_ray.direction().dot(N);
+ if(IdotN > 0)
+ {
+ // diffuse term
+ color_l += m_diffuse_color * intensity * IdotN * m_kd;
+ }
+
+ // specular term
+ float IdotR = shadow_ray.direction().dot(R);
+ if(IdotR > 0)
+ {
+ color_l += m_specular_color * intensity * pow(IdotR,m_ke) * m_ks;
+ }
+ }
+ }
+ color_l /= static_cast<float>(max_s);
+ color += color_l;
+ }
+ color.clamp();
+
+ return color;