Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1462 - in trunk: Engine/Shadows Interface Model/Lights Model/Primitives


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1462 - in trunk: Engine/Shadows Interface Model/Lights Model/Primitives
  • Date: Tue, 10 Jul 2007 18:59:51 -0600 (MDT)

Author: boulos
Date: Tue Jul 10 18:59:50 2007
New Revision: 1462

Added:
   trunk/Model/Lights/AreaLight.cc
   trunk/Model/Lights/AreaLight.h
Modified:
   trunk/Engine/Shadows/HardShadows.cc
   trunk/Interface/Primitive.cc
   trunk/Interface/Primitive.h
   trunk/Model/Lights/CMakeLists.txt
   trunk/Model/Primitives/Parallelogram.cc
   trunk/Model/Primitives/Parallelogram.h
Log:
Adding an AreaLight class that wraps around a
Primitive.

Adding area sampling for Primitives to do direct
lighting from area lights.

Leaving note in HardShadows about possible bug
with resetting hitMatl.


NOTE: The current code doesn't correctly handle
double counting of emitted light yet, so it's a
work in progress.



Modified: trunk/Engine/Shadows/HardShadows.cc
==============================================================================
--- trunk/Engine/Shadows/HardShadows.cc (original)
+++ trunk/Engine/Shadows/HardShadows.cc Tue Jul 10 18:59:50 2007
@@ -19,6 +19,10 @@
 using namespace Manta;
 using std::cerr;
 
+#ifdef MANTA_SSE
+#undef MANTA_SSE
+#endif
+
 ShadowAlgorithm* HardShadows::create(const vector<string>& args)
 {
   return new HardShadows(args);
@@ -139,6 +143,14 @@
 
           // The materials have already been set by the code above.
           // Don't touch minT.
+          /* TODO(boulos): I think this is probably required to actually 
reset the hitMatl properly
+
+            #if __x86_64
+            #error "too lazy"
+            #else
+            _mm_store_si128(&shadowData->hitMatl[i], _mm_setzero_si128());
+            #endif
+          */
           last = i+3;
           if (first < 0)
             first = i;

Modified: trunk/Interface/Primitive.cc
==============================================================================
--- trunk/Interface/Primitive.cc        (original)
+++ trunk/Interface/Primitive.cc        Tue Jul 10 18:59:50 2007
@@ -1,5 +1,7 @@
 
 #include <Interface/Primitive.h>
+#include <Core/Geometry/Vector.h>
+#include <Core/Exceptions/InternalError.h>
 
 using namespace Manta;
 
@@ -9,4 +11,12 @@
 
 Primitive::~Primitive()
 {
+}
+
+void Primitive::getRandomPoint(Vector& point,
+                               Vector& normal,
+                               Real& pdf,
+                               const RenderContext& context) const {
+  throw SCIRun::InternalError("Unimplemented getRandomPoint for Primitive",
+                              __FILE__, __LINE__);
 }

Modified: trunk/Interface/Primitive.h
==============================================================================
--- trunk/Interface/Primitive.h (original)
+++ trunk/Interface/Primitive.h Tue Jul 10 18:59:50 2007
@@ -3,10 +3,11 @@
 #define Manta_Interface_Primitive_h
 
 #include <Interface/Object.h>
+#include <MantaTypes.h>
 
 namespace Manta {
   class TexCoordMapper;
-
+  class Vector;
   class Primitive : public Object {
   public:
     Primitive();
@@ -14,12 +15,17 @@
 
     virtual void preprocess(const PreprocessContext& context) = 0;
     virtual void intersect(const RenderContext& context,
-                          RayPacket& rays) const = 0;
+                           RayPacket& rays) const = 0;
     virtual void computeNormal(const RenderContext& context,
-                              RayPacket& rays) const = 0;
+                               RayPacket& rays) const = 0;
     virtual void setTexCoordMapper(const TexCoordMapper* new_tex) = 0;
+
+    virtual void getRandomPoint(Vector& point,
+                                Vector& normal,
+                                Real& pdf,
+                                const RenderContext& context) const;
   private:
-         Primitive(const Primitive&);
+    Primitive(const Primitive&);
     Primitive& operator=(const Primitive&);
   };
 }

Added: trunk/Model/Lights/AreaLight.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Lights/AreaLight.cc     Tue Jul 10 18:59:50 2007
@@ -0,0 +1,36 @@
+
+#include <Model/Lights/AreaLight.h>
+#include <MantaSSE.h>
+#include <Interface/Primitive.h>
+
+using namespace Manta;
+
+AreaLight::AreaLight(const Primitive* primitive, const Color& color)
+  : primitive(primitive), color(color) {
+}
+
+AreaLight::~AreaLight() {
+}
+
+void AreaLight::preprocess(const PreprocessContext&) {
+}
+
+void AreaLight::computeLight(RayPacket& destRays, const RenderContext 
&context,
+                             RayPacket& sourceRays) const
+{
+  sourceRays.computeHitPositions();
+  for(int i = sourceRays.begin(); i < sourceRays.end(); i++) {
+    // Generate a point on the light
+    Vector position;
+    Vector normal;
+    Real pdf;
+    primitive->getRandomPoint(position, normal, pdf, context);
+    Vector dir = position - sourceRays.getHitPosition(i);
+    Real len = dir.normalize();
+    Real cosine = SCIRun::Max(-Dot(dir, normal), Real(0));
+    Real solid_pdf = pdf * (len * len / cosine);
+    destRays.setDirection(i, dir);
+    destRays.setColor(i, color / solid_pdf);
+    destRays.overrideMinT(i, len);
+  }
+}

Added: trunk/Model/Lights/AreaLight.h
==============================================================================
--- (empty file)
+++ trunk/Model/Lights/AreaLight.h      Tue Jul 10 18:59:50 2007
@@ -0,0 +1,30 @@
+
+#ifndef Manta_Model_AreaLight_h
+#define Manta_Model_AreaLight_h
+
+#include <Interface/Light.h>
+#include <Core/Geometry/Vector.h>
+#include <Core/Color/Color.h>
+
+namespace Manta {
+  class Primitive;
+  class AreaLight : public Light {
+  public:
+    AreaLight(const Primitive* primitive, const Color& color);
+    virtual ~AreaLight();
+
+    virtual void preprocess(const PreprocessContext&);
+
+    virtual void computeLight(RayPacket& rays, const RenderContext &context,
+                              RayPacket& source) const;
+
+    Color getColor() const { return color; }
+    void setColor(Color new_c) { color = new_c; }
+
+  private:
+    const Primitive* primitive;
+    Color color;
+  };
+}
+
+#endif

Modified: trunk/Model/Lights/CMakeLists.txt
==============================================================================
--- trunk/Model/Lights/CMakeLists.txt   (original)
+++ trunk/Model/Lights/CMakeLists.txt   Tue Jul 10 18:59:50 2007
@@ -1,5 +1,7 @@
 
 SET (Manta_Lights_SRCS
+     Lights/AreaLight.h
+     Lights/AreaLight.cc
      Lights/HeadLight.h
      Lights/HeadLight.cc
      Lights/PointLight.h

Modified: trunk/Model/Primitives/Parallelogram.cc
==============================================================================
--- trunk/Model/Primitives/Parallelogram.cc     (original)
+++ trunk/Model/Primitives/Parallelogram.cc     Tue Jul 10 18:59:50 2007
@@ -5,6 +5,8 @@
 #include <Core/Math/MiscMath.h>
 #include <MantaSSE.h>
 #include <Core/Math/SSEDefs.h>
+#include <Interface/Context.h>
+#include <Interface/RandomNumberGenerator.h>
 
 using namespace Manta;
 using SCIRun::Abs;
@@ -18,10 +20,11 @@
 
 Parallelogram::Parallelogram(Material* material, const Vector& anchor,
                              const Vector& in_v1, const Vector& in_v2)
-  : PrimitiveCommon(material, this), anchor(anchor), v1(in_v1), v2(in_v2)
+  : PrimitiveCommon(material, this), anchor(anchor), v1(in_v1), v2(in_v2),
+    v1_unscaled(in_v1), v2_unscaled(in_v2)
 {
   normal = Cross(v1, v2);
-  normal.normalize();
+  inv_area = Real(1)/normal.normalize();
   d = Dot(normal, anchor);
   v1 *= 1./v1.length2();
   v2 *= 1./v2.length2();
@@ -33,7 +36,7 @@
 
 void Parallelogram::computeBounds(const PreprocessContext&, BBox& bbox) const
 {
-  // Extend the box by the four corners of the parallelogram. 
+  // Extend the box by the four corners of the parallelogram.
   // v1 and v2 are stored with an inverse length to avoid extra
   // computation in the intersect routine, but we must divide that
   // out here.
@@ -170,7 +173,7 @@
         // Real a2 = Dot(v2, vi)+o2;
         // if (a2 < 0 || a2 > 1)
         //   continue;
-        
+
         __m128 a2 = _mm_add_ps(_mm_add_ps(_mm_add_ps(_mm_mul_ps(vix, 
_mm_set1_ps(v2[0])), _mm_mul_ps(viy, _mm_set1_ps(v2[1]))), _mm_mul_ps(viz, 
_mm_set1_ps(v2[2]))), vec_o2);
         hit = _mm_and_ps(hit, _mm_and_ps(_mm_cmpge_ps(a2, zero), 
_mm_cmple_ps(a2, one)));
         if(_mm_movemask_ps(hit) == 0)
@@ -184,7 +187,7 @@
         MANTA_ALIGN(16) float ra2[4];
         _mm_store_ps(ra1, a1);
         _mm_store_ps(ra2, a2);
-          
+
         if(_mm_movemask_ps(hit) == 15){
           rays.scratchpad<Vector>(i+0) = Vector(ra1[0], ra2[0], 0);
           rays.scratchpad<Vector>(i+1) = Vector(ra1[1], ra2[1], 0);
@@ -360,7 +363,7 @@
         __m128 dy = _mm_load_ps(&data->direction[1][i]);
         __m128 dz = _mm_load_ps(&data->direction[2][i]);
         __m128 dt = _mm_add_ps(_mm_add_ps(_mm_mul_ps(dx, normalx), 
_mm_mul_ps(dy, normaly)), _mm_mul_ps(dz, normalz));
-        
+
         //if(Abs(dt) < (Real)1.e-6)
         //continue;
         __m128 ox = _mm_load_ps(&data->origin[0][i]);
@@ -368,7 +371,7 @@
         __m128 oz = _mm_load_ps(&data->origin[2][i]);
         __m128 dot = _mm_add_ps(_mm_add_ps(_mm_mul_ps(ox, normalx), 
_mm_mul_ps(oy, normaly)), _mm_mul_ps(oz, normalz));
         __m128 t = _mm_div_ps(_mm_sub_ps(_mm_set1_ps(d), dot), dt);
-        
+
         __m128 hit = _mm_and_ps(_mm_cmplt_ps(t, _mm_load_ps(&data->minT[i])),
                                 _mm_cmpgt_ps(t, _mm_set1_ps(T_EPSILON)));
         if(_mm_movemask_ps(hit) == 0)
@@ -402,7 +405,7 @@
         MANTA_ALIGN(16) float ra2[4];
         _mm_store_ps(ra1, a1);
         _mm_store_ps(ra2, a2);
-          
+
         if(_mm_movemask_ps(hit) == 15){
           rays.scratchpad<Vector>(i+0) = Vector(ra1[0], ra2[0], 0);
           rays.scratchpad<Vector>(i+1) = Vector(ra1[1], ra2[1], 0);
@@ -454,7 +457,7 @@
         Real a2 = Dot(v2, vi);
         if (a2 < 0 || a2 > 1)
           continue;
-        
+
         if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
 #if USE_SCRATCHPAD == 1
           rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
@@ -541,4 +544,14 @@
 #endif
 #endif
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
+}
+
+void Parallelogram::getRandomPoint(Vector& point,
+                                   Vector& normal,
+                                   Real& pdf,
+                                   const RenderContext& context) const {
+  pdf = inv_area;
+  point = (anchor + context.rng->next<Real>() * v1_unscaled +
+           context.rng->next<Real>() * v2_unscaled);
+  normal = this->normal;
 }

Modified: trunk/Model/Primitives/Parallelogram.h
==============================================================================
--- trunk/Model/Primitives/Parallelogram.h      (original)
+++ trunk/Model/Primitives/Parallelogram.h      Tue Jul 10 18:59:50 2007
@@ -18,14 +18,22 @@
     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 getRandomPoint(Vector& point,
+                                Vector& normal,
+                                Real& pdf,
+                                const RenderContext& context) const;
   private:
     Vector anchor;
     Vector v1, v2;
+    Vector v1_unscaled;
+    Vector v2_unscaled;
     Vector normal;
     Real d;
+    Real inv_area;
   };
 }
 




  • [MANTA] r1462 - in trunk: Engine/Shadows Interface Model/Lights Model/Primitives, boulos, 07/10/2007

Archive powered by MHonArc 2.6.16.

Top of page