//----------------------------------------------------------------------------
// William Baxter III's Ray Tracer
//
//     Project for Comp 238, Raster Graphics
//     University of North Carolina at Chapel Hill
//     
// $Id:$
//----------------------------------------------------------------------------

#include "wb3CastingShader.hpp"
#include "wb3Light.hpp"

//----------------------------------------------------------------------------

wb3CastingShader::wb3CastingShader()
{
}
wb3CastingShader::~wb3CastingShader()
{
}


void wb3CastingShader::Shade(const wb3Scene* scene,
                             const wb3Artifact* from,
                             const wb3Artifact* hitObj,
                             const Ray3f& r, const Vec3f &hitPt, 
                             Vec3f& color,
                             Vec3f& attenuation,
                             int hits) const
{
  // Get normal at point of intersection
  Vec3f N;
  hitObj->GetNormal(r, hitPt, N);

  // Perturb intersection in dirn of normal to prevent
  // hitting again on the way out due to numerical imprecision.
  const float eps = 1e-6f;
  Vec3f isect( hitPt + eps * N);

  // Get lights
  const wb3LightArray& lights = scene->GetLights();

  // Iterate over lights in scene
  for (unsigned int i=0; i<lights.GetSize(); i++)
  {
    const wb3Light *light = lights.GetAt(i);

    light->Contribute(scene, hitObj, r, isect, N, color);
  }
}


