Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1790 - in trunk: Engine/Control Engine/PixelSamplers Engine/SampleGenerators Interface Model/Materials


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1790 - in trunk: Engine/Control Engine/PixelSamplers Engine/SampleGenerators Interface Model/Materials
  • Date: Thu, 25 Oct 2007 22:02:46 -0600 (MDT)

Author: boulos
Date: Thu Oct 25 22:02:40 2007
New Revision: 1790

Modified:
   trunk/Engine/Control/RTRT.cc
   trunk/Engine/PixelSamplers/JitterSampler.cc
   trunk/Engine/SampleGenerators/ConstantSampleGenerator.cc
   trunk/Engine/SampleGenerators/ConstantSampleGenerator.h
   trunk/Engine/SampleGenerators/Stratified2D.cc
   trunk/Engine/SampleGenerators/Stratified2D.h
   trunk/Engine/SampleGenerators/UniformRandomGenerator.cc
   trunk/Engine/SampleGenerators/UniformRandomGenerator.h
   trunk/Interface/Context.h
   trunk/Interface/RayPacket.h
   trunk/Interface/SampleGenerator.h
   trunk/Model/Materials/Phong.cc
Log:

Interface/Context.h
Engine/Control/RTRT.cc

 Adding SampleGenerator to the SetupContext and updating necessary
 RTRT SetupContext constructors.

Engine/PixelSamplers/JitterSampler.cc

 JitterSampler now "properly" uses the SampleGenerator class and calls
 the various setup methods.

Engine/SampleGenerators/ConstantSampleGenerator.cc
Engine/SampleGenerators/ConstantSampleGenerator.h
Engine/SampleGenerators/Stratified2D.cc
Engine/SampleGenerators/Stratified2D.h
Engine/SampleGenerators/UniformRandomGenerator.cc
Engine/SampleGenerators/UniformRandomGenerator.h

 Extending the SampleGenerators to provide the setupChildPacket
 function (called whenever a secondary packet of rays is spawned,
 before the trace call)

 Numerous bug fixes in Stratified2D SampleGenerator.

 Adding shuffling of samples to the Stratified2D SampleGenerator a la
 galileo's implementation.

Interface/RayPacket.h

 A RayPacket now only has a sample_depth per packet... We'll see how
 this goes.

Interface/SampleGenerator.h

 Added setupChildPacket.

Model/Materials/Phong.cc

 Call setupChildPacket before tracing reflection rays.


Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Thu Oct 25 22:02:40 2007
@@ -175,7 +175,7 @@
 
   //currentSampleGenerator = new ConstantSampleGenerator(0.f);
   currentSampleGenerator = new UniformRandomGenerator();
-  //currentSampleGenerator = new Stratified2D(16);
+  //currentSampleGenerator = new Stratified2D(64);
 }
 
 RTRT::~RTRT()
@@ -1041,7 +1041,7 @@
   int numChannels = static_cast<int>(channels.size());
   SetupContext globalcontext(this, numChannels, proc, numProcs,
                              currentLoadBalancer, currentPixelSampler,
-                             currentRenderer);
+                             currentRenderer, currentSampleGenerator);
   for(vector<IdleMode*>::iterator iter = currentIdleModes.begin();
       iter != currentIdleModes.end(); iter++){
     IdleMode* im = *iter;
@@ -1110,7 +1110,7 @@
   // Create a setup context.
   SetupContext globalcontext(this, numChannels, 0, numProcs,
                              currentLoadBalancer, currentPixelSampler,
-                             currentRenderer);
+                             currentRenderer, currentSampleGenerator);
 
   // Setup the image traverser.
   currentImageTraverser->setupBegin(globalcontext, numChannels);
@@ -1132,6 +1132,7 @@
                          currentLoadBalancer,
                          currentPixelSampler,
                          currentRenderer,
+                         currentSampleGenerator,
                          thread_storage );
 
     // Setup the channel iteratively, until context.isChanged() is false.

Modified: trunk/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.cc Thu Oct 25 22:02:40 2007
@@ -6,7 +6,7 @@
 #include <Interface/Fragment.h>
 #include <Interface/RayPacket.h>
 #include <Interface/Renderer.h>
-
+#include <Interface/SampleGenerator.h>
 #include <Core/Math/CheapRNG.h>
 #include <Core/Math/MiscMath.h>
 
@@ -58,6 +58,7 @@
   if (random) delete[] random;
   random = new MT_RNG[context.numProcs];
   context.renderer->setupBegin(context, numChannels);
+  context.sample_generator->setupBegin(context, numChannels);
 }
 
 void JitterSampler::setupDisplayChannel(SetupContext& context)
@@ -73,11 +74,13 @@
   ci.yoffset = (-ci.yres+1)*(Real)0.5*ci.yscale;
 
   context.renderer->setupDisplayChannel(context);
+  context.sample_generator->setupDisplayChannel(context);
 }
 
 void JitterSampler::setupFrame(const RenderContext& context)
 {
   context.renderer->setupFrame(context);
+  context.sample_generator->setupFrame(context);
 }
 
 // The fragment, sample_color, and sample_color_size paramters are
@@ -194,11 +197,13 @@
           px = (fx+x_sample)*ci.xscale+ci.xoffset;
           py = (fy+y_sample)*ci.yscale+ci.yoffset;
           rays.setPixel(sample_count, 0, px, py);
+          rays.data->sample_id[sample_count] = xs * ny + ys;
           sample_count++;
 
           if (sample_count == RayPacket::MaxSize) {
             // Filled up the ray packet, so send them off!
             rays.resize(sample_count);
+            context.sample_generator->setupPacket(context, rays);
             context.renderer->traceEyeRays(context, rays);
 
             computeAverages(fragment, rays,
@@ -228,6 +233,7 @@
   // Pick up any stragling samples
   if (sample_count > 0) {
     rays.resize(sample_count);
+    context.sample_generator->setupPacket(context, rays);
     context.renderer->traceEyeRays(context, rays);
 
     computeAverages(fragment, rays,

Modified: trunk/Engine/SampleGenerators/ConstantSampleGenerator.cc
==============================================================================
--- trunk/Engine/SampleGenerators/ConstantSampleGenerator.cc    (original)
+++ trunk/Engine/SampleGenerators/ConstantSampleGenerator.cc    Thu Oct 25 
22:02:40 2007
@@ -21,6 +21,9 @@
 void ConstantSampleGenerator::setupPacket(const RenderContext& context, 
RayPacket& rays) {
 }
 
+void ConstantSampleGenerator::setupChildPacket(const RenderContext& context, 
RayPacket& parent, RayPacket& child) {
+}
+
 void ConstantSampleGenerator::nextSeeds(const RenderContext& context, 
Packet<float>& results, RayPacket& rays) {
 #ifdef MANTA_SSE
   int b = (rays.rayBegin + 3) & (~3);

Modified: trunk/Engine/SampleGenerators/ConstantSampleGenerator.h
==============================================================================
--- trunk/Engine/SampleGenerators/ConstantSampleGenerator.h     (original)
+++ trunk/Engine/SampleGenerators/ConstantSampleGenerator.h     Thu Oct 25 
22:02:40 2007
@@ -14,7 +14,7 @@
     virtual void setupFrame(const RenderContext& context);
 
     virtual void setupPacket(const RenderContext& context, RayPacket& rays);
-
+    virtual void setupChildPacket(const RenderContext& context, RayPacket& 
parent, RayPacket& child);
     virtual void nextSeeds(const RenderContext& context, Packet<float>& 
results, RayPacket& rays);
     virtual void nextSeeds(const RenderContext& context, Packet<double>& 
results, RayPacket& rays);
 

Modified: trunk/Engine/SampleGenerators/Stratified2D.cc
==============================================================================
--- trunk/Engine/SampleGenerators/Stratified2D.cc       (original)
+++ trunk/Engine/SampleGenerators/Stratified2D.cc       Thu Oct 25 22:02:40 
2007
@@ -1,3 +1,4 @@
+#include <Core/Util/Preprocessor.h>
 #include <Engine/SampleGenerators/Stratified2D.h>
 #include <Interface/Context.h>
 #include <Interface/Scene.h>
@@ -7,6 +8,7 @@
 #include <SCIRun/Core/Math/Expon.h>
 #include <SCIRun/Core/Exceptions/InternalError.h>
 
+#include <iostream>
 using namespace Manta;
 using SCIRun::Sqrt;
 
@@ -63,16 +65,39 @@
 void Stratified2D::buildSamples(RandomNumberGenerator* rng,
                                 unsigned int thread_id,
                                 unsigned int depth) {
-  float* sample_buf = &(thread_samples[thread_id][spp * depth]);
-  if (max_depth - depth > 1)
-    build2DSamples(rng, sample_buf);
-  else
+  if (max_depth - depth > 1) {
+    // NOTE(boulos): We only want to generate the even cases
+    if (depth % 2 == 0) {
+      float* x_samples = &(thread_samples[thread_id][spp * depth]);
+      float* y_samples = &(thread_samples[thread_id][spp * (depth+1)]);
+      build2DSamples(rng, x_samples, y_samples);
+    }
+  } else {
+    float* sample_buf = &(thread_samples[thread_id][spp * depth]);
     build1DSamples(rng, sample_buf);
+  }
 }
 
 
+void Shuffle2DSamples(float* x_samples,
+                      float* y_samples,
+                      unsigned int num_samples,
+                      RandomNumberGenerator* rng) {
+  for (int i = static_cast<int>(num_samples) - 2; i >= 0; i--) {
+    int target = static_cast<int>(rng->nextFloat() * i);
+    float tmp_x = x_samples[i+1];
+    float tmp_y = y_samples[i+1];
+    x_samples[i+1] = x_samples[target];
+    y_samples[i+1] = y_samples[target];
+
+    x_samples[target] = tmp_x;
+    y_samples[target] = tmp_y;
+  }
+}
+
 void Stratified2D::build2DSamples(RandomNumberGenerator* rng,
-                                  float* sample_buf) {
+                                  float* x_samples,
+                                  float* y_samples) {
   unsigned int index = 0;
   float ii = 0.f;
   float jj = 0.f;
@@ -82,18 +107,32 @@
       float x = (ii + rng->nextFloat()) * inv_sqrt_spp;
       float y = (jj + rng->nextFloat()) * inv_sqrt_spp;
       jj += 1.f;
-      sample_buf[index + 0] = x;
-      sample_buf[index + 1] = y;
+      x_samples[index + j] = x;
+      y_samples[index + j] = y;
     }
     ii += 1.f;
     index += sqrt_spp;
   }
+  Shuffle2DSamples(x_samples, y_samples, spp, rng);
 }
 
+void Shuffle1DSamples(float* samples,
+                      unsigned int num_samples,
+                      RandomNumberGenerator* rng) {
+  for (int i = static_cast<int>(num_samples) - 2; i >= 0; i--) {
+    int target = static_cast<int>(rng->nextFloat() * i);
+    float tmp = samples[i+1];
+    samples[i+1] = samples[target];
+    samples[target] = tmp;
+  }
+}
+
+
 void Stratified2D::build1DSamples(RandomNumberGenerator* rng, float* 
sample_buf) {
   for (unsigned int i = 0; i < spp; i++) {
     sample_buf[i] = (i + rng->nextFloat()) * inv_spp;
   }
+  Shuffle1DSamples(sample_buf, spp, rng);
 }
 
 void Stratified2D::setupDisplayChannel(SetupContext& context) {
@@ -116,32 +155,38 @@
 }
 
 void Stratified2D::setupPacket(const RenderContext& context, RayPacket& 
rays) {
-  for (int i = rays.begin(); i < rays.end(); i++) {
-    rays.data->sample_depth[i] = 0;
-  }
+  rays.sample_depth = 0;
   buildSamplesAllDepths(context.rng, context.proc);
 }
 
+void Stratified2D::setupChildPacket(const RenderContext& context, RayPacket& 
parent, RayPacket& child) {
+  child.sample_depth = parent.sample_depth;
+  for (int i = parent.begin(); i < parent.end(); i++) {
+    child.data->sample_id[i] = parent.data->sample_id[i];
+  }
+}
+
 void Stratified2D::nextSeeds(const RenderContext& context, Packet<float>& 
results, RayPacket& rays) {
-  for (int i = rays.begin(); i < rays.end(); i++) {
-    if (static_cast<unsigned int>(rays.data->sample_depth[i]) < max_depth) {
-      float* sample_buf = &(thread_samples[context.proc][spp * 
rays.data->sample_depth[i]]);
+  if (rays.sample_depth < max_depth) {
+    float* sample_buf = &(thread_samples[context.proc][spp * 
rays.sample_depth]);
+    for (int i = rays.begin(); i < rays.end(); i++) {
       results.set(i, sample_buf[rays.data->sample_id[i]]);
-    } else {
-      results.set(i, context.rng->nextFloat());
     }
-    rays.data->sample_depth[i]++;
+  } else {
+    context.rng->nextPacket(results, rays);
   }
+  rays.sample_depth++;
 }
 
 void Stratified2D::nextSeeds(const RenderContext& context, Packet<double>& 
results, RayPacket& rays) {
-  for (int i = rays.begin(); i < rays.end(); i++) {
-    if (static_cast<unsigned int>(rays.data->sample_depth[i]) < max_depth) {
-      float* sample_buf = &(thread_samples[context.proc][spp * 
rays.data->sample_depth[i]]);
+  if (rays.sample_depth < max_depth) {
+    float* sample_buf = &(thread_samples[context.proc][spp * 
rays.sample_depth]);
+    for (int i = rays.begin(); i < rays.end(); i++) {
+
       results.set(i, 
static_cast<double>(sample_buf[rays.data->sample_id[i]]));
-    } else {
-      results.set(i, context.rng->nextDouble());
     }
-    rays.data->sample_depth[i]++;
+  } else {
+    context.rng->nextPacket(results, rays);
   }
+  rays.sample_depth++;
 }

Modified: trunk/Engine/SampleGenerators/Stratified2D.h
==============================================================================
--- trunk/Engine/SampleGenerators/Stratified2D.h        (original)
+++ trunk/Engine/SampleGenerators/Stratified2D.h        Thu Oct 25 22:02:40 
2007
@@ -21,7 +21,8 @@
                       unsigned int depth);
 
     void build2DSamples(RandomNumberGenerator* rng,
-                        float* sample_buf);
+                        float* x_samples,
+                        float* y_samples);
 
     void build1DSamples(RandomNumberGenerator* rng,
                         float* sample_buf);
@@ -31,6 +32,7 @@
     virtual void setupFrame(const RenderContext& context);
 
     virtual void setupPacket(const RenderContext& context, RayPacket& rays);
+    virtual void setupChildPacket(const RenderContext& context, RayPacket& 
parent, RayPacket& child);
 
     virtual void nextSeeds(const RenderContext& context, Packet<float>& 
results, RayPacket& rays);
     virtual void nextSeeds(const RenderContext& context, Packet<double>& 
results, RayPacket& rays);

Modified: trunk/Engine/SampleGenerators/UniformRandomGenerator.cc
==============================================================================
--- trunk/Engine/SampleGenerators/UniformRandomGenerator.cc     (original)
+++ trunk/Engine/SampleGenerators/UniformRandomGenerator.cc     Thu Oct 25 
22:02:40 2007
@@ -25,6 +25,9 @@
 void UniformRandomGenerator::setupPacket(const RenderContext& context, 
RayPacket& rays) {
 }
 
+void UniformRandomGenerator::setupChildPacket(const RenderContext& context, 
RayPacket& parent, RayPacket& child) {
+}
+
 void UniformRandomGenerator::nextSeeds(const RenderContext& context, 
Packet<float>& results, RayPacket& rays) {
   context.rng->nextPacket(results, rays);
 }

Modified: trunk/Engine/SampleGenerators/UniformRandomGenerator.h
==============================================================================
--- trunk/Engine/SampleGenerators/UniformRandomGenerator.h      (original)
+++ trunk/Engine/SampleGenerators/UniformRandomGenerator.h      Thu Oct 25 
22:02:40 2007
@@ -14,6 +14,7 @@
     virtual void setupFrame(const RenderContext& context);
 
     virtual void setupPacket(const RenderContext& context, RayPacket& rays);
+    virtual void setupChildPacket(const RenderContext& context, RayPacket& 
parent, RayPacket& child);
 
     virtual void nextSeeds(const RenderContext& context, Packet<float>& 
results, RayPacket& rays);
     virtual void nextSeeds(const RenderContext& context, Packet<double>& 
results, RayPacket& rays);

Modified: trunk/Interface/Context.h
==============================================================================
--- trunk/Interface/Context.h   (original)
+++ trunk/Interface/Context.h   Thu Oct 25 22:02:40 2007
@@ -52,13 +52,14 @@
                  bool stereo, int xres, int yres,
                  LoadBalancer* loadBalancer,  PixelSampler* pixelSampler,
                  Renderer* renderer,
-                 ThreadStorage *storage_allocator_ )
-
+                 SampleGenerator* sample_gen,
+                 ThreadStorage *storage_allocator_)
       : rtrt_int(rtrt_int),
         channelIndex(channelIndex), numChannels(numChannels),
         proc(proc), numProcs(numProcs),
         loadBalancer(loadBalancer), pixelSampler(pixelSampler),
-        renderer(renderer), storage_allocator( storage_allocator_ ),
+        renderer(renderer), sample_generator(sample_gen),
+        storage_allocator( storage_allocator_ ),
         stereo(stereo), xres(xres), yres(yres)
     {
       init();
@@ -66,11 +67,13 @@
     SetupContext(MantaInterface* rtrt_int, int numChannels,
                  int proc, int numProcs,
                  LoadBalancer* loadBalancer,  PixelSampler* pixelSampler,
-                 Renderer* renderer)
+                 Renderer* renderer,
+                 SampleGenerator* sample_gen)
       : rtrt_int(rtrt_int), channelIndex(-1), numChannels(numChannels),
         proc(proc), numProcs(numProcs),
         loadBalancer(loadBalancer), pixelSampler(pixelSampler),
         renderer(renderer),
+        sample_generator(sample_gen),
         stereo(false), xres(-1), yres(-1)
     {
       init();
@@ -89,8 +92,9 @@
     LoadBalancer* loadBalancer;
     PixelSampler* pixelSampler;
     Renderer* renderer;
+    SampleGenerator* sample_generator;
+    ThreadStorage* storage_allocator;
 
-    ThreadStorage *storage_allocator;
     mutable XWindow* masterWindow;
 
     void changeResolution(bool new_stereo, int new_xres, int new_yres) {

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Thu Oct 25 22:02:40 2007
@@ -111,7 +111,6 @@
     // Int-based arrays
     int whichEye[MaxSize];
     int sample_id[MaxSize];
-    int sample_depth[MaxSize];
     MANTA_ALIGN(16) int signs[3][MaxSize]; // 1=negative, 0=zero, positive
 
     // Scratchpad
@@ -174,7 +173,8 @@
     // Create a subset of another raypacket
     RayPacket(RayPacket& parent, int rayBegin, int rayEnd)
     : data(parent.data), rayBegin(rayBegin), rayEnd(rayEnd),
-      depth(parent.depth), flags(parent.flags)
+      depth(parent.depth), sample_depth(parent.sample_depth),
+      flags(parent.flags)
     {
       shape = parent.shape;
       if(shape == SquarePacket){
@@ -218,6 +218,14 @@
       depth=new_depth;
     }
 
+    // Sample depth (number of samples taken so far)
+    unsigned int getSampleDepth() const {
+      return sample_depth;
+    }
+    void setSampleDepth(unsigned int new_depth) {
+      sample_depth = new_depth;
+    }
+
     // Raypacket iteration
     int begin() const {
       return rayBegin;
@@ -850,6 +858,7 @@
     int rayBegin;
     int rayEnd;
     int depth;
+    unsigned int sample_depth;
     int flags;
   };
 

Modified: trunk/Interface/SampleGenerator.h
==============================================================================
--- trunk/Interface/SampleGenerator.h   (original)
+++ trunk/Interface/SampleGenerator.h   Thu Oct 25 22:02:40 2007
@@ -30,6 +30,11 @@
     // allow the SampleGenerator to setup whatever state it needs
     // (e.g. sample_id within a Hammersley pattern)
     virtual void setupPacket(const RenderContext& context, RayPacket& rays) 
= 0;
+    // Whenever a new RayPacket is created as a child of a parent
+    // RayPacket, let the SampleGenerator take a shot at setting up
+    // the child. For SampleGenerators that care to mess with
+    // sample_depth, etc, this is a good opportunity to do so.
+    virtual void setupChildPacket(const RenderContext& context, RayPacket& 
parent, RayPacket& child) = 0;
 
     // Grab a set of random seeds (float and double versions)
     virtual void nextSeeds(const RenderContext& context, Packet<float>& 
results, RayPacket& rays) = 0;

Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc      (original)
+++ trunk/Model/Materials/Phong.cc      Thu Oct 25 22:02:40 2007
@@ -40,6 +40,7 @@
 #include <Interface/Primitive.h>
 #include <Interface/RayPacket.h>
 #include <Interface/Renderer.h>
+#include <Interface/SampleGenerator.h>
 #include <Interface/Scene.h>
 #include <Interface/ShadowAlgorithm.h>
 #include <Model/Textures/Constant.h>
@@ -491,7 +492,7 @@
       refl_rays.setImportance(i, rays.getImportance(i) * refl.data[i]);
     }
 #endif // ifdef MANTA_SSE
-
+    context.sample_generator->setupChildPacket(context, rays, refl_rays);
     refl_rays.resetHits();
     // Look for runs where the ray importance is significant
     Real cutoff = context.scene->getRenderParameters().importanceCutoff;




  • [Manta] r1790 - in trunk: Engine/Control Engine/PixelSamplers Engine/SampleGenerators Interface Model/Materials, boulos, 10/26/2007

Archive powered by MHonArc 2.6.16.

Top of page