Ray tempRay = ray;
// Surface normal is the difference between intersection and center point
- Intersect(tempRay);
- // intersection
- Vec3f i = tempRay.origin() + tempRay.direction() * tempRay.t();
- // normal
- Vec3f n = (i - m_center);
- n.normalize();
- return n;
+ if(Intersect(tempRay)) {
+ // intersection point
+ Vec3f i = tempRay.origin() + tempRay.direction() * (tempRay.t() - Epsilon);
+ // normal
+ Vec3f n = (i - m_center);
+ n.normalize();
+ return n;
+ } else {
+ // no intersection with ray, so no surface normal
+ return Vec3f(0,0,0);
+ }
}