still broken ReflectiveEyeLightShader, saving it for later
authorRoland Hieber <rhieber@gaffel.ibr.cs.tu-bs.de>
Wed, 20 Jan 2010 18:45:52 +0000 (19:45 +0100)
committerRoland Hieber <rhieber@gaffel.ibr.cs.tu-bs.de>
Wed, 20 Jan 2010 18:45:52 +0000 (19:45 +0100)
Image.cxx
MicroTrace.cxx
Ray.cxx
ReflectiveEyeLightShader.cxx
Sphere.cxx

index b45cac9..899ac6f 100644 (file)
--- a/Image.cxx
+++ b/Image.cxx
@@ -39,31 +39,39 @@ Image::operator()(int x, int y)
 {
   assert(x >= 0 && x < m_resX);
   assert(y >= 0 && y < m_resY);
-        
-  return m_pixel[y*m_resX+x];   
+
+  return m_pixel[y*m_resX+x];
 }
 
 void Image::WritePPM(const std::string& fileName)
 {
   std::cerr << "(Image): Writing to file " << fileName << std::endl;
   std::ofstream file(fileName.c_str());
-  
+
   if(!file.is_open())
     {
       std::cerr << "(Image): Could not open file " << fileName << std::endl;
       return;
     }
-  
+
   file << "P3" << std::endl;
   file << m_resX << " " << m_resY << " " << 255 << std::endl;
-  for (int y=m_resY-1;y>=0;y--) 
+  for (int y=m_resY-1;y>=0;y--)
     {
       for (int x=0;x<m_resX;x++)
        {
-         file 
-           << (int)(255.99999999 * (*this)(x,y)[0]) << " "
-           << (int)(255.99999999 * (*this)(x,y)[1]) << " "
-           << (int)(255.99999999 * (*this)(x,y)[2]) << " "
+    Vec3f cur = (*this)(x,y);
+    if(cur[0] < 0) cur[0] = 0;
+    if(cur[1] < 0) cur[1] = 0;
+    if(cur[2] < 0) cur[2] = 0;
+    if(cur[0] > 255) cur[0] = 255;
+    if(cur[1] > 255) cur[1] = 255;
+    if(cur[2] > 255) cur[2] = 255;
+
+         file
+           << (int)(255.99999999 * cur[0]) << " "
+           << (int)(255.99999999 * cur[1]) << " "
+           << (int)(255.99999999 * cur[2]) << " "
            << "\t";
        }
       file << std::endl;
index 252ec18..3a27182 100644 (file)
@@ -163,7 +163,7 @@ void RenderFrameReflectiveEyeLight(const std::string& fileName)
     {
       for (int x = 0; x < scene.camera()->resX(); x++)
       {
-        /* Initialize your ray here */
+        /* Initialize your ray here */ //int x = 319, y = 59;
         // shoot four rays for antialiasing
         scene.camera()->InitRay(x+0.5,y+0.5, ray); // initialize ray
         Vec3f col1 = scene.RayTrace(ray);
@@ -174,7 +174,7 @@ void RenderFrameReflectiveEyeLight(const std::string& fileName)
         scene.camera()->InitRay(x-0.5,y-0.5, ray); // initialize ray
         Vec3f col4 = scene.RayTrace(ray);
 
-        img(x,y) = (col1 + col2 + col3 + col4) / 4.0; // store pixel color
+        img(x,y) = (col1 /*+ col2 + col3 + col4) / 4.0*/ ); // store pixel color
         //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
       }
     }
@@ -188,7 +188,7 @@ void RenderFrameReflectiveEyeLight(const std::string& fileName)
 
 int main(int, char**)
 {
-  RenderFrameFlat("flatshaded.ppm");
-  RenderFrameEyeLight("eyelight.ppm");
+  //RenderFrameFlat("flatshaded.ppm");
+  //RenderFrameEyeLight("eyelight.ppm");
   RenderFrameReflectiveEyeLight("reflective.ppm");
 }
diff --git a/Ray.cxx b/Ray.cxx
index a3c76cb..584db26 100644 (file)
--- a/Ray.cxx
+++ b/Ray.cxx
@@ -2,11 +2,13 @@
 
 #include "Ray.hxx"
 
+#define MAX_RECURSION_DEPTH 5
+
 Ray::Ray()
   : m_org(Vec3f()),
     m_dir(Vec3f()),
     m_hit(0),
-    m_level(10)
+    m_level(MAX_RECURSION_DEPTH)
 {
   m_t = std::numeric_limits<float>::max();
 }
@@ -16,7 +18,7 @@ Ray::Ray(const Vec3f& org,
   : m_org(org),
     m_dir(dir),
     m_hit(0),
-    m_level(10)
+    m_level(MAX_RECURSION_DEPTH)
 {
   m_t = std::numeric_limits<float>::max();
 }
index e7fa2ac..87369bd 100644 (file)
@@ -26,13 +26,23 @@ ReflectiveEyeLightShader::Shade(Ray& ray)
   Vec3f eyeColor = EyeLightShader::Shade(ray);
   Vec3f reflColor;
 
-  // shoot secondary rays from intersection
+  // get normal and turn towards ray if angle > 90°
   Vec3f n = ray.hit()->GetNormal(ray);
-  Ray sec(ray.origin() + ray.direction() * ray.t(), ray.direction() + n * 2);
+  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(sec)) {
-    reflColor = Shade(sec);
+  if(sec.recursionDepth() + 1 > 0) {
+    reflColor = m_scene->RayTrace(sec);
+    //reflColor = Shade(sec);
   }
-  return eyeColor + reflColor;
+  return eyeColor + (reflColor * m_reflectivity);
 }
index 5706cc3..77d4320 100644 (file)
@@ -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);
+  }
 }
This page took 0.032414 seconds and 4 git commands to generate.