not finished yet, but better than before
[MicroTrace.git] / ReflectiveEyeLightShader.cxx
index 2bd0db3..0adb174 100644 (file)
@@ -1,4 +1,6 @@
 #include "ReflectiveEyeLightShader.hxx"
+#include "Primitive.hxx"
+#include "Scene.hxx"
 
 ReflectiveEyeLightShader::ReflectiveEyeLightShader(Scene* scene,
                                                   float reflectivity,
@@ -21,5 +23,30 @@ ReflectiveEyeLightShader::ReflectiveEyeLightShader()
 Vec3f
 ReflectiveEyeLightShader::Shade(Ray& ray)
 {
-  return Vec3f();
+  Vec3f N = ray.hit()->GetNormal(ray);
+  
+  // diffuse color
+  Vec3f color = EyeLightShader::Shade(ray); 
+  // add reflection
+  if(ray.recursionDepth() < RecursionDepth)
+    {
+      // generate reflected ray
+      // ray origin = hitpoint
+      Vec3f origin = ray.origin() + ray.direction()*ray.t();
+      Vec3f dir = ray.direction()-N*2*N.dot(ray.direction());
+      dir.normalize();
+      
+      // spawn new ray
+      Ray reflection_ray(origin, dir, ray.recursionDepth()+1);
+      reflection_ray.setT(Infinity);
+      
+      // trace reflection ray
+      Vec3f reflected_color = m_scene->RayTrace(reflection_ray);
+      color += reflected_color * m_reflectivity;
+    }
+  
+  color.clamp();
+  
+  return color;
 }
This page took 0.02142 seconds and 4 git commands to generate.