Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r453 - branches/itanium2/Model/Materials


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r453 - branches/itanium2/Model/Materials
  • Date: Thu, 28 Jul 2005 18:10:36 -0600 (MDT)

Author: boulos
Date: Thu Jul 28 18:10:36 2005
New Revision: 453

Modified:
   branches/itanium2/Model/Materials/Dielectric.cc
Log:
New dielectric logic for refracting, etc.


Modified: branches/itanium2/Model/Materials/Dielectric.cc
==============================================================================
--- branches/itanium2/Model/Materials/Dielectric.cc     (original)
+++ branches/itanium2/Model/Materials/Dielectric.cc     Thu Jul 28 18:10:36 
2005
@@ -57,6 +57,8 @@
 
 using namespace Manta;
 
+#define USE_PETES_CODE 0
+
 //  Note-- both v and n must be unit vectors!
 // v is the incident vector and is rewritten
 bool Refract(const Vector& n, double ni, double nt, Vector& v)
@@ -128,15 +130,71 @@
   Vector refr_dirs[RayPacket::MaxSize];
   float fresnel_coeffs[RayPacket::MaxSize]; // might be better to compute
   bool internally_reflected[RayPacket::MaxSize];
+#if (!USE_PETES_CODE)
+  bool apply_beers[RayPacket::MaxSize];
+#else
   bool from_outsides[RayPacket::MaxSize];
+#endif
 
   int num_internal = 0;
   int num_branch   = 0;
 
   for(int i=0;i<rays.getSize();i++)
   {
+#if (!USE_PETES_CODE)
+      RayPacket::Element& e = rays.get(i);
+      Vector N = e.normal;
+      double n_dot_v = Dot(N, e.ray.direction());
+      double eta_tmp;
+      double eta_tmp_inv;
+      bool was_incoming = ( n_dot_v < 0 );
+      if ( was_incoming )
+      {
+          eta_tmp = n_values[i]/nt_values[i];
+          eta_tmp_inv = 1.0 / eta_tmp;
+          n_dot_v = -n_dot_v;
+      }
+      else
+      {
+          N = -N;
+          eta_tmp = nt_values[i]/nt_values[i];
+          eta_tmp_inv = 1.0 / eta_tmp;
+      }
+      apply_beers[i] = !was_incoming;
+
+      double cosine = 1.0 + (n_dot_v*n_dot_v - 
1.0)*(eta_tmp_inv*eta_tmp_inv);
+      if ( cosine <= 0.0 )
+      {
+          // total internal reflection
+          Vector refl_dir = e.ray.direction() + 2.0*n_dot_v*N;
+          internally_reflected[i] = true;
+          refl_dirs[i] = refl_dir;
+          num_internal++;
+      }
+      else
+      {
+          cosine = (cosine > 0) ? sqrt(cosine) : 0;
+          double cos_min = ( cosine > n_dot_v ) ? n_dot_v : cosine;
+                    float k = 1 - cosine;
+          k*=k*k*k*k;
+
+          double r0 = (n_values[i] - nt_values[i]) / (n_values[i] + 
nt_values[i]);
+          r0 *= r0;
+          float R = r0*(1-k) + k;
+
+          Vector refr_dir = e.ray.direction()*eta_tmp_inv + 
(n_dot_v*eta_tmp_inv - cosine) * N;
+          Vector refl_dir = e.ray.direction() + 2.0*n_dot_v*N;
+
+          internally_reflected[i] = false;
+          num_branch++;
+          refl_dirs[i] = refl_dir;
+          refr_dirs[i] = refr_dir;
+          fresnel_coeffs[i] = R;
+      }
+#else
       RayPacket::Element& e = rays.get(i);
       double cosine = -Dot(e.normal, e.ray.direction());
+
       Vector refl_dir, refr_dir;
       bool from_outside = (cosine > 0);
       from_outsides[i] = from_outside;
@@ -191,6 +249,7 @@
           refr_dirs[i] = refr_dir;
           fresnel_coeffs[i] = R;
       }
+#endif
   }
 
   // okay we've got everything ready now
@@ -246,13 +305,6 @@
       {
           RayPacket::Element& r = internal_rays.get(internal_counter);
 
-          if ( !from_outsides[i] ) // the original ray rays.get(i) was 
leaving
-          {
-              // These two Beer's law calculations are equivalent, but
-              // one may be faster than the other
-              //(*r.color) *= 
sigma_a_values[i].Log().attenuate(e.hitInfo.minT());
-              (*r.color) *= sigma_a_values[i].Pow(e.hitInfo.minT());
-          }
           rays.setResult(i, *r.color);
           internal_counter++;
       }
@@ -261,16 +313,15 @@
           RayPacket::Element& refl = reflected_rays.get(branch_counter);
           RayPacket::Element& refr = refracted_rays.get(branch_counter);
 
-          if ( !from_outsides[i] )
-          {
-              // These two Beer's law calculations are equivalent, but
-              // one may be faster than the other
-              //(*refr.color) *= 
sigma_a_values[i].Log().attenuate(e.hitInfo.minT());
-              (*refr.color) *= sigma_a_values[i].Pow(e.hitInfo.minT());
-          }
           rays.setResult(i, (Color::white()*fresnel_coeffs[i])*(*refl.color) 
+
-                         
(Color::white()*(1.-fresnel_coeffs[i]))*(*refr.color) );
+                       (Color::white()*(1.-fresnel_coeffs[i]))*(*refr.color) 
);
+
           branch_counter++;
+      }
+
+      if (apply_beers[i])
+      {
+          *e.color *= sigma_a_values[i].Pow(e.hitInfo.minT());
       }
   }
 }




  • [MANTA] r453 - branches/itanium2/Model/Materials, boulos, 07/28/2005

Archive powered by MHonArc 2.6.16.

Top of page