Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r842 - in trunk/fox: . disco_demo/Engine/Renderers disco_demo/Engine/Shaders dm_demo


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r842 - in trunk/fox: . disco_demo/Engine/Renderers disco_demo/Engine/Shaders dm_demo
  • Date: Fri, 13 Jan 2006 01:13:01 -0700 (MST)

Author: abe
Date: Fri Jan 13 01:13:00 2006
New Revision: 842

Modified:
   trunk/fox/CMakeLists.txt
   trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
   trunk/fox/disco_demo/Engine/Shaders/AOShader.cc
   trunk/fox/dm_demo/dm_demo.cc
Log:

Added -stack option to dm_demo.cc so disco shader stack may be run from it.
M    fox/dm_demo/dm_demo.cc

Added code to call manta background shader instead of using a hard coded one.
M    fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
M    fox/disco_demo/Engine/Shaders/AOShader.cc

Added file glob statement so that the fox/ directory will try to configure 
any directory it contains that matches *_demo. This allows me to have several 
test directories that aren't in the repository without changing the cmake 
files.
M    fox/CMakeLists.txt


Modified: trunk/fox/CMakeLists.txt
==============================================================================
--- trunk/fox/CMakeLists.txt    (original)
+++ trunk/fox/CMakeLists.txt    Fri Jan 13 01:13:00 2006
@@ -14,10 +14,10 @@
 SUBDIRS(FManta)
 
 # Demo examples.
+FILE(GLOB DEMO_SUBDIRS *_demo)
+
 SUBDIRS(
-  disco_demo
-  dm_demo
-  sc_demo
+  ${DEMO_SUBDIRS}
   )
     
 

Modified: trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
==============================================================================
--- trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc     (original)
+++ trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc     Fri Jan 13 
01:13:00 2006
@@ -114,31 +114,36 @@
   tile_packet.resetHit();
   context.scene->getObject()->intersect(context, tile_packet);
 
-  // Find the first hit.
-  int start = 0;
+  // Send hit rays to the per sample shader and missed rays to
+  // the background shader.
+  for(int i = 0;i<tile_packet.getSize();){
 
-  // This is necessary since calling raypacket.computeNormals assumes
-  // that all of the rays in the packet hit something and have a valid
-  // primitive pointer.
-  for (;start<tile_packet.getSize();++start) {
+    // Call the per-sample shader.
+    if(tile_packet.hitInfo(i).wasHit()){
+      int end = i+1;
+      while(end < tile_packet.getSize() && tile_packet.hitInfo(end).wasHit())
+        end++;
 
-    while ((start<tile_packet.getSize()) &&
-         !tile_packet.hitInfo(start).wasHit())
-    ++start;
-    
-    // Find a run of elements that generated hits.
-    int end = start;
-    while (end < tile_packet.getSize() && tile_packet.hitInfo(end).wasHit())
-      ++end;
+      TilePacket sub_packet(tile_packet, i, end);
+      per_sample_shader->shade( context, sub_packet );
+      
+      i=end;
+      
+    }
 
-    // Create a sub packet of elements which generated hits.
-    TilePacket sub_packet( tile_packet, start, end );
-  
-    // Send the packet to the disco per sample shader.
-    per_sample_shader->shade( context, sub_packet );
+    // Call the background shader.
+    else {
+      int end = i+1;
+      while(end < tile_packet.getSize() && 
!tile_packet.hitInfo(end).wasHit())
+        end++;
+      
+      TilePacket subPacket(tile_packet, i, end);
+      context.scene->getBackground()->shade(context, subPacket);
+      
+      i=end;
+    }
+  }
 
-    start = end;
-  };
 }
 
 

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 Jan 13 01:13:00 
2006
@@ -219,80 +219,74 @@
     TilePacket::Element &p = packet.getTilePacketElement( i );
     RayPacket::Element  &e = packet.getRayPacketElement ( i );
 
-    if (e.hitInfo.wasHit()) {
-
-      int task =
-        ((p.tilex+overlap)%kernel_width) +
-        ((p.tiley+overlap)%kernel_width) * kernel_width;
+    int task =
+      ((p.tilex+overlap)%kernel_width) +
+      ((p.tiley+overlap)%kernel_width) * kernel_width;
       
-      int d     = task*task_size;
-      int d_end = d+task_size;
+    int d     = task*task_size;
+    int d_end = d+task_size;
 
-      Real total_hit  = 0.0;
-      Real total_sent = 0.0;
+    Real total_hit  = 0.0;
+    Real total_sent = 0.0;
       
-      for (;d<d_end;++d) {
+    for (;d<d_end;++d) {
 
-        // Transform the precomputed direction to the local coordinate system
-        // of the hit.
-        Vector dir =
-          directions[d][0]*U[i] +
-          directions[d][1]*V[i] +
-          directions[d][2]*W[i];
-
-        // Add a ray to the outgoing packet.
-        RayPacket::Element &out = secondary_packet.get( secondary_size++ );
-
-        // Initialize the ray.
-        out.ray.set( e.hitPosition, dir );
-        out.hitInfo.reset( ambient_cutoff );
-        ++total_sent;
-
-        // Check to see if the packet is filled.
-        if (secondary_size == RayPacket::MaxSize) {
-
-          
/////////////////////////////////////////////////////////////////////
-          // Send the ray packet.
-          secondary_packet.resize( secondary_size );
-          context.scene->getObject()->intersect( context, secondary_packet );
-
-          // Count how many hit.
-          for (int j=0;j<secondary_packet.getSize();++j) {
-            if (secondary_packet.get(j).hitInfo.wasHit()) {
-              ++total_hit;
-            }
+      // Transform the precomputed direction to the local coordinate system
+      // of the hit.
+      Vector dir =
+        directions[d][0]*U[i] +
+        directions[d][1]*V[i] +
+        directions[d][2]*W[i];
+
+      // Add a ray to the outgoing packet.
+      RayPacket::Element &out = secondary_packet.get( secondary_size++ );
+
+      // Initialize the ray.
+      out.ray.set( e.hitPosition, dir );
+      out.hitInfo.reset( ambient_cutoff );
+      ++total_sent;
+
+      // Check to see if the packet is filled.
+      if (secondary_size == RayPacket::MaxSize) {
+
+        /////////////////////////////////////////////////////////////////////
+        // Send the ray packet.
+        secondary_packet.resize( secondary_size );
+        context.scene->getObject()->intersect( context, secondary_packet );
+
+        // Count how many hit.
+        for (int j=0;j<secondary_packet.getSize();++j) {
+          if (secondary_packet.get(j).hitInfo.wasHit()) {
+            ++total_hit;
           }
-
-          
/////////////////////////////////////////////////////////////////////
-          // Reset the secondary packet.
-          secondary_packet.setAllFlags( 0 );
-          secondary_size = 0;
         }
+
+        /////////////////////////////////////////////////////////////////////
+        // Reset the secondary packet.
+        secondary_packet.setAllFlags( 0 );
+        secondary_size = 0;
       }
+    }
 
-      /////////////////////////////////////////////////////////////////////
-      // Check to see if there are any secondary rays left over.
-      secondary_packet.resize( secondary_size );
-      context.scene->getObject()->intersect( context, secondary_packet );
+    /////////////////////////////////////////////////////////////////////
+    // Check to see if there are any secondary rays left over.
+    secondary_packet.resize( secondary_size );
+    context.scene->getObject()->intersect( context, secondary_packet );
       
-      // Count how many hit.
-      for (int j=0;j<secondary_packet.getSize();++j) {
-        if (secondary_packet.get(j).hitInfo.wasHit()) {
-          ++total_hit;
-        }
+    // Count how many hit.
+    for (int j=0;j<secondary_packet.getSize();++j) {
+      if (secondary_packet.get(j).hitInfo.wasHit()) {
+        ++total_hit;
       }
+    }
 
-      secondary_packet.setAllFlags( 0 );
-      secondary_size = 0;
+    secondary_packet.setAllFlags( 0 );
+    secondary_size = 0;
 
-      
////////////////////////////////////////////////////////////////////////
-      // Determine hit ratio.
-      p.scratch_pad<DiscoInfo>().hit_ratio = ( total_hit / total_sent );
+    ////////////////////////////////////////////////////////////////////////
+    // Determine hit ratio.
+    p.scratch_pad<DiscoInfo>().hit_ratio = ( total_hit / total_sent );
 
-    }
-    else {
-      p.scratch_pad<DiscoInfo>().hit_ratio = 1.0;
-    }
   }    
            
 }
@@ -315,8 +309,8 @@
 /////////////////////////////////////////////////////////////////////////////
 // Shader method
 void AONeighborhoodShader::shade( const RenderContext &context,
-                                DiscoTile *disco_tile,
-                                TilePacket &packet ) {
+                                  DiscoTile *disco_tile,
+                                  TilePacket &packet ) {
 
   // Compute normals.
   packet.computeNormals( context );

Modified: trunk/fox/dm_demo/dm_demo.cc
==============================================================================
--- trunk/fox/dm_demo/dm_demo.cc        (original)
+++ trunk/fox/dm_demo/dm_demo.cc        Fri Jan 13 01:13:00 2006
@@ -34,6 +34,10 @@
 #include <Interface/Camera.h>
 #include <Interface/Context.h>
 
+#include <Core/Exceptions/Exception.h>
+#include <Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/IllegalArgument.h>
+
 #include <X11/Xlib.h>
 
 #include <Engine/Display/GLXImageDisplay.h>
@@ -59,6 +63,7 @@
 using namespace fox_manta;
 using namespace Manta;
 using namespace std;
+using namespace SCIRun;
 
 #include <Model/Groups/KDTree.h>
 #include <Model/Groups/TransparentKDTree.h>
@@ -75,18 +80,13 @@
 }
 
 Scene* createDefaultScene();
+static void make_stack( ReadContext &context, const vector<string> &args );
 
 int main( int argc, char *argv[]) {
 
-       // Make sure the necessary environment is setup.
-       if (getenv("THREAD_NO_CATCH_SIGNALS") == 0) {
-               cerr << "ALERT: setenv THREAD_NO_CATCH_SIGNALS 1 to avoid 
instability on exit." << std::endl;
-       };
-       if (getenv("FGL_MACRO_TILE_FB") == 0) {
-               cerr << "ALERT: setenv FGL_MACRO_TILE_FB 1 to improve 
performance over vizserver." << std::endl;
-       }
-
        // Parse args.
+  vector<string> args( argv, &argv[argc] );
+  
        int np = 1;
        char *scene_text = 0;
        string bookmark_file_name;
@@ -94,6 +94,7 @@
   string default_camera         = "pinhole(-eye 3 3 2 -lookat 0 0 0.3 -up 0 
0 1 -fov 60)";
   string default_imagetraverser = "tiled";
   string default_pixelsampler   = "singlesample";
+  string stack_file = "";
 
   bool use_stereo = false;
 
@@ -116,11 +117,8 @@
     else if (arg == "-camera") {
       default_camera = argv[++i];
     }
-    else if (arg == "-imagetraverser") {
-      default_imagetraverser = argv[++i];
-    }
-    else if (arg == "-pixelsampler" ) {
-      default_pixelsampler = argv[++i];
+    else if (arg == "-stack") {
+      stack_file = argv[++i];
     }
        }
        
@@ -156,21 +154,9 @@
     manta_interface->changeNumWorkers     ( np );
     manta_interface->selectImageType      ( "rgba8" );
     manta_interface->selectLoadBalancer   ( "workqueue" );
-
-    // Check to see if image traverser and pixel sampler are found.
-    if (!manta_interface->selectImageTraverser ( default_imagetraverser )) {
-      std::cerr << "Invalid Image traverser: " << default_imagetraverser << 
std::endl;
-      return 1;
-    }
-    
-    if (!manta_interface->selectPixelSampler   ( default_pixelsampler )) {
-      std::cerr << "Invalid Pixel sampler: " << default_pixelsampler << 
std::endl;
-      return 1;      
-    }
-    
     manta_interface->selectRenderer       ( "raytracer" );
-    manta_interface->selectShadowAlgorithm( "hard" );
-       
+    manta_interface->selectShadowAlgorithm( "hard" );    
+    
     // Camera *camera = new PinholeCamera( Point ( 0.0, 0.0, 0.0 ), Point ( 
0.0, -1.0, 0.0 ), Vector( 0.0, 0.0, 1.0 ), 60 );
        
     // Create the manta image frame.
@@ -241,6 +227,18 @@
       }
     }
 
+    
///////////////////////////////////////////////////////////////////////////
+    // Configure the renderer stack.
+    if (stack_file.size()) {
+      manta_interface->readStack( stack_file, args );
+    }
+    else {
+      // Pass a read context and all of the command line args to the scene
+      // configuration function. The function will ignore some arguments.
+      ReadContext context( manta_interface );
+      make_stack( context, args );
+    }
+
     // Add a camera bookmark for the default camera.
     manta_window.addCameraBookmark( "Default", default_camera );
   
@@ -346,6 +344,120 @@
     Thread::exitAll( 1 );
   }
 }      
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// Default stack setup
+
+void printList(ostream& out, const MantaInterface::listType& list, int 
spaces=0)
+{
+  for(int i=0;i<spaces;i++)
+    out << ' ';
+  for(MantaInterface::listType::const_iterator iter = list.begin();
+      iter != list.end(); ++iter){
+    if(iter != list.begin())
+      out << ", ";
+    out << *iter;
+  }
+  out << "\n";
+}
+
+static void usage(MantaInterface* rtrt)
+{
+  cerr << "Usage: manta [options]\n";
+  cerr << "Valid options are:\n";
+  cerr << " -np N           - Use N processors\n";
+  // cerr << " -res NxM        - Use N by M pixels for rendering (needs the 
x).\n";
+  cerr << " -imagedisplay S - Use image display mode named S, valid modes 
are:\n";
+  printList(cerr, rtrt->listImageDisplays(), 4);
+  cerr << " -imagetype S    - Use image display mode named S, valid modes 
are:\n";
+  printList(cerr, rtrt->listImageTypes(), 4);
+  cerr << " -ui S           - Use the user interface S, valid options 
are:\n";
+  printList(cerr, rtrt->listUserInterfaces(), 4);
+  cerr << " -shadows S      - Use S mode for rendering shadows, valid modes 
are:\n";
+  printList(cerr, rtrt->listShadowAlgorithms(), 4);
+  cerr << " -imagetraverser S - Use S method for image traversing, valid 
modes are:\n";
+  printList(cerr, rtrt->listImageTraversers(), 4);
+  cerr << " -pixelsampler S - Use S method for pixel sampling, valid modes 
are:\n";
+  printList(cerr, rtrt->listPixelSamplers(), 4);
+  cerr << " -camera S       - User camera model S, valid cameras are:\n";
+  printList(cerr, rtrt->listCameras(), 4);
+  cerr << " -renderer S     - Use renderer S, valid renderers are:\n";
+  printList(cerr, rtrt->listRenderers(), 2);
+  cerr << " -scene S        - Render Scene S\n";
+  cerr << " -stack S        - Load render stack using library S\n";
+  cerr << " -bookmarks S    - Read bookmarks from file S\n";
+}
+
+
+void make_stack( ReadContext &context, const vector<string> &args ) {
+
+  // Obtain a pointer to manta.
+  MantaInterface *rtrt = context.manta_interface;
+
+  // Defaults.
+  
+  if(!rtrt->selectLoadBalancer("workqueue"))
+    throw InternalError("default load balancer not found", __FILE__, 
__LINE__);
+  
+  if(!rtrt->selectImageTraverser("tiled"))
+    throw InternalError("default image traverser not found", __FILE__, 
__LINE__ );
+  
+  if(!rtrt->selectPixelSampler("singlesample"))
+    throw InternalError("default pixel sampler not found", __FILE__, 
__LINE__ );
+  
+  if(!rtrt->selectRenderer("raytracer"))
+    throw InternalError("default renderer not found", __FILE__, __LINE__ );
+
+  // Parse command line args.
+  for (int i=0;i<args.size();++i) {
+    string arg = args[i];
+
+    if(arg == "-imagetraverser"){
+      string s;
+      if(!getStringArg(i, args, s))
+        usage(rtrt);
+      if(!rtrt->selectImageTraverser(s)){
+        cerr << "Invalid image traverser: " << s << ", available image 
traversers are:\n";
+        printList(cerr, rtrt->listImageTraversers());
+        throw IllegalArgument( s, i, args );
+      }
+
+    } else if(arg == "-loadbalancer"){
+      string s;
+      if(!getStringArg(i, args, s))
+        usage(rtrt);
+      if(!rtrt->selectLoadBalancer(s)){
+        cerr << "Invalid load balancer: " << s << ", available load 
balancers are:\n";
+        printList(cerr, rtrt->listLoadBalancers());
+        throw IllegalArgument( s, i, args );
+      }
+    } else if(arg == "-pixelsampler"){
+      string s;
+      if(!getStringArg(i, args, s))
+        usage(rtrt);
+      if(!rtrt->selectPixelSampler(s)){
+        cerr << "Invalid pixel sampler: " << s << ", available pixel 
samplers are:\n";
+        printList(cerr, rtrt->listPixelSamplers());
+        throw IllegalArgument( s, i, args );
+      }
+    } else if(arg == "-renderer"){
+      string s;
+      if(!getStringArg(i, args, s))
+        usage(rtrt);
+      if(!rtrt->selectRenderer(s)){
+        cerr << "Invalid renderer: " << s << ", available renderers are:\n";
+        throw IllegalArgument( s, i, args );
+      }
+    }
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// Default scene
 
 #include <Interface/LightSet.h>
 #include <Model/AmbientLights/ConstantAmbient.h>




  • [MANTA] r842 - in trunk/fox: . disco_demo/Engine/Renderers disco_demo/Engine/Shaders dm_demo, abe, 01/13/2006

Archive powered by MHonArc 2.6.16.

Top of page