WORKING ReflectiveEyelightShader \o/
[MicroTrace.git] / ReflectiveEyeLightShader.cxx
index 2bd0db3..b681e47 100644 (file)
@@ -1,4 +1,6 @@
 #include "ReflectiveEyeLightShader.hxx"
+#include "Primitive.hxx"
+#include "Scene.hxx"
 
 ReflectiveEyeLightShader::ReflectiveEyeLightShader(Scene* scene,
                                                   float reflectivity,
@@ -21,5 +23,20 @@ ReflectiveEyeLightShader::ReflectiveEyeLightShader()
 Vec3f
 ReflectiveEyeLightShader::Shade(Ray& ray)
 {
-  return Vec3f();
+  Vec3f eyeColor = EyeLightShader::Shade(ray);
+  Vec3f reflColor;
+
+  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));
+
+    Ray sec(i, r + n * (2 * r.dot(n * -1)));
+    sec.setRecursionDepth(ray.recursionDepth() - 1);
+    reflColor = m_scene->RayTrace(sec);
+  }
+  return eyeColor + reflColor * m_reflectivity;
 }
This page took 0.025469 seconds and 4 git commands to generate.