Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r942 - trunk/fox/disco_demo/Engine/Shaders


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r942 - trunk/fox/disco_demo/Engine/Shaders
  • Date: Fri, 17 Feb 2006 16:09:54 -0700 (MST)

Author: bigler
Date: Fri Feb 17 16:09:54 2006
New Revision: 942

Modified:
   trunk/fox/disco_demo/Engine/Shaders/AOShader.cc
   trunk/fox/disco_demo/Engine/Shaders/AOShader.h
Log:

directions[] is now shared among all the processors.  This fixes the
shimmering that was a result of different tiles being picked up by
different processors from frame to frame.  There is no longer a need
for per processor allocations.

Added fill_directions() and fill_directions_stratified() functions
that encapsulate these features.  Call from constructor or some other
function that will be called when you make changes to the
AOSampleShader.

Got rid of generated flag, but it may be back if you add accessors
that can change the total number of directions needed.


Modified: trunk/fox/disco_demo/Engine/Shaders/AOShader.cc
==============================================================================
--- trunk/fox/disco_demo/Engine/Shaders/AOShader.cc     (original)
+++ trunk/fox/disco_demo/Engine/Shaders/AOShader.cc     Fri Feb 17 16:09:54 
2006
@@ -41,7 +41,7 @@
 #include <SCIRun/Core/Math/Trig.h>
 
 #include <iostream>
-#include <cassert>
+//#include <cassert>
 
 #include <disco_demo/Interface/DiscoTile.h>
 
@@ -56,103 +56,33 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 
+AOSampleShader::AOSampleShader( int kernel_width_, int total_directions_,
+                                Real ambient_cutoff_ )
+  : kernel_width( kernel_width_ ),
+    total_directions( total_directions_ ),
+    ambient_cutoff( ambient_cutoff_ )
+{
+  directions = new Vector[total_directions];
+  fill_directions();
+}
+
 /////////////////////////////////////////////////////////////////////////////
 // Setup
   
-void AOSampleShader::setupDisplayChannel(SetupContext& context) {
-
-  // Determine how much storage is needed for the direction vector.
-  size_t bytes = sizeof( Vector ) * total_directions;
-
-  // Request storage.
-  storage_token = context.storage_allocator->requestStorage( bytes, 128 );
-
-  if (context.proc == 0) {
-    generated = false;
-  }
+void AOSampleShader::setupDisplayChannel(SetupContext& context)
+{
 }
 
 // Per frame / per thread setup.
-void AOSampleShader::setupFrame(const RenderContext& context) {
-
-  ///////////////////////////////////////////////////////////////////////////
-  // Generate directions.
-  if (!generated) {
-
-    // Obtain a pointer to the array.
-    Vector *directions = (Vector *)context.storage_allocator->get( 
context.proc, storage_token );
-
-    /////////////////////////////////////////////////////////////////////////
-    // Generate cosine weighted directions
-    HaltonSequence<Real,2> sequence( context.proc*100 );
-    VectorT<Real,2> p;
-
-    // #define STRATIFY
-#ifdef STRATIFY
-    Real width = 1.0/(Real)kernel_width;
-    int task_size = total_directions/(kernel_width*kernel_width);
-
-    int i = 0;
-    for (int s=0;s<kernel_width;++s) {
-      for (int t=0;t<kernel_width;++t) {
-        
-        Real s_start = width*s;
-        Real t_start = width*t;
-        
-        for (int r=0;r<task_size;++r) {
-          
-          // Obtain the next point.
-          sequence.next( p );
-          
-          // Stratify the point.
-          p[0] = s_start+(p[0]*width);
-          p[1] = t_start+(p[1]*width);
-          
-          // Map to hemisphere.
-          Real phi = 2.0 * Pi * p[0];
-          Real r   = SCIRun::Sqrt( p[1] );
-          Real x   = r * Cos(phi);
-          Real y   = r * Sin(phi);
-          Real z   = 1.0 - x*x - y*y;
-          z = (z > 0.0) ? SCIRun::Sqrt(z) : 0.0;
-          
-          directions[i++] = Vector(x, y, z);
-          
-        }
-      }
-      
-    }
-    
-#else 
-    for ( int i = 0; i < total_directions; i++ ) {
-      
-      sequence.next( p );
-      
-      Real phi = 2.0 * Pi * p[0];
-      Real r   = sqrt( p[1] );
-      Real x   = r * Cos(phi);
-      Real y   = r * Sin(phi);
-      Real z   = 1.0 - x*x - y*y;
-      z = (z > 0.0) ? SCIRun::Sqrt(z) : 0.0;
-        
-      directions[i] = Vector(x, y, z);
-    }
-#endif
-
-  }
-  
+void AOSampleShader::setupFrame(const RenderContext& context)
+{
 }
 
 /////////////////////////////////////////////////////////////////////////////
 // Shader Method
-void AOSampleShader::shade( const RenderContext &context, RayPacket 
&ray_packet, TilePacket &tile_packet ) {
-
-  // Obtain a pointer to the array.
-  Vector *directions = (Vector *)context.storage_allocator->get( 
context.proc, storage_token );
-  
-  if (context.proc == 0) {
-    generated = true;
-  }
+void AOSampleShader::shade( const RenderContext &context,
+                            RayPacket &ray_packet, TilePacket &tile_packet )
+{
 
   ///////////////////////////////////////////////////////////////////////////
   // Compute normals and hit positions.
@@ -212,6 +142,8 @@
     // Iterate across directions.
     for (;d<d_end;++d) {
 
+      //      assert(d < total_directions);
+
       // Transform the precomputed direction to the local coordinate system
       // of the hit.
       {
@@ -292,7 +224,63 @@
   }
 }
 
-  
+void AOSampleShader::fill_directions() {
+
+  HaltonSequence<Real,2> sequence( 13 );
+
+  for ( int i = 0; i < total_directions; i++ ) {
+    VectorT<Real,2> p;
+    sequence.next( p );
+
+    Real phi = (Real)(2 * M_PI) * p[0];
+    Real r   = SCIRun::Sqrt( p[1] );
+    Real x   = r * Cos(phi);
+    Real y   = r * Sin(phi);
+    Real z   = 1 - x*x - y*y;
+    z = (z > 0) ? SCIRun::Sqrt(z) : 0;
+
+    directions[i] = Vector(x, y, z);
+  }
+}

+void AOSampleShader::fill_directions_stratified() {
+
+  HaltonSequence<Real,2> sequence( 13 );
+
+  Real width = 1/(Real)kernel_width;
+  int task_size = total_directions/(kernel_width*kernel_width);
+
+  int d_index = 0;
+  for (int s=0;s<kernel_width;++s) {
+    for (int t=0;t<kernel_width;++t) {
+
+      Real s_start = width*s;
+      Real t_start = width*t;
+
+      for (int r=0;r<task_size;++r) {
+
+        // Obtain the next point.
+        VectorT<Real,2> p;
+        sequence.next( p );
+
+        // Stratify the point.
+        p[0] = s_start+(p[0]*width);
+        p[1] = t_start+(p[1]*width);
+
+        // Map to hemisphere.
+        Real phi = (Real)(2 * M_PI) * p[0];
+        Real r   = SCIRun::Sqrt( p[1] );
+        Real x   = r * Cos(phi);
+        Real y   = r * Sin(phi);
+        Real z   = 1 - x*x - y*y;
+        z = (z > 0) ? SCIRun::Sqrt(z) : 0;
+
+        directions[d_index++] = Vector(x, y, z);
+      }
+
+    }
+  }
+}
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 // Neighborhood shader.

Modified: trunk/fox/disco_demo/Engine/Shaders/AOShader.h
==============================================================================
--- trunk/fox/disco_demo/Engine/Shaders/AOShader.h      (original)
+++ trunk/fox/disco_demo/Engine/Shaders/AOShader.h      Fri Feb 17 16:09:54 
2006
@@ -61,29 +61,30 @@
     // Per-sample shader.
     class AOSampleShader : public PerSampleShader {
     public:
-      AOSampleShader( int kernel_width_, int total_directions_, Real 
ambient_cutoff_ )
-        : kernel_width( kernel_width_ ),
-          total_directions( total_directions_ ),
-          ambient_cutoff( ambient_cutoff_ ) { };
+      AOSampleShader( int kernel_width_, int total_directions_,
+                      Real ambient_cutoff_ );
+      virtual ~AOSampleShader() { if (directions) delete[] directions; }
       
       virtual void setupDisplayChannel(SetupContext& context);
       virtual void setupFrame(const RenderContext& context);
       
-      virtual void shade( const RenderContext &context, RayPacket 
&ray_packet, TilePacket &tile_packet );
+      virtual void shade( const RenderContext &context, RayPacket 
&ray_packet,
+                          TilePacket &tile_packet );
 
       // Accessors.
       int getTotalDirections() { return total_directions; };
       int getKernelWidth() { return kernel_width; };
 
     private:
+      void fill_directions();
+      void fill_directions_stratified();
+
       // Members.
-      int generated;
       int total_directions;
       int kernel_width;
       Real ambient_cutoff;
 
-      // Storage
-      ThreadStorage::Token storage_token;
+      Vector* directions;
     };
 
     // Neighborhood shader.




  • [MANTA] r942 - trunk/fox/disco_demo/Engine/Shaders, bigler, 02/17/2006

Archive powered by MHonArc 2.6.16.

Top of page