Vec3f eyeColor = EyeLightShader::Shade(ray);
Vec3f reflColor;
- // shoot secondary rays from intersection
- Vec3f n = ray.hit()->GetNormal(ray);
- Ray sec(ray.origin() + ray.direction() * ray.t(), ray.direction() + n * 2);
- sec.setRecursionDepth(ray.recursionDepth() - 1);
+ if(ray.recursionDepth() > 0) {
+ m_scene->Intersect(ray);
+ // intersection, - Epsilon to avoid numerical problems and getting the
+ // reflection on the object's inside ;-)
+ Vec3f i = ray.origin() + ray.direction() * (ray.t() - Epsilon);
+ Vec3f r = ray.direction();
+ Vec3f n = (ray.hit()->GetNormal(ray));
- if(ray.recursionDepth() > 0 && m_scene->Intersect(sec)) {
- reflColor = Shade(sec);
+ Ray sec(i, r + n * (2 * r.dot(n * -1)));
+ sec.setRecursionDepth(ray.recursionDepth() - 1);
+ reflColor = m_scene->RayTrace(sec);
}
- return eyeColor + reflColor;
+ return eyeColor + reflColor * m_reflectivity;
}