Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1325 - in trunk: Engine/Shadows Interface Model/Materials SwigInterface


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1325 - in trunk: Engine/Shadows Interface Model/Materials SwigInterface
  • Date: Mon, 9 Apr 2007 16:58:45 -0600 (MDT)

Author: bigler
Date: Mon Apr  9 16:58:40 2007
New Revision: 1325

Modified:
   trunk/Engine/Shadows/HardShadows.cc
   trunk/Interface/RayPacket.h
   trunk/Model/Materials/Dielectric.cc
   trunk/Model/Materials/Dielectric.h
   trunk/Model/Materials/Lambertian.cc
   trunk/Model/Materials/Phong.cc
   trunk/SwigInterface/manta.i
   trunk/SwigInterface/mantainterface.i
   trunk/SwigInterface/runmanta.py
Log:

Engine/Shadows/HardShadows.cc

  Things seem to be working now.

  Added debug flag information.

  Added 'first' variable to tell where the first shadow ray is.  This
  is needed for later when you need to set the begin and end range of
  the shadow ray packet.

  Added a rayAttenudated flag array.  This helps keep track of which
  rays are being attenuated and which are not (or are done).

  Changed while loop to do/while loop.

Interface/RayPacket.h

  Added warning about using resize(int newSize).  This is a hold over
  from the days when all rays from 0 to size were active instead of
  now when you have a begin/end range.

  Added a new resize function that take rayBegin and rayEnd.
  
Model/Materials/Dielectric.cc
Model/Materials/Dielectric.h

  Added attenuateShadows implementation.

Model/Materials/Lambertian.cc
Model/Materials/Phong.cc

  Added debug flag propagation to the new ray packets.

SwigInterface/manta.i

  Added interfaces for the OpaqueShadower and uncommented LitMaterial.

  Added PixelSampler interfaces and casting helpers.

SwigInterface/mantainterface.i

  Added PixelSampler interface.

SwigInterface/runmanta.py

  Added createTransparentShadowScene.

  Don't delete the factory.  It seems to crash on my laptop.

  Default number of processors is 1 not 2.  That was a very
  frustrating hour or so of debugging two threads at the same time.

  Default scene is now the createTransparentShadowScene.

  Shadows are now attenuated by default. ;)


Modified: trunk/Engine/Shadows/HardShadows.cc
==============================================================================
--- trunk/Engine/Shadows/HardShadows.cc (original)
+++ trunk/Engine/Shadows/HardShadows.cc Mon Apr  9 16:58:40 2007
@@ -48,6 +48,12 @@
                                  RayPacket& sourceRays,        // Input rays.
                                  RayPacket& shadowRays)        // Output 
shadow rays, already intersected.
 {
+  int debugFlag = sourceRays.getAllFlags() & RayPacket::DebugPacket;
+  if (debugFlag) {
+    cerr << "HardShadows::computeShadows called\n";
+    //    cerr << SCIRun::getStackTrace();
+  }
+  
   int nlights = lights->numLights();
   
   // Compute the hit positions.
@@ -65,6 +71,7 @@
   }
 
   // Compute the contribution for this light.
+  int first = -1;
   int last = -1;
   do {
     lights->getLight(j)->computeLight(shadowRays, context, sourceRays);
@@ -83,6 +90,8 @@
           shadowRays.setRay(i, sourceRays.getHitPosition(i), dir );
           shadowRays.resetHit(i, length );
           last = i;
+          if (first < 0)
+            first = i;
         } else {
           shadowRays.maskRay(i);
         }
@@ -100,6 +109,8 @@
           shadowRays.setRay(i, sourceRays.getHitPosition(i), dir );
           shadowRays.resetHit(i, length );
           last = i;
+          if (first < 0)
+            first = i;
         } else {
           shadowRays.maskRay(i);
         }
@@ -146,6 +157,8 @@
           __m128 combo = _mm_or_ps(_mm_andnot_ps(mask, length), 
_mm_and_ps(_mm_set1_ps(-MAXT), mask));
           _mm_store_ps(&shadowData->minT[i], combo);
           last = i+3;
+          if (first < 0)
+            first = i;
         } else {
           _mm_store_ps(&shadowData->minT[i], _mm_set1_ps(-MAXT));
         }
@@ -161,6 +174,8 @@
           shadowRays.setRay(i, sourceRays.getHitPosition(i), dir );
           shadowRays.resetHit(i, length );
           last = i;
+          if (first < 0)
+            first = i;
         } else {
           shadowRays.maskRay(i);
         }
@@ -179,6 +194,8 @@
         shadowRays.setRay(i, sourceRays.getHitPosition(i), dir );
         shadowRays.resetHit(i, length );
         last = i;
+        if (first < 0)
+          first = i;
       } else {
         shadowRays.maskRay(i);
       }
@@ -186,57 +203,89 @@
 #endif // ifdef MANTA_SSE
     j++;
   } while(last == -1 && j < nlights);
-      
+
   // Send the shadow rays, if any
   if(last != -1){
     shadowRays.setFlag( RayPacket::NormalizedDirections );
-    shadowRays.resize ( last + 1);
+    shadowRays.resize ( first, last + 1);
+    //shadowRays.resetHits();
     context.scene->getObject()->intersect(context, shadowRays);
     if (attenuateShadows) {
-      bool raysActive = true;
+      bool raysActive;
       Real cutoff = context.scene->getRenderParameters().importanceCutoff;
       int currentDepth = shadowRays.getDepth();
       int maxDepth = context.scene->getRenderParameters().maxDepth;
-      while (raysActive && (currentDepth < maxDepth)) {
+      int pass = 0;
+      bool rayAttenudated[RayPacket::MaxSize];
+      for(int i = shadowRays.begin(); i < shadowRays.end(); ++i) {
+        rayAttenudated[i] = false;
+      }
+      do {
+        pass++;
+        if (debugFlag) cerr << "================   pass  "<<pass<<"   
=====\n";
         // Those rays that did hit something, we need to compute the
         // attenuation.
 
-        raysActive = false;
+        // This is when none of the rays hit, we can avoid the loop below.
+        bool anyHit = false;
         for(int i = shadowRays.begin();i<shadowRays.end();){
-          if(shadowRays.wasHit(i)){
-            const Material* hit_matl = shadowRays.getHitMaterial(i);
-            int end = i+1;
+          int end = i+1;
+          const Material* hit_matl = shadowRays.getHitMaterial(i);
+          if(shadowRays.wasHit(i) && hit_matl != (Material*)0xffffffff){
+            anyHit = true;
+            rayAttenudated[i] = true;
             while(end < shadowRays.end() && shadowRays.wasHit(end) &&
-                  shadowRays.getHitMaterial(end) == hit_matl)
+                  shadowRays.getHitMaterial(end) == hit_matl) {
+              rayAttenudated[end] = true;
               end++;
+            }
             RayPacket subPacket(shadowRays, i, end);
+            if (debugFlag) cerr << "attenuating shadow rays 
("<<shadowRays.begin()<<", "<<shadowRays.end()<<")\n";
             hit_matl->attenuateShadows(context, subPacket);
-            i=end;
           }
+          i=end;
         }
 
-        // If there are any rays left that have attenuation, create a
-        // new shadow ray and keep it going.
-        for(int i = shadowRays.begin();i<shadowRays.end();){
-          if(shadowRays.wasHit(i) &&
-             !shadowRays.getColor(i).luminance() > cutoff) {
-            if (!raysActive) {
-              raysActive = true;
-              currentDepth++;
-            }
+        raysActive = false;
+        if (anyHit) {
+          // If there are any rays left that have attenuation, create a
+          // new shadow ray and keep it going.
+          for(int i = shadowRays.begin();i<shadowRays.end();){
             int end = i+1;
-            while(end < shadowRays.end() &&
-                  shadowRays.wasHit(i) &&
-                  (!shadowRays.getColor(i).luminance() > cutoff))
-              end++;
-            // Change all the origins and reset the hits?
-            RayPacket subPacket(shadowRays, i, end);
-            subPacket.computeHitPositions();
-            context.scene->getObject()->intersect(context, subPacket);
+            const Material* hit_matl = shadowRays.getHitMaterial(i);
+            if(rayAttenudated[i]) {
+              if (shadowRays.getColor(i).luminance() > cutoff) {
+                if (!raysActive) {
+                  raysActive = true;
+                  currentDepth++;
+                }
+                while(end < shadowRays.end() &&
+                      rayAttenudated[i] &&
+                      (shadowRays.getColor(end).luminance() > cutoff))
+                  end++;
+                // Change all the origins and reset the hits?
+                RayPacket subPacket(shadowRays, i, end);
+                subPacket.setDepth(currentDepth);
+                subPacket.computeHitPositions();
+                subPacket.resetHits();
+                for(int s_index = subPacket.begin(); s_index < 
subPacket.end();
+                    ++s_index) {
+                  subPacket.setOrigin(s_index, 
subPacket.getHitPosition(s_index));
+                }
+                context.scene->getObject()->intersect(context, subPacket);
+              } else {
+                // The ray has reached its saturation point, masked it off
+                rayAttenudated[i] = false;
+                shadowRays.resetHit(i);
+              }
+            }
             i=end;
-          }
-        }
-
+          } // end foreach (shadowRay)
+        } // if (anyHit)
+      } while (raysActive && (currentDepth < maxDepth));
+      for(int i = shadowRays.begin(); i < shadowRays.end(); ++i) {
+        if (rayAttenudated[i])
+          shadowRays.resetHit(i);
       }
     }
   }

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Mon Apr  9 16:58:40 2007
@@ -221,9 +221,16 @@
     int end() const {
       return rayEnd;
     }
+    // This function is dangerous since most RayPacket loops go from
+    // rayBegin to rayEnd instead of 0 to rayEnd.  Consider not using
+    // it.
     void resize(int newSize)
     {
       rayBegin = 0; rayEnd = newSize;
+    }
+    void resize(int rayBegin_in, int rayEnd_in)
+    {
+      rayBegin = rayBegin_in; rayEnd = rayEnd_in;
     }
 
 

Modified: trunk/Model/Materials/Dielectric.cc
==============================================================================
--- trunk/Model/Materials/Dielectric.cc (original)
+++ trunk/Model/Materials/Dielectric.cc Mon Apr  9 16:58:40 2007
@@ -38,6 +38,7 @@
 #include <Interface/Scene.h>
 #include <Interface/ShadowAlgorithm.h>
 #include <Core/Math/Expon.h>
+#include <Core/Color/ColorSpace_fancy.h>
 
 using namespace Manta;
 using namespace SCIRun;
@@ -140,6 +141,7 @@
       Real r0 = (n_values.data[i] - nt_values.data[i]) / (n_values.data[i] + 
nt_values.data[i]);
       r0 *= r0;
       Real R = r0*(1-k) + k;
+      if (rays.getFlag(RayPacket::DebugPacket)) cerr << "r0 = "<<r0<<"\n";
 
       // Possibly create refraction ray
       refr_attenuation[num_refr] = beers_color * (1-R);
@@ -186,4 +188,19 @@
 
   for(int i = rays.begin(); i < rays.end(); i++)
     rays.setColor(i, results[i]);
+}
+
+void Dielectric::attenuateShadows(const RenderContext& context,
+                                  RayPacket& shadowRays) const
+{
+  // This is basically a hack for now.
+  Packet<Color> sigma_a_values;
+  sigma_a->mapValues(sigma_a_values, context, shadowRays);
+
+  for(int i = shadowRays.begin(); i < shadowRays.end(); ++i){
+    if (shadowRays.getFlag(RayPacket::DebugPacket)) cerr << i<<":shadowColor 
* sigma_a_values = "<<shadowRays.getColor(i).toString()<<" * 
"<<sigma_a_values.get(i).toString()<<" = ";
+    shadowRays.setColor(i, shadowRays.getColor(i) * sigma_a_values.get(i));
+    //    shadowRays.setColor(i, Color::black());
+    if (shadowRays.getFlag(RayPacket::DebugPacket)) cerr << 
shadowRays.getColor(i).toString()<<"\n";
+  }
 }

Modified: trunk/Model/Materials/Dielectric.h
==============================================================================
--- trunk/Model/Materials/Dielectric.h  (original)
+++ trunk/Model/Materials/Dielectric.h  Mon Apr  9 16:58:40 2007
@@ -56,6 +56,8 @@
     ~Dielectric();
 
     void shade(const RenderContext& context, RayPacket& rays) const;
+    virtual void attenuateShadows(const RenderContext& context,
+                                  RayPacket& shadowRays) const;
                        
   private:
     const Texture<Real>* n;

Modified: trunk/Model/Materials/Lambertian.cc
==============================================================================
--- trunk/Model/Materials/Lambertian.cc (original)
+++ trunk/Model/Materials/Lambertian.cc Mon Apr  9 16:58:40 2007
@@ -54,6 +54,11 @@
 
 void Lambertian::shade(const RenderContext& context, RayPacket& rays) const
 {
+  int debugFlag = rays.getAllFlags() & RayPacket::DebugPacket;
+  if (debugFlag) {
+    cerr << "Lambertian::shade called\n";
+    //    cerr << SCIRun::getStackTrace();
+  }
   // Shade a bunch of rays.  We know that they all have the same intersected
   // object and are all of the same material
 
@@ -74,7 +79,7 @@
   ShadowAlgorithm::StateBuffer shadowState;
   do {
     RayPacketData shadowData;
-    RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0, 
rays.getDepth(), 0);
+    RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0, 
rays.getDepth(), debugFlag);
 
     // Call the shadowalgorithm(sa) to generate shadow rays.  We may not be
     // able to compute all of them, so we pass along a buffer for the sa

Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc      (original)
+++ trunk/Model/Materials/Phong.cc      Mon Apr  9 16:58:40 2007
@@ -115,7 +115,8 @@
 
 void Phong::shade(const RenderContext& context, RayPacket& rays) const
 {
-  if (rays.getFlag(RayPacket::DebugPacket)) {
+  int debugFlag = rays.getAllFlags() & RayPacket::DebugPacket;
+  if (debugFlag) {
     cerr << "Phong::shade called\n";
     //    cerr << SCIRun::getStackTrace();
   }
@@ -147,7 +148,7 @@
   ShadowAlgorithm::StateBuffer shadowState;
   do {
     RayPacketData shadowData;
-    RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0, 
rays.getDepth(), 0);
+    RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0, 
rays.getDepth(), debugFlag);
 
     // Call the shadowalgorithm(sa) to generate shadow rays.  We may not be
     // able to compute all of them, so we pass along a buffer for the sa
@@ -427,8 +428,10 @@
 
     rays.computeHitPositions();
     RayPacketData rdata;
-    RayPacket refl_rays(rdata, RayPacket::UnknownShape, rays.begin(), 
rays.end(),
-                        rays.getDepth()+1, RayPacket::NormalizedDirections);
+    RayPacket refl_rays(rdata, RayPacket::UnknownShape,
+                        rays.begin(), rays.end(),
+                        rays.getDepth()+1,
+                        RayPacket::NormalizedDirections | debugFlag);
 #ifdef MANTA_SSE
     int b = (rays.rayBegin + 3) & (~3);
     int e = rays.rayEnd & (~3);

Modified: trunk/SwigInterface/manta.i
==============================================================================
--- trunk/SwigInterface/manta.i (original)
+++ trunk/SwigInterface/manta.i Mon Apr  9 16:58:40 2007
@@ -168,7 +168,8 @@
 /////////////////////////////////////////////////////
 // Materials and Primitivs
 %{
-//#include <Model/Materials/LitMaterial.h>
+#include <Model/Materials/OpaqueShadower.h>
+#include <Model/Materials/LitMaterial.h>
 #include <Model/Materials/Phong.h>
 #include <Model/Materials/Lambertian.h>
 #include <Model/Materials/MetalMaterial.h>
@@ -186,7 +187,8 @@
 #include <Model/Groups/RealisticBvh.h>
 %}
 
-//%include <Model/Materials/LitMaterial.h>
+%include <Model/Materials/OpaqueShadower.h>
+%include <Model/Materials/LitMaterial.h>
 %include <Model/Materials/Phong.h>
 %include <Model/Materials/Lambertian.h>
 %include <Model/Materials/MetalMaterial.h>
@@ -262,7 +264,35 @@
 
 %include <Engine/Control/RTRT.h>
 
+////////////////////////////////////////////////
+// Pixel Samplers
+%{
+#include <Engine/PixelSamplers/JitterSampler.h>
+#include <Engine/PixelSamplers/SingleSampler.h>
+#include <Engine/PixelSamplers/TimeViewSampler.h>
+%}
 
+%include <Engine/PixelSamplers/JitterSampler.h>
+%include <Engine/PixelSamplers/SingleSampler.h>
+%include <Engine/PixelSamplers/TimeViewSampler.h>
+
+namespace Manta {
+  %extend JitterSampler {
+    static JitterSampler* fromPixelSampler(PixelSampler* parent) {
+      return dynamic_cast<Manta::JitterSampler*>(parent);
+    }
+  };
+  %extend SingleSampler {
+    static SingleSampler* fromPixelSampler(PixelSampler* parent) {
+      return dynamic_cast<Manta::SingleSampler*>(parent);
+    }
+  };
+  %extend TimeViewSampler {
+    static TimeViewSampler* fromPixelSampler(PixelSampler* parent) {
+      return dynamic_cast<Manta::TimeViewSampler*>(parent);
+    }
+  };
+} // end namespace Manta
 
 ////////////////////////////////////////////////
 // Thread stuff

Modified: trunk/SwigInterface/mantainterface.i
==============================================================================
--- trunk/SwigInterface/mantainterface.i        (original)
+++ trunk/SwigInterface/mantainterface.i        Mon Apr  9 16:58:40 2007
@@ -393,7 +393,13 @@
 // The Array Containers
 
 ///////////////////////////////////////////////////////
-// Engine Control
+// Engine Components
+
+%{
+#include <Interface/PixelSampler.h>
+%}
+
+%include <Interface/PixelSampler.h>
 
 ////////////////////////////////////////////////
 // Thread stuff

Modified: trunk/SwigInterface/runmanta.py
==============================================================================
--- trunk/SwigInterface/runmanta.py     (original)
+++ trunk/SwigInterface/runmanta.py     Mon Apr  9 16:58:40 2007
@@ -156,12 +156,70 @@
     #
     return scene
 
+def createTransparentShadowScene():
+    scene = manta_new(Scene())
+    scene.setBackground(manta_new(ConstantBackground(Color(RGBColor(0.5, 
0.8, 0.9)))))
+    #
+    # world will be added to the scene
+    world = manta_new(Group())
+    # Collection of objects that will be put in the BVH.
+    objs = Array1_ObjectP()
+    #
+    checker1 = manta_new(CheckerTexture_Color(Color(RGBColor(.6,.6,.6)),
+                                              Color(RGBColor(0,0,0)),
+                                              Vector(1,0,0),
+                                              Vector(0,1,0)))
+    groundmatl = manta_new(Lambertian(checker1))
+    print groundmatl
+    world.add(manta_new(Plane(groundmatl,
+                              Vector(0,0,1), Vector(0,0,2.5))))
+    #
+    lenscale = 2.5
+    glass = Color(RGBColor(pow(0.80, lenscale), pow(0.93, lenscale), 
pow(0.87, lenscale)))
+    transp_matl = manta_new(Dielectric(1, 1.01, glass))
+    print transp_matl
+    objs.add(manta_new(Cube(transp_matl,
+                            Vector(-5, -2, 2.95 ),
+                            Vector(-1, 2, 3.05))))
+#     objs.add(manta_new(Cube(manta_new(Dielectric(1.1, 1, glass)),
+#                             Vector(-5, -2, 2.95 ),
+#                             Vector(-1, 2, 3.05))))
+
+    ringmatl = manta_new(Lambertian(Color(RGBColor(.9, .3, .2))))
+    print ringmatl
+    r = .30
+    inner_radius = r*0.5
+    center = Vector(-6, 0, 3.5+r)
+    offset = Vector(2.25*r, 0, 0)
+    for i in range(9):
+        objs.add(manta_new(Ring(ringmatl,
+                                center+offset*i,
+                                Vector(0, 0, 1),
+                                inner_radius, r-inner_radius)))
+
+    # Create a BVH
+    world.add(manta_new(RealisticBvh(objs.get_objs(), objs.size())))
+    scene.setObject(world)
+    #
+    lights = manta_new(LightSet())
+    lights.add(manta_new(PointLight(Vector(20, 30, 100), 
Color(RGBColor(.9,.9,.9)))))
+#    lights.add(manta_new(PointLight(Vector(-40, -30, 50), 
Color(RGBColor(.3,.1,.1)))))
+    lights.setAmbientLight(manta_new(ConstantAmbient(Color(RGBColor(.4, .4, 
.4)))))
+    #
+    scene.setLights(lights)
+    scene.getRenderParameters().maxDepth = 25
+    scene.getRenderParameters().importanceCutoff = 0.01
+    #
+    return scene
+
 def setupDefaultEngine(numworkers):
     print "Using " + str(numworkers) + " rendering threads."
     engine = createManta()
 
     global factory
-    factory = Factory( engine )
+    # For whatever reason the compiler on my laptop blows up garbage
+    # collecting this thing, so I'm not going to delete it.
+    factory = manta_new(Factory( engine ))
     
     engine.changeNumWorkers(numworkers)
     factory.selectImageType("rgba8")
@@ -170,7 +228,8 @@
     factory.selectPixelSampler("singlesample")
     #factory.selectPixelSampler("jittersample(-numberOfSamples 4)")
     factory.selectRenderer("raytracer")
-    factory.selectShadowAlgorithm("hard")
+    factory.selectShadowAlgorithm("hard(-attenuate)")
+    #factory.selectShadowAlgorithm("hard")
     #
     return engine
 
@@ -193,19 +252,20 @@
     engine.createChannel("null", camera, False, xres, yres)
 
 
-engine = setupDefaultEngine(2)
+engine = setupDefaultEngine(1)
 
-defaultCamera = factory.createCamera("pinhole(-eye 3 3 2 -lookat 0 0 0.3 -up 
0 0 1 -fov 60)")
+#defaultCamera = factory.createCamera("pinhole(-eye 3 3 2 -lookat 0 0 0.3 
-up 0 0 1 -fov 60)")
 #defaultCamera = factory.createCamera("pinhole(-eye 8 -18 8.5 -lookat -4.7 
2.5 2.5 -up 0 0 1 -fov 15)")
-#defaultCamera = factory.createCamera("pinhole(-eye 8.3 -18 7 -lookat -4.7 
2.5 3 -up 0 0 1 -fov 15)")
+defaultCamera = factory.createCamera("pinhole(-eye 8.3 -18 7 -lookat -4.7 
2.5 3 -up 0 0 1 -fov 15)")
 
 addXInterface(engine, defaultCamera, 512, 512)
 #addNullInterface(engine, defaultCamera, 512, 512)
 
 # scene = createDefaultScene()
-scene = createDefaultScenePython()
+#scene = createDefaultScenePython()
 #scene = createDielectricTestScene()
 #scene = createProg4TestScene()
+scene = createTransparentShadowScene()
 engine.setScene(scene)
 
 




  • [MANTA] r1325 - in trunk: Engine/Shadows Interface Model/Materials SwigInterface, bigler, 04/09/2007

Archive powered by MHonArc 2.6.16.

Top of page