Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1784 - in trunk: Engine Engine/Control Engine/PixelSamplers Engine/SampleGenerators Interface


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1784 - in trunk: Engine Engine/Control Engine/PixelSamplers Engine/SampleGenerators Interface
  • Date: Thu, 18 Oct 2007 02:35:32 -0600 (MDT)

Author: boulos
Date: Thu Oct 18 02:35:25 2007
New Revision: 1784

Added:
   trunk/Engine/SampleGenerators/
   trunk/Engine/SampleGenerators/CMakeLists.txt
   trunk/Engine/SampleGenerators/ConstantSampleGenerator.cc
   trunk/Engine/SampleGenerators/ConstantSampleGenerator.h
   trunk/Interface/SampleGenerator.h
Modified:
   trunk/Engine/CMakeLists.txt
   trunk/Engine/Control/RTRT.cc
   trunk/Engine/Control/RTRT.h
   trunk/Engine/PixelSamplers/SingleSampler.cc
   trunk/Interface/CMakeLists.txt
   trunk/Interface/Context.h
   trunk/Interface/MantaInterface.h
   trunk/Interface/RayPacket.h
Log:

Interface/SampleGenerator.h

 Adding a new SampleGenerator interface to support multidimensional
 sampling.

Interface/CMakeLists.txt
Interface/Context.h
Interface/MantaInterface.h

 Adding a SampleGenerator into the RenderContext and allowing the
 MantaInterface to get/set it.

Interface/RayPacket.h

 A RayPacket currently stores a sample_id and sample_depth as well as
 these seem to be common values across multidimensional sampling
 schemes. Not all schemes use them, but they're useful to have. 

Engine/CMakeLists.txt
Engine/Control/RTRT.cc
Engine/Control/RTRT.h

 Setting RTRT.cc to have a SampleGenerator and to default it to the
 new ConstantSampleGenerator.

Engine/PixelSamplers/SingleSampler.cc

 Updating the SingleSampler to fill in the sample_id field with
 0. More PixelSamplers will be updated in the future, I just want to
 get this committed first.

Engine/SampleGenerators
Engine/SampleGenerators/CMakeLists.txt
Engine/SampleGenerators/ConstantSampleGenerator.cc
Engine/SampleGenerators/ConstantSampleGenerator.h

 Adding the first multidimensional sample generator that simply
 returns the same number regardless of sample_id or sample_depth. It's
 even got an SSE version for the float case ;)


Modified: trunk/Engine/CMakeLists.txt
==============================================================================
--- trunk/Engine/CMakeLists.txt (original)
+++ trunk/Engine/CMakeLists.txt Thu Oct 18 02:35:25 2007
@@ -6,6 +6,7 @@
 INCLUDE (LoadBalancers/CMakeLists.txt)
 INCLUDE (PixelSamplers/CMakeLists.txt)
 INCLUDE (Renderers/CMakeLists.txt)
+INCLUDE (SampleGenerators/CMakeLists.txt)
 INCLUDE (Shadows/CMakeLists.txt)
 # INCLUDE (Animators/CMakeLists.txt)
 
@@ -16,6 +17,7 @@
              ${Manta_ImageTraversers_SRCS}
              ${Manta_LoadBalancers_SRCS}
              ${Manta_PixelSamplers_SRCS}
+            ${Manta_SampleGenerators_SRCS}
              ${Manta_Renderers_SRCS}
              ${Manta_Shadows_SRCS}
 #             ${Manta_Animators_SRCS}

Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Thu Oct 18 02:35:25 2007
@@ -44,6 +44,7 @@
 #include <Interface/Object.h>
 #include <Interface/PixelSampler.h>
 #include <Interface/Renderer.h>
+#include <Interface/SampleGenerator.h>
 #include <Interface/Scene.h>
 #include <Interface/SetupCallback.h>
 #include <Interface/Task.h>
@@ -75,6 +76,11 @@
 #include <Core/Math/CheapRNG.h>
 #include <Core/Math/MT_RNG.h>
 
+// NOTE(boulos): This is temporary to get the code to compile and
+// allow us to discuss the interface (so that I don't have to do all
+// the Factory work just yet)
+#include <Engine/SampleGenerators/ConstantSampleGenerator.h>
+
 #include <queue>
 
 using namespace Manta;
@@ -127,6 +133,7 @@
     currentLoadBalancer(NULL),
     currentPixelSampler(NULL),
     currentRenderer(NULL),
+    currentSampleGenerator(NULL),
     currentShadowAlgorithm(NULL),
     create_image(NULL),
     create_rng(NULL),
@@ -163,6 +170,8 @@
 #else
   create_rng = Callback::create(&MT_RNG::create);
 #endif
+
+  currentSampleGenerator = new ConstantSampleGenerator(0.f);
 }
 
 RTRT::~RTRT()
@@ -652,7 +661,8 @@
                                 currentLoadBalancer, currentPixelSampler,
                                 currentRenderer, currentShadowAlgorithm,
                                 channel->camera, scene, thread_storage,
-                                rngs[proc]);
+                                rngs[proc],
+                                currentSampleGenerator);
         currentImageTraverser->setupFrame(myContext);
       }
     }
@@ -766,7 +776,8 @@
                                   channel->camera,
                                   scene,
                                   thread_storage,
-                                  rngs[proc]);
+                                  rngs[proc],
+                                  currentSampleGenerator);
 
           currentImageTraverser->setupFrame(myContext);
         }
@@ -836,7 +847,8 @@
                                 currentLoadBalancer, currentPixelSampler,
                                 currentRenderer, currentShadowAlgorithm,
                                 channel->camera, scene, thread_storage,
-                                rngs[proc]);
+                                rngs[proc],
+                                currentSampleGenerator);
         currentImageTraverser->renderImage(myContext, image);
       }
     }
@@ -1314,6 +1326,14 @@
   return currentRenderer;
 }
 
+// Sample Generators
+void RTRT::setSampleGenerator(SampleGenerator* sample_gen) {
+  currentSampleGenerator = sample_gen;
+}
+SampleGenerator* RTRT::getSampleGenerator() const {
+  return currentSampleGenerator;
+}
+
 // Idle Mode
 
 RTRT::IdleModeHandle RTRT::addIdleMode(IdleMode* idle_mode)
@@ -1385,7 +1405,8 @@
                                currentLoadBalancer, currentPixelSampler,
                                currentRenderer, currentShadowAlgorithm,
                                channel->camera, scene, thread_storage,
-                               rngs[0]);
+                               rngs[0],
+                               currentSampleGenerator);
 
   // Send this to the renderer.  It will fill in the colors for us.
   currentRenderer->traceEyeRays( render_context, result_rays );

Modified: trunk/Engine/Control/RTRT.h
==============================================================================
--- trunk/Engine/Control/RTRT.h (original)
+++ trunk/Engine/Control/RTRT.h Thu Oct 18 02:35:25 2007
@@ -106,6 +106,10 @@
     virtual void setRenderer( Renderer *renderer_ );
     virtual Renderer* getRenderer() const;
 
+    // Sample Generators
+    virtual void setSampleGenerator(SampleGenerator* sample_gen);
+    virtual SampleGenerator* getSampleGenerator() const;
+
     // Shadow Algorithms
     virtual void setShadowAlgorithm(ShadowAlgorithm* shadows);
     virtual ShadowAlgorithm* getShadowAlgorithm() const;
@@ -253,6 +257,7 @@
     LoadBalancer*    currentLoadBalancer;
     PixelSampler*    currentPixelSampler;
     Renderer*        currentRenderer;
+    SampleGenerator* currentSampleGenerator;
     ShadowAlgorithm* currentShadowAlgorithm;
     vector<IdleMode*> currentIdleModes;
 

Modified: trunk/Engine/PixelSamplers/SingleSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/SingleSampler.cc (original)
+++ trunk/Engine/PixelSamplers/SingleSampler.cc Thu Oct 18 02:35:25 2007
@@ -4,6 +4,7 @@
 #include <Interface/Fragment.h>
 #include <Interface/RayPacket.h>
 #include <Interface/Renderer.h>
+#include <Interface/SampleGenerator.h>
 #include <MantaSSE.h>
 using namespace Manta;
 
@@ -94,6 +95,8 @@
       __m128 vec_xscale4 = _mm_set1_ps(ci.xscale*4);
       for(int i=0;i<e;i+=4){
         _mm_store_si128((__m128i*)&data->whichEye[i], vec_eye);
+        _mm_store_si128((__m128i*)&data->sample_id[i], _mm_set1_epi32(0));
+
         _mm_store_ps(&data->image[0][i], vec_px);
         _mm_store_ps(&data->image[1][i], vec_py);
         vec_px = _mm_add_ps(vec_px, vec_xscale4);
@@ -104,6 +107,7 @@
 #endif
       for(int i=e;i<size;i++){
         rays.setPixel(i, eye, px, py);
+        rays.data->sample_id[i] = 0;
         px += ci.xscale;
       }
     }
@@ -117,6 +121,7 @@
         Real py = (fragment.getY(f+i)+y_splat_offset)*ci.yscale+ci.yoffset;
 
         rays.setPixel(i, fragment.getWhichEye(f+i), px, py);
+        rays.data->sample_id[i] = 0;
       }
     }
     // Otherwise, set each pixel individually.
@@ -130,10 +135,12 @@
       __m128 vec_yscale = _mm_set1_ps(ci.yscale);
       for(int i=0;i<e;i+=4) {
         _mm_store_si128((__m128i*)&data->whichEye[i], 
_mm_load_si128((__m128i*)&fragment.whichEye[f+i]));
+        _mm_store_si128((__m128i*)&data->sample_id[i], _mm_set1_epi32(0));
         __m128 fx = 
_mm_cvtepi32_ps(_mm_load_si128((__m128i*)&fragment.pixel[0][f+i]));
         _mm_store_ps(&data->image[0][i], _mm_add_ps(_mm_mul_ps(fx, 
vec_xscale), vec_xoffset));
         __m128 fy = 
_mm_cvtepi32_ps(_mm_load_si128((__m128i*)&fragment.pixel[1][f+i]));
         _mm_store_ps(&data->image[1][i], _mm_add_ps(_mm_mul_ps(fy, 
vec_yscale), vec_yoffset));
+
       }
 #else
       int e = 0;
@@ -142,10 +149,12 @@
         Real px = fragment.getX(f+i)*ci.xscale+ci.xoffset;
         Real py = fragment.getY(f+i)*ci.yscale+ci.yoffset;
         rays.setPixel(i, fragment.getWhichEye(f+i), px, py);
+        rays.data->sample_id[i] = 0;
       }
     }
 
     // Trace the rays.  The results will automatically go into the fragment
+    context.sample_generator->setupPacket(context, rays);
     context.renderer->traceEyeRays(context, rays);
 
 #if MANTA_SSE

Added: trunk/Engine/SampleGenerators/CMakeLists.txt
==============================================================================
--- (empty file)
+++ trunk/Engine/SampleGenerators/CMakeLists.txt        Thu Oct 18 02:35:25 
2007
@@ -0,0 +1,4 @@
+SET (Manta_SampleGenerators_SRCS
+     SampleGenerators/ConstantSampleGenerator.h
+     SampleGenerators/ConstantSampleGenerator.cc
+     )

Added: trunk/Engine/SampleGenerators/ConstantSampleGenerator.cc
==============================================================================
--- (empty file)
+++ trunk/Engine/SampleGenerators/ConstantSampleGenerator.cc    Thu Oct 18 
02:35:25 2007
@@ -0,0 +1,56 @@
+#include <Engine/SampleGenerators/ConstantSampleGenerator.h>
+#include <Interface/RayPacket.h>
+
+using namespace Manta;
+
+ConstantSampleGenerator::ConstantSampleGenerator(float value) : 
sample_value(value) {
+}
+
+ConstantSampleGenerator::~ConstantSampleGenerator() {
+}
+
+void ConstantSampleGenerator::setupBegin(const SetupContext&, int 
numChannels) {
+}
+
+void ConstantSampleGenerator::setupDisplayChannel(SetupContext& context) {
+}
+
+void ConstantSampleGenerator::setupFrame(const RenderContext& context) {
+}
+
+void ConstantSampleGenerator::setupPacket(const RenderContext& context, 
RayPacket& rays) {
+}
+
+void ConstantSampleGenerator::nextSeeds(Packet<float>& results, RayPacket& 
rays) {
+#ifdef MANTA_SSE
+  int b = (rays.rayBegin + 3) & (~3);
+  int e = (rays.rayEnd) & (~3);
+  if (b >= e) {
+    for (int i = rays.begin(); i < rays.end(); i++) {
+      results.set(i, sample_value);
+    }
+  } else {
+    int i = rays.rayBegin;
+    for (; i < b; i++) {
+       results.set(i, sample_value);
+    }
+    __m128 sse_val = _mm_set1_ps(sample_value);
+    for (; i < e; i += 4) {
+      _mm_store_ps(&results.data[i], sse_val);
+    }
+    for (; i < rays.rayEnd; i++) {
+      results.set(i, sample_value);
+    }
+  }
+#else
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    results.set(i, sample_value);
+  }
+#endif // MANTA_SSE
+}
+
+void ConstantSampleGenerator::nextSeeds(Packet<double>& results, RayPacket& 
rays) {
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    results.set(i, sample_value);
+  }
+}

Added: trunk/Engine/SampleGenerators/ConstantSampleGenerator.h
==============================================================================
--- (empty file)
+++ trunk/Engine/SampleGenerators/ConstantSampleGenerator.h     Thu Oct 18 
02:35:25 2007
@@ -0,0 +1,25 @@
+#ifndef MANTA_ENGINE_SAMPLEGENERATORS_CONSTANT_SAMPLE_GENERATOR_H_
+#define MANTA_ENGINE_SAMPLEGENERATORS_CONSTANT_SAMPLE_GENERATOR_H_
+
+#include <Interface/SampleGenerator.h>
+
+namespace Manta {
+  class ConstantSampleGenerator : public SampleGenerator {
+  public:
+    ConstantSampleGenerator(float value);
+    ~ConstantSampleGenerator();
+
+    virtual void setupBegin(const SetupContext&, int numChannels);
+    virtual void setupDisplayChannel(SetupContext& context);
+    virtual void setupFrame(const RenderContext& context);
+
+    virtual void setupPacket(const RenderContext& context, RayPacket& rays);
+
+    virtual void nextSeeds(Packet<float>& results, RayPacket& rays);
+    virtual void nextSeeds(Packet<double>& results, RayPacket& rays);
+
+    float sample_value;
+  };
+} // end namespace Manta
+
+#endif // MANTA_ENGINE_SAMPLEGENERATORS_CONSTANT_SAMPLE_GENERATOR_H_

Modified: trunk/Interface/CMakeLists.txt
==============================================================================
--- trunk/Interface/CMakeLists.txt      (original)
+++ trunk/Interface/CMakeLists.txt      Thu Oct 18 02:35:25 2007
@@ -48,6 +48,7 @@
         RenderParameters.h
         Renderer.cc
         Renderer.h
+        SampleGenerator.h
         Scene.cc
         Scene.h
         SetupCallback.cc

Modified: trunk/Interface/Context.h
==============================================================================
--- trunk/Interface/Context.h   (original)
+++ trunk/Interface/Context.h   Thu Oct 18 02:35:25 2007
@@ -16,6 +16,7 @@
   class ReadContext;
   class Renderer;
   class MantaInterface;
+  class SampleGenerator;
   class Scene;
   class ShadowAlgorithm;
   class TaskList;
@@ -161,12 +162,15 @@
                   Renderer* renderer, ShadowAlgorithm* shadowAlgorithm,
                   const Camera* camera, const Scene* scene,
                   ThreadStorage *storage_allocator_,
-                  RandomNumberGenerator* rng)
+                  RandomNumberGenerator* rng,
+                  SampleGenerator* sample_gen)
       : rtrt_int(rtrt_int), channelIndex(channelIndex),
         proc(proc), numProcs(numProcs),
         frameState(frameState),
         loadBalancer(loadBalancer), pixelSampler(pixelSampler),
-        renderer(renderer), shadowAlgorithm(shadowAlgorithm),
+        renderer(renderer),
+        sample_generator(sample_gen),
+        shadowAlgorithm(shadowAlgorithm),
         camera(camera), scene(scene),
         storage_allocator( storage_allocator_ ),
         rng(rng)
@@ -180,6 +184,7 @@
     LoadBalancer* loadBalancer;
     PixelSampler* pixelSampler;
     Renderer* renderer;
+    SampleGenerator* sample_generator;
     ShadowAlgorithm* shadowAlgorithm;
     const Camera* camera;
     const Scene* scene;

Modified: trunk/Interface/MantaInterface.h
==============================================================================
--- trunk/Interface/MantaInterface.h    (original)
+++ trunk/Interface/MantaInterface.h    Thu Oct 18 02:35:25 2007
@@ -61,6 +61,7 @@
   class RandomNumberGenerator;
   class RayPacket;
   class Renderer;
+  class SampleGenerator;
   class Scene;
   class SetupCallback;
   class ShadowAlgorithm;
@@ -130,6 +131,10 @@
     // Renderers
     virtual void setRenderer( Renderer* renderer_ ) = 0;
     virtual Renderer* getRenderer() const = 0;
+
+    // Sample Generators
+    virtual void setSampleGenerator(SampleGenerator* sample_gen) = 0;
+    virtual SampleGenerator* getSampleGenerator() const = 0;
 
     // Shadow Algorithms
     virtual void setShadowAlgorithm(ShadowAlgorithm* shadows) = 0;

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Thu Oct 18 02:35:25 2007
@@ -110,6 +110,8 @@
 
     // 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

Added: trunk/Interface/SampleGenerator.h
==============================================================================
--- (empty file)
+++ trunk/Interface/SampleGenerator.h   Thu Oct 18 02:35:25 2007
@@ -0,0 +1,40 @@
+#ifndef MANTA_INTERFACE_SAMPLE_GENERATOR_H_
+#define MANTA_INTERFACE_SAMPLE_GENERATOR_H_
+
+// NOTE(boulos): Is there a good way to forward declare Packet<float>
+// and Packet<double> even though they have to be MANTA_ALIGNed?
+#include <Interface/Packet.h>
+
+namespace Manta {
+  class RayPacket;
+  class RenderContext;
+  class SetupContext;
+
+  class SampleGenerator {
+  public:
+    virtual ~SampleGenerator() {}
+
+    // If there's some sort of precomputation that needs to be done at
+    // the beginning of the setup phase you can do that here.
+    virtual void setupBegin(const SetupContext&, int numChannels) = 0;
+
+    // Whenever the display changes (e.g. a resolution change) allow
+    // the SampleGenerator to perform some action.
+    virtual void setupDisplayChannel(SetupContext& context) = 0;
+
+    // If for some reason you want to do something each frame, you can
+    // do so.
+    virtual void setupFrame(const RenderContext& context) = 0;
+
+    // Before rays are shot through the scene, the PixelSampler should
+    // 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;
+
+    // Grab a set of random seeds (float and double versions)
+    virtual void nextSeeds(Packet<float>& results, RayPacket& rays) = 0;
+    virtual void nextSeeds(Packet<double>& results, RayPacket& rays) = 0;
+  };
+} // end namespace Manta
+
+#endif // MANTA_INTERFACE_SAMPLE_GENERATOR_H_




  • [Manta] r1784 - in trunk: Engine Engine/Control Engine/PixelSamplers Engine/SampleGenerators Interface, boulos, 10/18/2007

Archive powered by MHonArc 2.6.16.

Top of page