X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/7a2c1f3713be127f6e4361fd8f426e78e8965bab..13c3b8d1e2ecf7f1dbd02f9d4bfeb813b36fd40a:/Sphere.cxx diff --git a/Sphere.cxx b/Sphere.cxx index 5706cc3..77d4320 100644 --- a/Sphere.cxx +++ b/Sphere.cxx @@ -44,11 +44,15 @@ Sphere::GetNormal(Ray& ray) 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); + } }