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
Irefl = shininess * shader(reflected ray) |
maxRecursionLevel to both the scene
file and as a data variable to class Scene shininess to both the scene file (as a primitive attribute)
and as a data variable to class Primitive recurse_level as a data variable to class Ray,
initially set to 1.Color Scene::shader(Ray &r)
- declare local variable for reflected ray:
Ray refl- After calculating
total_color = Idiff + Ispec + Iamb
if (r.recurseLevel == maxRecursionLevel)don't go any further
return total_color; //hit object is shiny enough)
if (//add any reflected light
{calculate direction of reflected ray, refl:
//
setdm = -2.0*(r.dir).dot(m)
setrefl.dir.x = r.dir.x + dm * m.x
setrefl.dir.y = r.dir.y + dm * m.y
setrefl.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)
}