Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1787 - trunk/Model/Backgrounds


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1787 - trunk/Model/Backgrounds
  • Date: Thu, 18 Oct 2007 21:35:06 -0600 (MDT)

Author: boulos
Date: Thu Oct 18 21:35:05 2007
New Revision: 1787

Modified:
   trunk/Model/Backgrounds/EnvMapBackground.cc
   trunk/Model/Backgrounds/EnvMapBackground.h
Log:
Model/Backgrounds/EnvMapBackground.cc
Model/Backgrounds/EnvMapBackground.h

 Implementing the Debevec Spherical Probe mapping.


Modified: trunk/Model/Backgrounds/EnvMapBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/EnvMapBackground.cc (original)
+++ trunk/Model/Backgrounds/EnvMapBackground.cc Thu Oct 18 21:35:05 2007
@@ -2,10 +2,12 @@
 #include <Interface/RayPacket.h>
 #include <Model/Backgrounds/EnvMapBackground.h>
 #include <SCIRun/Core/Math/Trig.h>
+#include <SCIRun/Core/Math/Expon.h>
 #include <SCIRun/Core/Exceptions/InternalError.h>
 
 using namespace Manta;
 using SCIRun::InternalError;
+using SCIRun::Sqrt;
 
 static Real OneOverPi=static_cast<Real>(1/M_PI);
 static Real OneOverTwoPi=static_cast<Real>(1/(2*M_PI));
@@ -39,7 +41,7 @@
     CylindricalEqualAreaMapping(context, rays);
     break;
   case DebevecSphere:
-    throw InternalError("Debevec Sphere probe format not finished", 
__FILE__, __LINE__);
+    DebevecMapping(context, rays);
     break;
   case OldBehavior:
     OldBehaviorMapping(context, rays);
@@ -151,5 +153,36 @@
 #endif
 
     rays.setTexCoords(i, texcoords);
+  }
+}
+
+void EnvMapBackground::DebevecMapping(const RenderContext& context, 
RayPacket& rays) const {
+  rays.normalizeDirections();
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    Vector local_dir(Dot(rays.getDirection(i), U),
+                     Dot(rays.getDirection(i), V),
+                     Dot(rays.getDirection(i), W));
+
+    // In Debevec's mapping, he considers Y to be up and -Z to be
+    // forward (a standard right handed graphics coordinate
+    // system). So to convert our standard UVW space into his, we need
+    // to rotate (in our heads) the UVW coordinate system by 90
+    // degrees around X. This makes X_deb=X_uvw, Y_deb=Z_uvw and,
+    // Z_deb=Y_uvw. Where _deb is the debevec mapping and uvw is the
+    // coordinate frame we are given.
+
+    // Given the above note, Debevec explains his mapping as:
+    //
+    // (X_deb*r, Y_deb*r) where r=(1/PI)*Acos(Z_deb)/sqrt(X_deb^2+Y_deb^2)
+    //
+    Real r = OneOverPi * Acos(local_dir[1])/Sqrt(local_dir[0]*local_dir[0] + 
local_dir[2]*local_dir[2]);
+    Real u = local_dir[0] * r;
+    Real v = local_dir[2] * r;
+    // This results in a mapping where u,v \in [-1, 1]^2 so we scale
+    // and shift
+    u = .5 * (1 + u);
+    v = .5 * (1 + v);
+
+    rays.setTexCoords(i, VectorT<Real, 2>(u, v));
   }
 }

Modified: trunk/Model/Backgrounds/EnvMapBackground.h
==============================================================================
--- trunk/Model/Backgrounds/EnvMapBackground.h  (original)
+++ trunk/Model/Backgrounds/EnvMapBackground.h  Thu Oct 18 21:35:05 2007
@@ -26,6 +26,7 @@
 
     void CylindricalEqualAreaMapping(const RenderContext& context, 
RayPacket& rays) const;
     void OldBehaviorMapping(const RenderContext& context, RayPacket& rays) 
const;
+    void DebevecMapping(const RenderContext& context, RayPacket& rays) const;
 
   private:
     Texture<Color>* image;




  • [Manta] r1787 - trunk/Model/Backgrounds, boulos, 10/18/2007

Archive powered by MHonArc 2.6.16.

Top of page