Reflections

Total Intensity due to positional lights :         I = IL_0 + IL_1 + IL_2 + ...+ IL_numlilghts-1 + IG   

      where

              IL_i = Idiff + Ispec + Iamb   + Irefl       for Lighti

              and IG = intensity due to global ambient light

              and Irefl  = shininess * shader(reflected ray)

Color Scene::shader(Ray &r)

if (r.recurseLevel == maxRecursionLevel)
     return total_color; //
don't go any further
if (
hit object is shiny enough)   //add any reflected light
{
     //
calculate direction of reflected ray, refl:
          set
dm = -2.0*(r.dir).dot(m)
          set
refl.dir.x = r.dir.x + dm * m.x
          set
refl.dir.y = r.dir.y + dm * m.y
          set
refl.dir.z = r.dir.z + dm * m.z

          //set start position of reflected ray to actual hit point, P:
          
refl.setStart(P)

           //set recurse level for this ray to be 1 more than r's level:
          
refl.recurse_level = r.recurse_level + 1

          //calculate color returned by reflected ray, via recursion:
          
refcolor = shader(refl) * this object's shininess
          
          //add to current color:
          total_color.add(refcolor)
}