WORKING ReflectiveEyelightShader \o/
authorRoland Hieber <rohieb@rohieb.name>
Thu, 21 Jan 2010 01:14:15 +0000 (02:14 +0100)
committerRoland Hieber <rohieb@rohieb.name>
Thu, 21 Jan 2010 01:14:15 +0000 (02:14 +0100)
Ray.cxx
ReflectiveEyeLightShader.cxx

diff --git a/Ray.cxx b/Ray.cxx
index 584db26..e0a1ab5 100644 (file)
--- a/Ray.cxx
+++ b/Ray.cxx
@@ -2,13 +2,13 @@
 
 #include "Ray.hxx"
 
-#define MAX_RECURSION_DEPTH 5
+#define MAX_RECURSION_DEPTH 10
 
 Ray::Ray()
   : m_org(Vec3f()),
     m_dir(Vec3f()),
-    m_hit(0),
-    m_level(MAX_RECURSION_DEPTH)
+    m_level(MAX_RECURSION_DEPTH),
+    m_hit(0)
 {
   m_t = std::numeric_limits<float>::max();
 }
@@ -17,8 +17,8 @@ Ray::Ray(const Vec3f& org,
         const Vec3f& dir)
   : m_org(org),
     m_dir(dir),
-    m_hit(0),
-    m_level(MAX_RECURSION_DEPTH)
+    m_level(MAX_RECURSION_DEPTH),
+    m_hit(0)
 {
   m_t = std::numeric_limits<float>::max();
 }
index 87369bd..b681e47 100644 (file)
@@ -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="<<cos_theta <<", flipping normal" <<std::endl;
-    n = n * -1;
-  }
-
-  // shoot secondary rays from intersection
-  Ray sec(ray.origin() + ray.direction() * (ray.t() - Epsilon),
-    ray.direction() + n * 2);
-  sec.setRecursionDepth(ray.recursionDepth() - 1);
+  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));
 
-  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;
 }
This page took 0.026244 seconds and 4 git commands to generate.