Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2264 - trunk/Model/Primitives


Chronological Thread 
  • From: "Thiago Ize" <thiago@sci.utah.edu>
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2264 - trunk/Model/Primitives
  • Date: Wed, 14 May 2008 19:00:55 -0600 (MDT)

Author: thiago
Date: Wed May 14 19:00:54 2008
New Revision: 2264

Modified:
   trunk/Model/Primitives/Sphere.cc
   trunk/Model/Primitives/Sphere.h
Log:
Implemented getRandomPoints for the Sphere. Now Spheres can
be used as AreaLights.

Modified: trunk/Model/Primitives/Sphere.cc
==============================================================================
--- trunk/Model/Primitives/Sphere.cc    (original)
+++ trunk/Model/Primitives/Sphere.cc    Wed May 14 19:00:54 2008
@@ -3,6 +3,7 @@
 #include <Core/Geometry/BBox.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/Trig.h>
+#include <Core/Math/TrigSSE.h>
 #include <Core/Math/Expon.h>
 #include <Core/Math/SSEDefs.h>
 #include <Core/Persistent/ArchiveElement.h>
@@ -10,6 +11,8 @@
 #include <Interface/RayPacket.h>
 #include <Interface/InterfaceRTTI.h>
 #include <MantaSSE.h>
+#include <Interface/Context.h>
+#include <Interface/SampleGenerator.h>
 
 using namespace Manta;
 using namespace std;
@@ -369,6 +372,65 @@
     rays.setTexCoords(i, Vector(x, y, 0));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
+}
+
+void Sphere::getRandomPoints(Packet<Vector>& points,
+                             Packet<Vector>& normals,
+                             Packet<Real>& pdfs,
+                             const RenderContext& context,
+                             RayPacket& rays) const {
+  // TODO(boulos): Change this code to only do work for active rays
+  Packet<Real> r1;
+  Packet<Real> r2;
+  context.sample_generator->nextSeeds(context, r1, rays);
+  context.sample_generator->nextSeeds(context, r2, rays);
+
+  const Real inv_area = 1 / (4*M_PI*radius*radius);
+
+#ifdef MANTA_SSE
+  for (int i = 0; i < Packet<Vector>::MaxSize; i+=4) {
+    sse_t z = sub4(_mm_one, mul4(_mm_two, load44(&r1.data[i])));
+    const sse_t r = mul4(set4(radius), sqrt4(sub4(_mm_one, mul4(z, z))));
+    z = add4(set4(center[2]), mul4(set4(radius), z));
+    const sse_t phi = mul4(set4(2*M_PI), load44(&r2.data[i]));
+    sse_t cos_phi, sin_phi;
+    sincos4(phi, &cos_phi, &sin_phi);
+    const sse_t x = add4(set4(center[0]), mul4(r, cos_phi));
+    const sse_t y = add4(set4(center[1]), mul4(r, sin_phi));
+
+    store44(&points.vectordata[0][i], x);
+    store44(&points.vectordata[1][i], y);
+    store44(&points.vectordata[2][i], z);
+                  
+    store44(&normals.vectordata[0][i],
+           mul4(sub4(load44(&points.vectordata[0][i]), set4(center[0])),
+                set4(inv_radius)));
+    store44(&normals.vectordata[1][i],
+           mul4(sub4(load44(&points.vectordata[1][i]), set4(center[1])),
+                set4(inv_radius)));
+    store44(&normals.vectordata[2][i],
+           mul4(sub4(load44(&points.vectordata[2][i]), set4(center[2])),
+                set4(inv_radius)));
+
+    store44(&pdfs.data[i], set4(inv_area));
+  }
+#else
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    Real z = 1 - 2*r1.get(i);
+    Real r = radius*Sqrt(1 - z*z);
+    z = center[2] + radius*z;
+    Real phi = 2 * M_PI * r2.get(i);
+    Real x = center[0] + r*Cos(phi);
+    Real y = center[1] + r*Sin(phi);
+    points.set(i, Vector(x, y, z));
+  }
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    normals.set(i, (points.get(i) - center) * inv_radius);
+  }
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    pdfs.set(i, inv_area);
+  }
+#endif
 }
 
 Interpolable::InterpErr Sphere::serialInterpolate(const 
std::vector<keyframe_t> &keyframes)

Modified: trunk/Model/Primitives/Sphere.h
==============================================================================
--- trunk/Model/Primitives/Sphere.h     (original)
+++ trunk/Model/Primitives/Sphere.h     Wed May 14 19:00:54 2008
@@ -25,9 +25,15 @@
     virtual void intersect(const RenderContext& context, RayPacket& rays) 
const;
     virtual void computeNormal(const RenderContext& context, RayPacket& 
rays) const;
     virtual void computeTexCoords2(const RenderContext& context,
-                                  RayPacket& rays) const;
+                                   RayPacket& rays) const;
     virtual void computeTexCoords3(const RenderContext& context,
-                                  RayPacket& rays) const;
+                                   RayPacket& rays) const;
+
+    virtual void getRandomPoints(Packet<Vector>& points,
+                                 Packet<Vector>& normals,
+                                 Packet<Real>& pdfs,
+                                 const RenderContext& context,
+                                 RayPacket& rays) const;
 
     Vector getCenter(void) const
     {


  • [Manta] r2264 - trunk/Model/Primitives, Thiago Ize, 05/14/2008

Archive powered by MHonArc 2.6.16.

Top of page