X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/13c3b8d1e2ecf7f1dbd02f9d4bfeb813b36fd40a..430ddbc0e443b60b6d0c7893a96e045411368dbf:/ReflectiveEyeLightShader.cxx?ds=sidebyside diff --git a/ReflectiveEyeLightShader.cxx b/ReflectiveEyeLightShader.cxx index 87369bd..b681e47 100644 --- a/ReflectiveEyeLightShader.cxx +++ b/ReflectiveEyeLightShader.cxx @@ -26,23 +26,17 @@ ReflectiveEyeLightShader::Shade(Ray& ray) Vec3f eyeColor = EyeLightShader::Shade(ray); Vec3f reflColor; - // get normal and turn towards ray if angle > 90° - Vec3f n = ray.hit()->GetNormal(ray); - float cos_theta = n.dot(ray.direction()); - // we just need the sign, no value - if( cos_theta > 0 ) { - std::cout << "cos_theta="< 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(sec.recursionDepth() + 1 > 0) { + Ray sec(i, r + n * (2 * r.dot(n * -1))); + sec.setRecursionDepth(ray.recursionDepth() - 1); reflColor = m_scene->RayTrace(sec); - //reflColor = Shade(sec); } - return eyeColor + (reflColor * m_reflectivity); + return eyeColor + reflColor * m_reflectivity; }