Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r367 - in branches/itanium2: Engine/Shadows Interface Model/Cameras Model/Groups Model/Lights Model/Materials scenes


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r367 - in branches/itanium2: Engine/Shadows Interface Model/Cameras Model/Groups Model/Lights Model/Materials scenes
  • Date: Tue, 7 Jun 2005 00:11:53 -0600 (MDT)

Author: abe
Date: Tue Jun  7 00:11:39 2005
New Revision: 367

Modified:
   branches/itanium2/Engine/Shadows/BeamShadows.cc
   branches/itanium2/Engine/Shadows/CMakeLists.txt
   branches/itanium2/Engine/Shadows/HardShadows.cc
   branches/itanium2/Engine/Shadows/NoShadows.cc
   branches/itanium2/Interface/Camera.h
   branches/itanium2/Interface/Light.h
   branches/itanium2/Interface/LightSet.cc
   branches/itanium2/Interface/LightSet.h
   branches/itanium2/Interface/Parameters.h
   branches/itanium2/Model/Cameras/CMakeLists.txt
   branches/itanium2/Model/Cameras/EnvironmentCamera.h
   branches/itanium2/Model/Cameras/OrthogonalCamera.h
   branches/itanium2/Model/Cameras/PinholeCamera.h
   branches/itanium2/Model/Groups/kdtree.cc
   branches/itanium2/Model/Lights/CMakeLists.txt
   branches/itanium2/Model/Lights/PointLight.cc
   branches/itanium2/Model/Lights/PointLight.h
   branches/itanium2/Model/Materials/Lambertian.cc
   branches/itanium2/scenes/boeing777.cc
Log:
Big change: Added computeLight method to Light. Added HeadLight class. 
Parallelized kdtree load, is now around 3 minutes, down from 10. Only 
triangle parse is parallel, io takes a while still.

Modified: branches/itanium2/Engine/Shadows/BeamShadows.cc
==============================================================================
--- branches/itanium2/Engine/Shadows/BeamShadows.cc     (original)
+++ branches/itanium2/Engine/Shadows/BeamShadows.cc     Tue Jun  7 00:11:39 
2005
@@ -42,6 +42,7 @@
                               const LightSet* lights, RayPacket& rays,
                               int start, RayPacket& shadowRays)
 {
+#if 0
   int nlights = lights->numLights();
   rays.computeHitPositions();
 
@@ -98,6 +99,8 @@
     shadowRays.setFlag(RayPacket::ConstantOrigin);
   context.scene->getObject()->intersect(context, shadowRays);
   return end;
+#endif
+       return 0;
 }
 
 string BeamShadows::getName() const {

Modified: branches/itanium2/Engine/Shadows/CMakeLists.txt
==============================================================================
--- branches/itanium2/Engine/Shadows/CMakeLists.txt     (original)
+++ branches/itanium2/Engine/Shadows/CMakeLists.txt     Tue Jun  7 00:11:39 
2005
@@ -1,6 +1,9 @@
 
 SET (Manta_Shadows_SRCS
+     Shadows/NoShadows.h
      Shadows/NoShadows.cc
+     Shadows/HardShadows.h
      Shadows/HardShadows.cc
+     Shadows/BeamShadows.h
      Shadows/BeamShadows.cc
      )

Modified: branches/itanium2/Engine/Shadows/HardShadows.cc
==============================================================================
--- branches/itanium2/Engine/Shadows/HardShadows.cc     (original)
+++ branches/itanium2/Engine/Shadows/HardShadows.cc     Tue Jun  7 00:11:39 
2005
@@ -23,35 +23,108 @@
 }
 
 int HardShadows::computeShadows(const RenderContext& context,
-                                                                             
                                                  const LightSet* lights, 
RayPacket& rays,
-                                                                             
                                                  int start, RayPacket& 
shadowRays)
+                                                                             
                                                  const LightSet* lights, 
+                                                                             
                                                  RayPacket& rays,            
  // Input rays.
+                                                                             
                                                  int start,                  
  // Offset to start from in input rays?
+                                                                             
                                                  RayPacket& shadow_rays)     
  // Output shadow rays, already intersected.
 {
   int nlights = lights->numLights();
-  rays.computeHitPositions();
+  
+       // Compute the hit positions.
+       rays.computeHitPositions();
+       rays.computeNormals( context );
        
+#if 0
+       // Construct a shadow ray packet.
+       // NOTE: this code won't send more then RayPacket::MaxSize shadow 
rays.
+       // Although the old code didn't either.
+       
+       Real   distance [RayPacket::MaxSize];
+       Color  color    [RayPacket::MaxSize];
+       Vector direction[RayPacket::MaxSize];
+
+       int shadow_i = 0; // Iterator over computed shadow rays.
+       int i = start;    // Iterator over initial rays used to compute 
shadow rays.
+       
+       // NEED TO MAKE SURE ORDER MATCHES MATERIAL SHADER!!
+       // WANT ALL RAYS TOWARDS ONE LIGHT TO BE COMMON PACKET.
+       // 
+       
+       // Iterate over the lights and compute directions, colors, distances.
+       for (int light=0; 
+            (light<lights->numLights()) && 
+                        (shadow_i<RayPacket::MaxSize); 
+                        ++light) {
+               
+               // Compute the info for this light.
+               lights->get(light)->getLight( distance, color, direction, 
rays, context );
+               
+               // Compute the shadow rays and append them to the shadow 
packet.
+               
+               // Set the shadow ray.
+               for (int i=0; ((shadow_i+i)<RayPacket::MaxSize) && 
(i<rays.getSize();++i) {
+                       shadow_rays.get(shadow_i+i).ray.set( 
rays[i].hitPosition, direction[i] );
+               }
+               
+               // Copy the light contribution.
+               for (int i=0; ((shadow_i+i)<RayPacket::MaxSize) && 
(i<rays.getSize();++i) {             
+                       shadow_rays.get(shadow_i+i).light = 
lights[light].color;
+               }       
+               
+               // Copy the distance.
+               for (int i=0; ((shadow_i+i)<RayPacket::MaxSize) && 
(i<rays.getSize();++i) {
+                       shadow_rays.get(shadow_i+i).hitInfo.reset( 
distance[i] );
+               }
+               
+               // Move to the next part of the shadow ray packet.
+               shadow_i += rays.getSize();
+       }
+#endif
+
   int sidx = 0;
   int end = start;
   while(end < rays.getSize() && sidx+nlights <= RayPacket::MaxSize){
+
     RayPacket::Element& e = rays.get(end++);
+
+               // Specify the beginning index for this ray in the shadow 
packet.
     e.shadowBegin = sidx;
-    for(int l = 0;l<nlights;l++){
-      Vector dir(lights->centers[l]-e.hitPosition);
-      if(Dot(dir, e.normal)  > 0){
-                               RayPacket::Element& s = 
shadowRays.get(sidx++);
-                               double length = dir.normalize();
-                               s.ray.set(e.hitPosition+(e.normal*1e-3), dir);
-                               s.light = lights->colors[l];
-                               s.hitInfo.reset(length);
+
+               // Iterate over the lights and create shadow rays.
+    for(int l=0;l<nlights;l++){
+               
+                       Vector dir;
+                       Color  color;
+               
+                 // Compute the contribution for this light.
+                       lights->getLight(l)->computeLight( color, dir, 
context, e );
+      
+                       // Check to see if the light is on the front face.
+      if(Dot(dir, e.normal) > 0) {
+                       
+                               // If so normalize and compute length.
+                               Real length = dir.normalize();
+                       
+                               // Populate the shadow ray.
+                               RayPacket::Element& s = 
shadow_rays.get(sidx++);
+                               s.ray.set( e.hitPosition, dir );
+                               s.light = color;
+                               s.hitInfo.reset( length );
       }
     }
     e.shadowEnd = sidx;
   }
        
-  
shadowRays.setFlag(RayPacket::NormalizedDirections|RayPacket::HaveHitRecords);
-  shadowRays.resize(sidx);
+       // Send the shadow rays.
+  shadow_rays.setFlag( 
RayPacket::NormalizedDirections|RayPacket::HaveHitRecords );
+  shadow_rays.resize ( sidx );
+       
+       // Check to see if all of the shadow rays start from the same input 
ray.
   if(end == start+1)
-    shadowRays.setFlag(RayPacket::ConstantOrigin);
-  context.scene->getObject()->intersect(context, shadowRays);
+    shadow_rays.setFlag( RayPacket::ConstantOrigin );
+  
+       context.scene->getObject()->intersect(context, shadow_rays);
+       
   return end;
 }
 

Modified: branches/itanium2/Engine/Shadows/NoShadows.cc
==============================================================================
--- branches/itanium2/Engine/Shadows/NoShadows.cc       (original)
+++ branches/itanium2/Engine/Shadows/NoShadows.cc       Tue Jun  7 00:11:39 
2005
@@ -19,24 +19,32 @@
 {
 }
 
-int NoShadows::computeShadows(const RenderContext&,
-                             const LightSet* lights, RayPacket& rays,
-                             int start, RayPacket& shadowRays)
+int NoShadows::computeShadows(const RenderContext& context,
+                                                                             
                                          const LightSet* lights, RayPacket& 
rays,
+                                                                             
                                          int start, RayPacket& shadowRays)
 {
   int nlights = lights->numLights();
   rays.computeHitPositions();
-
+       
   int sidx = 0;
   while(start < rays.getSize() && sidx+nlights < RayPacket::MaxSize){
     RayPacket::Element& e = rays.get(start++);
     e.shadowBegin = sidx;
     for(int l = 0;l<nlights;l++){
+               
+                       Color color;
+                       Vector dir;
+               
+                       // Compute the direction & color of this light.
+                       
lights->getLight(l)->computeLight(color,dir,context,e);
+               
+                       // Construct the shadow ray.
       RayPacket::Element& s = shadowRays.get(sidx);
-      Vector dir(lights->centers[l]-e.hitPosition);
+                       
       if(Dot(dir, e.normal)  > 0){
-       sidx++;
-       s.ray.setDirection(dir);
-       s.light = lights->colors[l];
+                               sidx++;
+                               s.ray.setDirection(dir);
+                               s.light = color;
       }
     }
     e.shadowEnd = sidx;

Modified: branches/itanium2/Interface/Camera.h
==============================================================================
--- branches/itanium2/Interface/Camera.h        (original)
+++ branches/itanium2/Interface/Camera.h        Tue Jun  7 00:11:39 2005
@@ -17,6 +17,10 @@
     virtual void scaleFOV(double) = 0;
     virtual void translate(Vector v) = 0;
     virtual void dolly(double) = 0;
+               
+               // Accessors
+               virtual const Point &getPosition() const = 0; // This method 
is called to get the "location" by HeadLight etc.
+               
        virtual Point project(const Point &point) = 0; // project the 3D 
point on to the camera image plane
     enum TransformCenter {
       LookAt,

Modified: branches/itanium2/Interface/Light.h
==============================================================================
--- branches/itanium2/Interface/Light.h (original)
+++ branches/itanium2/Interface/Light.h Tue Jun  7 00:11:39 2005
@@ -3,21 +3,45 @@
 #define Manta_Interface_Light_h
 
 #include <Core/Color/Color.h>
+#include <Core/Geometry/PointVector.h>
+#include <Interface/RayPacket.h>
 
 namespace Manta {
 
   class PreprocessContext;
+       class RenderContext;
+       
   class Light {
   public:
     Light();
     virtual ~Light();
+               
+    virtual void preprocess( const PreprocessContext& context ) = 0;
+    // virtual const Point& getCenter() const = 0;
+    // virtual const Color& getColor() const = 0;
 
-    virtual void preprocess(const PreprocessContext& context) = 0;
-    virtual const Point& getCenter() const = 0;
-    virtual const Color& getColor() const = 0;
+#if 0          
+               // This method is called on the light by the shadow 
algorithm. The color and direction 
+               // produced by the light may change for each ray in the 
packet, and may change based 
+               // on the render context.
+               virtual void computeLight( Real   
lightDistance[RayPacket::MaxSize], 
+                                          Color  
resultColor[RayPacket::MaxSize], 
+                                                                             
                               Vector lightDirection[RayPacket::MaxSize], 
+                                                                             
                           
+                                                                             
                           RenderContext &context, RayPacket &rays ) = 0;
+#endif
+
+               // This method is called on the light by the shadow algorithm 
to compute
+               // the direction and contribution for one ray packet element.
+               // The direction is not normalized and the distance to the 
light from 
+               // the intersection must be computed.
+               virtual void computeLight( Color &resultColor, Vector 
&lightDirection,
+                                          const RenderContext &context, 
RayPacket::Element &e ) const = 0;
+               
   private:
-    Light(const Light&);
-    Light& operator=(const Light&);
+               // Lights may not be copied.
+    Light( const Light & );
+    Light& operator = ( const Light & );
   };
 }
 

Modified: branches/itanium2/Interface/LightSet.cc
==============================================================================
--- branches/itanium2/Interface/LightSet.cc     (original)
+++ branches/itanium2/Interface/LightSet.cc     Tue Jun  7 00:11:39 2005
@@ -23,13 +23,14 @@
 void LightSet::preprocess(const PreprocessContext& context)
 {
   // This won't work in many of the shadow algorithms
-  ASSERT(static_cast<int>(lights.size()) <= RayPacket::MaxSize);
-  if(ambientLight)
-    ambientLight->preprocess(context);
-  for(int i=0;i<static_cast<int>(lights.size());i++){
+  // ASSERT(static_cast<int>(lights.size()) <= RayPacket::MaxSize);
+  
+       // Call preprocess on ambient light.
+       ambientLight->preprocess(context);
+       
+       // Call preprocess on each light.
+  for(unsigned int i=0;i<lights.size();++i){
     lights[i]->preprocess(context);
-    centers[i] = lights[i]->getCenter();
-    colors[i] = lights[i]->getColor();
   }
 }
 

Modified: branches/itanium2/Interface/LightSet.h
==============================================================================
--- branches/itanium2/Interface/LightSet.h      (original)
+++ branches/itanium2/Interface/LightSet.h      Tue Jun  7 00:11:39 2005
@@ -15,46 +15,30 @@
 
   class LightSet {
   public:
-    LightSet()
-      : ambientLight(0)
-    {
-    }
-    ~LightSet()
-    {
-    }
+               LightSet()            : ambientLight(0) {  };
+               LightSet( int size_ ) : lights( size_ ), ambientLight(0) {  };
+    ~LightSet() {  }
 
-    const AmbientLight* getAmbientLight() const
-    {
-      return ambientLight;
-    }
-    void setAmbientLight(AmbientLight* newamb)
-    {
-      ambientLight = newamb;
-    }
+               // Get and set the ambient light for the scene.
+    const AmbientLight* getAmbientLight() const { return ambientLight; }
+    void setAmbientLight(AmbientLight* newamb) { ambientLight = newamb; }
+    
+               // Determine the size of the light set.
+               int numLights() const { return 
static_cast<int>(lights.size()); }
 
-    int numLights() const
-    {
-      return static_cast<int>(lights.size());
-    }
-    void add(Light* light)
-    {
-      lights.push_back(light);
-    }
-
-    const Light* getLight(int which) const
-    {
-      return lights[which];
-    }
-    Light* getLight(int which)
-    {
-      return lights[which];
-    }
-    static LightSet* merge(LightSet* l1, LightSet* l2);
+               // Append a light to the light set.
+    void add(Light* light) { lights.push_back(light); }
+               
+               // Accessors.
+    const Light* getLight(int which) const { return lights[which]; }
+    Light* getLight(int which)             { return lights[which]; }
+    
+               // Combine two light sets.
+               static LightSet* merge(LightSet* l1, LightSet* l2);
 
+               // Calls preprocess on each light.
     void preprocess(const PreprocessContext&);
 
-    Point centers[RayPacket::MaxSize];
-    Color colors[RayPacket::MaxSize];
   private:
     LightSet(const LightSet&);
     LightSet& operator=(const LightSet&);

Modified: branches/itanium2/Interface/Parameters.h
==============================================================================
--- branches/itanium2/Interface/Parameters.h    (original)
+++ branches/itanium2/Interface/Parameters.h    Tue Jun  7 00:11:39 2005
@@ -3,6 +3,6 @@
 #define Manta_Interface_Parameters_h
 
 #define MAXCACHELINESIZE 128
-#define T_EPSILON 1.e-4
+#define T_EPSILON 1.e-3
 
 #endif

Modified: branches/itanium2/Model/Cameras/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/Cameras/CMakeLists.txt      (original)
+++ branches/itanium2/Model/Cameras/CMakeLists.txt      Tue Jun  7 00:11:39 
2005
@@ -1,5 +1,8 @@
 
 SET (Manta_Cameras_SRCS
+     Cameras/EnvironmentCamera.h
      Cameras/EnvironmentCamera.cc
+     Cameras/PinholeCamera.h
      Cameras/PinholeCamera.cc
+     Cameras/OrthogonalCamera.h
      Cameras/OrthogonalCamera.cc)

Modified: branches/itanium2/Model/Cameras/EnvironmentCamera.h
==============================================================================
--- branches/itanium2/Model/Cameras/EnvironmentCamera.h (original)
+++ branches/itanium2/Model/Cameras/EnvironmentCamera.h Tue Jun  7 00:11:39 
2005
@@ -26,6 +26,9 @@
     virtual void autoview(double fov);
     virtual Point project(const Point &point);  // project a 3D point to the 
camera image plane
     static Camera* create(const vector<string>& args);
+               
+               virtual const Point &getPosition() const { return eye; }
+               
   private:
     void setup();
     Point  eye;

Modified: branches/itanium2/Model/Cameras/OrthogonalCamera.h
==============================================================================
--- branches/itanium2/Model/Cameras/OrthogonalCamera.h  (original)
+++ branches/itanium2/Model/Cameras/OrthogonalCamera.h  Tue Jun  7 00:11:39 
2005
@@ -25,6 +25,9 @@
     virtual void autoview(double fov);
        virtual Point project(const Point &point);
     static Camera* create(const vector<string>& args);
+               
+               virtual const Point &getPosition() const { return eye; }
+               
   private:
     void setup();
     Point eye;

Modified: branches/itanium2/Model/Cameras/PinholeCamera.h
==============================================================================
--- branches/itanium2/Model/Cameras/PinholeCamera.h     (original)
+++ branches/itanium2/Model/Cameras/PinholeCamera.h     Tue Jun  7 00:11:39 
2005
@@ -28,6 +28,9 @@
     virtual void autoview(double fov);
          virtual Point project(const Point &point);  // project a 3D point 
to the camera image plane
     static Camera* create(const vector<string>& args);
+               
+               virtual const Point &getPosition() const { return eye; }
+               
   private:
     void setup();
     Point  eye;

Modified: branches/itanium2/Model/Groups/kdtree.cc
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.cc    (original)
+++ branches/itanium2/Model/Groups/kdtree.cc    Tue Jun  7 00:11:39 2005
@@ -7,7 +7,10 @@
 #include "kdtree.h"
 
 #include <Model/Intersections/AxisAlignedBox.h>
+
 #include <SCIRun/Core/Thread/Time.h>
+#include <SCIRun/Core/Thread/Thread.h>
+#include <SCIRun/Core/Thread/Runnable.h>
 
 using namespace Manta;
 using namespace Manta::Kdtree;
@@ -31,6 +34,104 @@
 inline int intersectTriangle3Edge(const Ray &ray, const Triangle &tri,
                                                                              
                                                          float &t, float &u, 
float &v );
 
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// Worker thread for load V3C1 method (boeing dataset).
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+class V3C1Worker : public Runnable {
+public:
+       BBox bounds; // Thread specific bounding box.
+       
+       // Target data.
+       float *rawData;
+       VArray<Triangle> **tris;
+       Vectorf **perVertNormals;
+       
+       // Region of data this thread is responsible for.
+       long begin_offset;
+       long end_offset;
+       
+       
/////////////////////////////////////////////////////////////////////////////
+       // Constructor.
+       V3C1Worker( float *rawData_, VArray<Triangle> **tris_, Vectorf 
**perVertNormals_,
+                   long begin_offset_, long end_offset_ ) :
+               Runnable( false ), // Do not delete on exit (so we can pick 
up the bounds).
+               rawData( rawData_ ), tris( tris_ ), perVertNormals( 
perVertNormals_ ),
+               begin_offset( begin_offset_ ), end_offset( end_offset_ ) {  }
+       
+       
/////////////////////////////////////////////////////////////////////////////
+       // This is the thread method.
+       virtual void run() {
+       
+               for (long i=begin_offset; i<end_offset; i++) {
+                       
+                       // Offset into the data.
+                       float *_rawData = rawData + 12 * i;
+                       
+                       // Check to see if we are on a big endian system
+                       // Data was generate on Altix (little endian)
+                       if (is_big_endian()) {
+                               for (int j=0; j<3; ++j) {
+                                       (**tris)[i][j] = Pointf( endian_swap( 
_rawData[0] ), 
+                                                                             
                                                           endian_swap( 
_rawData[1] ), 
+                                                                             
                                                           endian_swap( 
_rawData[2] ));
+                                       _rawData += 3;
+                               }
+                       }
+                       // Otherwise don't swap.
+                       else {
+                               for (int j=0; j<3; ++j) {
+                                       (**tris)[i][j] = Pointf( _rawData[0], 
_rawData[1], _rawData[2] );
+                                       _rawData += 3;
+                               }
+                       }
+                       
+                       long r, g, b;
+                       
+                       // Check for big endian data.
+                       if (is_big_endian()) {
+                               r = int(endian_swap(_rawData[0]) * 255 + .5f);
+                               g = int(endian_swap(_rawData[1]) * 255 + .5f);
+                               b = int(endian_swap(_rawData[2]) * 255 + .5f);
+                               _rawData += 3;
+                       }
+                       else {
+                               r = int(_rawData[0] * 255 + .5f);
+                               g = int(_rawData[1] * 255 + .5f);
+                               b = int(_rawData[2] * 255 + .5f);
+                               _rawData += 3;                  
+                       }
+                       
+                       // Compute edges.
+                       (**tris)[i].edge1 = (**tris)[i][1] - (**tris)[i][0]; 
+                       (**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0];
+                       
+                       // Specify the payload.
+                       (**tris)[i].payload = ((r<<16)+(g<<8)+b);
+                       
+                       // Compute the normal.
+                       Vectorf v01, v02;
+                       v01 = (**tris)[i][1] - (**tris)[i][0];
+                       v02 = (**tris)[i][2] - (**tris)[i][0];
+                       (*perVertNormals)[3*i] = Cross(v01, v02).normal();
+                       
+                       // Copy normals to each vertex.
+                       (*perVertNormals)[3*i+1] = (*perVertNormals)[3*i+2] = 
(*perVertNormals)[3*i];
+                       
+                       // Update the bounding box of the whole scene
+                       for (long j=0; j<3; j++) {
+                               Triangle &tri = (**tris)[i];
+                               bounds.extendByPoint( tri[0] );
+                               bounds.extendByPoint( tri[1] );
+                               bounds.extendByPoint( tri[2] ); 
+                       }
+               }               
+       }
+       
+};
+
+
 int LoadTris(const char *filename, 
                                                 VArray<Triangle> **tris, 
                         Vectorf **perTriNormals, 
@@ -53,11 +154,7 @@
        int line = 0;
        char line_buffer[128];
        
-       // Begin timer.
-       // Timer timer;
-       // double time;
        
-       // timer.start();
        
        // Read in the file.
        while (fgets( line_buffer, 127, f ) != NULL) {
@@ -149,7 +246,9 @@
        return 1;
 }
 
-int LoadBin_V3C1(const char *filename, VArray<Triangle> **tris, /*Vectorf 
**perVertNormals,*/ Vectorf **perVertNormals, BBox &bounds ) {
+int LoadBin_V3C1(const char *filename, VArray<Triangle> **tris, /*Vectorf 
**perVertNormals,*/ Vectorf **perVertNormals, BBox &bounds, int np ) {
+       
+       
        
        FILE *f;
        if ((f=fopen(filename, "r")) == NULL) {
@@ -170,10 +269,11 @@
        //
        long i;
        
-#pragma omp parallel for private (i)
-       for (i=0; i<nFloats; i+=1024*4) {
-               rawData[i] = 0;
-       }
+       // #pragma omp parallel for private (i)
+       
+       // for (i=0; i<nFloats; i+=1024*4) {
+       //      rawData[i] = 0;
+       // }
        
        fseek(f, 0, SEEK_SET);
        
@@ -187,26 +287,75 @@
        
        double time_end = Time::currentSeconds();
        
-       std::cout << "Time to input triangles: " << (time_end-time_begin) << 
" seconds. " 
-                                               << 
(double)nTris/(time_end-time_begin) << " faces/second." << std::endl;
+       std::cout << "Time to input triangles: " << (time_end-time_begin)     
                         << " seconds. "  << std::endl
+               << "Total file size:         " << 
((double)fileSize/1048576.0) << " MB. " << std::endl
+               << "IO Performance:          " << 
((double)fileSize/1048576.0)/(time_end-time_begin) << " MB/second." << 
std::endl;
        
+       // Allocate a new array for the triangles.
        time_begin = Time::currentSeconds();
        
-       // Allocate a new array for the triangles.
        *tris = new VArray<Triangle> (nTris);
        (*tris)->setLen(nTris);
        *perVertNormals = new Vectorf [nTris*3];
        
+       // Record the time for alloc/dealloc
+       double memory_time = (Time::currentSeconds() - time_begin);
+       
+       // Record the time for the actual preprocess.
+       time_begin = Time::currentSeconds();
+       
+       std::cout << "Creating " << np << " workers." << std::endl;
+       
+       // Create worker threads to preprocess and bound the data.
+       Thread **workers = new Thread *[ np ];
+       
+       int work_per_thread = nTris / np;
+       
+       long begin = 0;
+       long end   = work_per_thread;
+       
+       std::cout << "Faces per worker: " << work_per_thread << std::endl;
+       
+       char worker_name[32];
+       
+       // Assign work to the workers.
+       for (int i=0;i<np-1;++i) {
+               
+               sprintf( worker_name, "V3C1 Worker %d", i );
+       
+               workers[i] = new Thread( new V3C1Worker( rawData, tris, 
perVertNormals, begin, end ), worker_name );    
+               begin = end;
+               end += work_per_thread;
+       }
+       
+       sprintf( worker_name, "V3C1 Worker %d", np-1 );
+       
+       // Assign the rest of the work to the last worker.
+       workers[np-1] = new Thread( new V3C1Worker( rawData, tris, 
perVertNormals, begin, nTris ), "V3C1 Worker" );
+       
+       // Wait for all of the threads to finish.
+       for (int i=0;i<np;++i) {
+               workers[i]->join();
+       
+               std::cout << "Worker " << i << " finished." << std::endl;
+                               
+               // Enlarge the bounding box.
+               bounds.extendByBox( ((V3C1Worker 
*)workers[i]->getRunnable())->bounds );
+               
+               // Delete the thread.
+               // delete workers[i];
+       }
+       
+       // Delete the array of pointers to workers.
+       delete [] workers;
+       
+#if 0  
        float *_rawData;
-#pragma omp parallel for private (_rawData, i)
+       // #pragma omp parallel for private (_rawData, i)
        for (i=0; i<nTris; i++) {
+               
+               // Offset into the data.
                _rawData = rawData + 12 * i;
-               /*
-                  (*perVertNormals)[3*i] = 
-                  (*perVertNormals)[3*i+1] = 
-                  (*perVertNormals)[3*i+2] =
-                  Vectorf(_rawData[0], _rawData[1], _rawData[2]);
-                */
                
                // Check to see if we are on a big endian system
                // Data was generate on Altix (little endian)
@@ -226,15 +375,6 @@
                        }
                }
                
-#if 0
-               (**tris)[i][0] = Pointf(_rawData[0], _rawData[1], 
_rawData[2]);
-               _rawData += 3;
-               (**tris)[i][1] = Pointf(_rawData[0], _rawData[1], 
_rawData[2]);
-               _rawData += 3;
-               (**tris)[i][2] = Pointf(_rawData[0], _rawData[1], 
_rawData[2]);
-               _rawData += 3;
-#endif
-               
                long r, g, b;
                
                // Check for big endian data.
@@ -251,15 +391,20 @@
                        _rawData += 3;                  
                }
                
+               // Compute edges.
                (**tris)[i].edge1 = (**tris)[i][1] - (**tris)[i][0]; 
-               (**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0]; 
+               (**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0];
+               
+               // 
                (**tris)[i].payload = ((r<<16)+(g<<8)+b);
                
+               // Compute the normal.
                Vectorf v01, v02;
                v01 = (**tris)[i][1] - (**tris)[i][0];
                v02 = (**tris)[i][2] - (**tris)[i][0];
                (*perVertNormals)[3*i] = Cross(v01, v02).normal();
                
+               // Copy normals to each vertex.
                (*perVertNormals)[3*i+1] = (*perVertNormals)[3*i+2] = 
(*perVertNormals)[3*i];
                
                // Update the bounding box of the whole scene
@@ -271,93 +416,97 @@
                }
                
        }
-       
+#endif 
        time_end = Time::currentSeconds();
        
-       std::cout << "Time to parse triangles: " << (time_end - time_begin) 
<< " seconds." 
-                 << (double)nTris/(time_end-time_begin) << " faces/second." 
<< std::endl;
+       std::cout << "Time to parse triangles: " << (time_end - 
time_begin)/60.0 << " Minutes." << std::endl;
+       std::cout << "Triangles loaded: " << nTris << std::endl;
+       
+       time_begin = Time::currentSeconds();
        
-       fprintf(stderr, "Triangles loaded: %d\n", nTris);
        delete [] rawData;
+       
+       memory_time += (Time::currentSeconds() - time_begin);
+       
+       std::cout << "Total time for memory allocation/deallocation: " << 
memory_time << " Seconds." << std::endl;
+       
        return 1;
 }
 
 int LoadBin_N1V3(const char *filename, VArray<Triangle> **tris, 
-               Vectorf **perVertNormals,
-               BBox &bounds,
-               long long maxtris=-1)
+                                                                Vectorf 
**perVertNormals,
+                                                                BBox &bounds,
+                                                                long long 
maxtris=-1)
 {
        FILE *f;
        int nFloatPerTri = 3+9;
        int triSize = nFloatPerTri*sizeof(float);
-
+       
        if ((f=fopen(filename, "r")) == NULL) {
                fprintf(stderr, "Cannot open file: %s\n", filename);
                return 0;
        }
-
+       
        fseek(f, 0, SEEK_END);
        long long fileSize = ftell(f);
        // One normal followed by 3 vertices
        long long nTris = fileSize / ((3+9)*4);
-
+       
        if (maxtris>0 && nTris > maxtris)
                nTris = maxtris;
-
+       
        long long totalNumFloats = nFloatPerTri * nTris;
        float *rawData = new float [totalNumFloats];
        long i;
 #pragma omp parallel for private (i)
-       for (i=0; i<totalNumFloats; i+=1024*4) {
-               rawData[i] = 0;
-       }
+       
+       // Zero out the raw data.
+       memset( rawData, 0x0, totalNumFloats*sizeof(float) );
+       
        fseek(f, 0, SEEK_SET);
-       long long nFloats = 
-               fread(rawData, sizeof(float), totalNumFloats, f);
+       long long nFloats = fread(rawData, sizeof(float), totalNumFloats, f);
        if (nFloats != totalNumFloats) {
                fprintf(stderr, "Error reading file: %s (size in floats: %lld 
read: %lld)\n", filename, totalNumFloats, nFloats);
        }
-
+       
        *tris = new VArray<Triangle> (nTris);
        (*tris)->setLen(nTris);
        *perVertNormals = new Vectorf [nTris*3];
-
+       
        float *_rawData;
 #pragma omp parallel for private (_rawData, i)
        for (i=0; i<nTris; i++) {
                _rawData = rawData + 12 * i;
-               (*perVertNormals)[3*i] = 
-                       (*perVertNormals)[3*i+1] = 
-                       (*perVertNormals)[3*i+2] =
-                       Vectorf(_rawData[0], _rawData[1], _rawData[2]);
+               
+               (*perVertNormals)[3*i] = (*perVertNormals)[3*i+1] = 
+                                        (*perVertNormals)[3*i+2] =
+                                              Vectorf(_rawData[0], 
_rawData[1], _rawData[2]);
+                                                                             
                                   
                (**tris)[i][0] = Point(_rawData[3], _rawData[4], _rawData[5]);
-               _rawData += 6;
+               _rawData += 6; // Is this correct?
+               
                (**tris)[i][1] = Point(_rawData[0], _rawData[1], _rawData[2]);
                _rawData += 3;
+               
                (**tris)[i][2] = Point(_rawData[0], _rawData[1], _rawData[2]);
                _rawData += 3;
+               
                (**tris)[i].payload = 0xFFFFFF;
+               
+               // Compute edges.
                (**tris)[i].edge1 = (**tris)[i][1] - (**tris)[i][0]; 
                (**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0]; 
-
+               
                //
                // Update the bounding box of the whole scene
           for (int j=0; j<3; j++) {
                   Triangle &tri = (**tris)[i];
-                       bounds.extendByPoint( tri[0] );
-                       bounds.extendByPoint( tri[1] );
-                       bounds.extendByPoint( tri[2] ); 
+                        bounds.extendByPoint( tri[0] );
+                        bounds.extendByPoint( tri[1] );
+                        bounds.extendByPoint( tri[2] ); 
           }
        }
-       /*
-          for (int i=0; i<nTris; i++) {
-          Triangle &tri = (**tris)[i];
-          printf("%f %f %f ", tri.v0[0], tri.v0[1], tri.v0[2]); 
-          printf("%f %f %f ", tri.v1[0], tri.v1[1], tri.v1[2]); 
-          printf("%f %f %f ", tri.v2[0], tri.v2[1], tri.v2[2]); 
-          printf("0xFF0000\n");
-          }
-        */
+       
        fprintf(stderr, "Triangles loaded: %d\n", nTris);
        delete [] rawData;
        return 1;
@@ -383,11 +532,13 @@
 
 int KDTree::load( const char *fn) {
        
+       double time_begin = Time::currentSeconds();
+       
        // Call a helper function to load the triangles.
        if (strstr(fn, ".tri")) {
                LoadTris(fn, &tris, NULL, &normals, bbox );
        } else if (strstr(fn, ".v3c1")) {
-               LoadBin_V3C1(fn, &tris, &normals, bbox );
+               LoadBin_V3C1(fn, &tris, &normals, bbox, 32 );
        } else if (strstr(fn, ".bin") || strstr(fn, "n1v3")) {
                LoadBin_N1V3(fn, &tris, &normals, bbox );
        } else {
@@ -395,6 +546,10 @@
                return 0;
        }
        
+       double time_end = Time::currentSeconds();
+       
+       std::cout << "Total time for loading triangles: " << (time_end - 
time_begin) << std::endl << std::endl;
+       
        
/////////////////////////////////////////////////////////////////////////////
        // Load the kd tree.
        char filename[512];
@@ -411,7 +566,7 @@
        void *buffer = (void*)malloc(fileSize);
        fseek(f, 0, SEEK_SET);
        
-       double time_begin = Time::currentSeconds();
+       time_begin = Time::currentSeconds();
        
        long long nread = fread(buffer, 1, fileSize, f);
        if (nread != fileSize) {
@@ -419,10 +574,11 @@
                                                filename, fileSize, nread);
        }
        fclose(f);
-
-       double time_end = Time::currentSeconds();
+       
+       time_end = Time::currentSeconds();
+       
        std::cout << "Time to read kdtree: " << (time_end-time_begin) << " 
seconds." << std::endl;
-
+       
        // Specify the root node loaded from the file.
        rootNode = (KDTreeNode*)buffer;
        
@@ -479,7 +635,7 @@
        time_end = Time::currentSeconds();
        
        std::cout << "Total time to read in indices: " << 
(time_end-time_begin) << std::endl;
-
+       
        triIndices = indices;
        
        // Swap the indicies.

Modified: branches/itanium2/Model/Lights/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/Lights/CMakeLists.txt       (original)
+++ branches/itanium2/Model/Lights/CMakeLists.txt       Tue Jun  7 00:11:39 
2005
@@ -1,3 +1,6 @@
 
 SET (Manta_Lights_SRCS
-     Lights/PointLight.cc)
+     Lights/PointLight.h
+     Lights/PointLight.cc
+     Lights/HeadLight.h
+     Lights/HeadLight.cc)

Modified: branches/itanium2/Model/Lights/PointLight.cc
==============================================================================
--- branches/itanium2/Model/Lights/PointLight.cc        (original)
+++ branches/itanium2/Model/Lights/PointLight.cc        Tue Jun  7 00:11:39 
2005
@@ -16,13 +16,13 @@
 {
 }
 
-const Point& PointLight::getCenter() const
-{
-  return position;
-}
+void PointLight::computeLight( Color &resultColor, Vector &lightDirection, 
const RenderContext &context, RayPacket::Element &e ) const {
 
-const Color& PointLight::getColor() const
-{
-  return color;
+       // Specify the color.
+       resultColor = color;
+       
+       // Compute the light direction.
+       lightDirection = (position - e.hitPosition);
+       
 }
 

Modified: branches/itanium2/Model/Lights/PointLight.h
==============================================================================
--- branches/itanium2/Model/Lights/PointLight.h (original)
+++ branches/itanium2/Model/Lights/PointLight.h Tue Jun  7 00:11:39 2005
@@ -13,8 +13,10 @@
     virtual ~PointLight();
 
     virtual void preprocess(const PreprocessContext&);
-    virtual const Point& getCenter() const;
-    virtual const Color& getColor() const;
+    
+               virtual void computeLight( Color &resultColor, Vector 
&lightDirection,
+                                          const RenderContext &context, 
RayPacket::Element &e ) const;
+               
   private:
     Point position;
     Color color;

Modified: branches/itanium2/Model/Materials/Lambertian.cc
==============================================================================
--- branches/itanium2/Model/Materials/Lambertian.cc     (original)
+++ branches/itanium2/Model/Materials/Lambertian.cc     Tue Jun  7 00:11:39 
2005
@@ -17,7 +17,7 @@
 }
 
 Lambertian::Lambertian(const Texture<Color>* colortex)
-  : colortex(colortex)
+: colortex(colortex)
 {
 }
 
@@ -29,51 +29,91 @@
 {
   // Shade a bunch of rays.  We know that they all have the same intersected
   // object and are all of the same material
-
+       
   // Compute normals
   rays.computeNormals(context);
-
+       
   // Compute colors
   Color colors[RayPacket::MaxSize];
   colortex->mapValues(context, rays, colors);
-
+       
   // Compute ambient contributions for all rays
   activeLights->getAmbientLight()->computeAmbient(context, rays);
-
+       
+#if 0  
+       RayPacket::Iterator ray_iter = rays.begin(); // Iterate across the 
ray packet making shadow rays.
+       RayPacket::Iterator ray_end  = rays.end();
+       RayPacket::Iterator ray_last;    // Iterator to the last ray in the 
shadow packet.
+       RayPacket::Iterator ray_copy;    // Iterator between ray_iter and 
ray_last.
+       
+       RayPacket shadow_rays;           // Ray Packet for the shadow rays..
+       RayPacket::Iterator shadow_iter  // Iterator over shadow packets.
+       
+       for (;ray_iter<ray_end;++ray_iter) {
+               
+               // Create a shadow ray packet.
+               ray_last = context.shadowAlgorithm->computeShadows( context, 
activeLights,
+                                                                   ray_iter, 
ray_end,
+                                                                             
                                                                              
                                                                    
shadow_rays );
+               
+               // Compute the total contribution for each ray that has 
shadow rays
+               // in this shadow packet.
+               for (ray_copy=ray_iter;ray_copy<ray_last;++ray_copy) {
+                       Color total_light = ray_copy.getAmbientLight();
+                       
+                       // Iterate over the shadow rays for this inital ray.
+                       for 
(shadow_iter=ray_copy.shadowBegin();shadow_iter<ray_copy.shadowEnd();++shadow_iter)
 {
+                               
+                               // Check to see if a hit occured.
+                               if (shadow_iter.getHitInfo().wasHit()) {
+                                       Real cos_theta = 
Dot(shadow_iter.getRay().direction(),
+                                                            
ray_copy.getNormal() );
+                                       // Add the contribution for this 
light.
+                                       total_light += shadow_iter.getLight();
+                               }
+                       }
+                       
+                       // Set the color for this ray.
+                       ray_copy.setResult( colors[i]*totalLight );
+               }
+       }
+       
+#endif
   RayPacketData data;
   int start = 0;
   do {
     RayPacket shadowRays(data, 0, rays.getDepth(), 0);
     int end = context.shadowAlgorithm->computeShadows(context, activeLights,
-                                                     rays, start, 
shadowRays);
+                                                                             
                                                                              
                                                            rays, start, 
shadowRays);
     if(shadowRays.getFlags() & RayPacket::NormalizedDirections){
       for(int i=start;i<end;i++){
-       RayPacket::Element& e = rays.get(i);
-       Color totalLight(e.ambientLight);
-       for(int j=e.shadowBegin;j<e.shadowEnd;j++){
-         RayPacket::Element& s = shadowRays.get(j);
-         if(!s.hitInfo.wasHit()){
-           double cos_theta = Dot(s.ray.direction(), e.normal);
-           totalLight += s.light*cos_theta;
-         }
-       }
-       rays.setResult(i, colors[i]*totalLight);
+                               RayPacket::Element& e = rays.get(i);
+                               Color totalLight(e.ambientLight);
+                               for(int j=e.shadowBegin;j<e.shadowEnd;j++){
+                                       RayPacket::Element& s = 
shadowRays.get(j);
+                                       if(!s.hitInfo.wasHit()){
+                                               double cos_theta = 
Dot(s.ray.direction(), e.normal);
+                                               totalLight += 
s.light*cos_theta;
+                                       }
+                               }
+                               rays.setResult(i, colors[i]*totalLight);
       }
     } else {
       for(int i=start;i<end;i++){
-       RayPacket::Element& e = rays.get(i);
-       Color totalLight(e.ambientLight);
-       for(int j=e.shadowBegin;j<e.shadowEnd;j++){
-         RayPacket::Element& s = shadowRays.get(j);
-         if(!s.hitInfo.wasHit()){
-           s.ray.normalizeDirection();
-           double cos_theta = Dot(s.ray.direction(), e.normal);
-           totalLight += s.light*cos_theta;
-         }
-       }
-       rays.setResult(i, colors[i]*totalLight);
+                               RayPacket::Element& e = rays.get(i);
+                               Color totalLight(e.ambientLight);
+                               for(int j=e.shadowBegin;j<e.shadowEnd;j++){
+                                       RayPacket::Element& s = 
shadowRays.get(j);
+                                       if(!s.hitInfo.wasHit()){
+                                               s.ray.normalizeDirection();
+                                               double cos_theta = 
Dot(s.ray.direction(), e.normal);
+                                               totalLight += 
s.light*cos_theta;
+                                       }
+                               }
+                               rays.setResult(i, colors[i]*totalLight);
       }
     }
     start = end;
   } while(start < rays.getSize());
+
 }

Modified: branches/itanium2/scenes/boeing777.cc
==============================================================================
--- branches/itanium2/scenes/boeing777.cc       (original)
+++ branches/itanium2/scenes/boeing777.cc       Tue Jun  7 00:11:39 2005
@@ -18,6 +18,7 @@
 #include <Model/Groups/Group.h>
 #include <Model/Groups/kdtree.h>
 #include <Model/Lights/PointLight.h>
+#include <Model/Lights/HeadLight.h>
 #include <Model/Materials/Lambertian.h>
 #include <Model/Materials/MetalMaterial.h>
 #include <Model/Materials/NormalMaterial.h>
@@ -69,7 +70,8 @@
        
        double end_time = Time::currentSeconds();
        
-       std::cout << "Total load time: " << (end_time-start_time)/60.0 << " 
minutes." << std::endl;
+       std::cout << "Total load time: " << (end_time-start_time)/60.0 << " 
minutes." 
+                 << std::endl << std::endl;
        
        // Add the kdtree to the world group.
        group->add( kdtree );
@@ -88,7 +90,8 @@
        //      lights->add( new PointLight( bounds.getCorner(i), Color(RGB( 
0.15, 0.15, 0.15 )) ));
        //}
 
-       lights->add( new PointLight( Point(5000,5000,5000), 
Color(RGB(1.0,1.0,1.0)) ));
+       // lights->add( new PointLight( Point(5000,5000,5000), 
Color(RGB(1.0,1.0,1.0)) ));
+       lights->add( new HeadLight( Vector( 0.0, 1.0, 0.0 ), 
Color(RGB(1.0,1.0,1.0)) ));
        
        //lights->add( new PointLight( bounds.center() + Vector
 
@@ -109,7 +112,7 @@
        PinholeCamera *camera = new PinholeCamera( bounds[1], bounds[0], 
Vector(0,1,0), 40.0 );
        
        // Background.
-       scene->setBackground( new ConstantBackground(Color(RGB(0.8, 0.8, 
0.8))) );
+       scene->setBackground( new ConstantBackground( Color(RGB(0.8, 0.8, 
0.8)) ) );
        
        return scene;
 }




  • [MANTA] r367 - in branches/itanium2: Engine/Shadows Interface Model/Cameras Model/Groups Model/Lights Model/Materials scenes, abe, 06/07/2005

Archive powered by MHonArc 2.6.16.

Top of page