Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r876 - in trunk/fox/disco_demo: Engine/Renderers Engine/Shaders Interface scenes


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r876 - in trunk/fox/disco_demo: Engine/Renderers Engine/Shaders Interface scenes
  • Date: Tue, 31 Jan 2006 02:04:06 -0700 (MST)

Author: abe
Date: Tue Jan 31 02:04:05 2006
New Revision: 876

Modified:
   trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
   trunk/fox/disco_demo/Engine/Shaders/AOShader.cc
   trunk/fox/disco_demo/Interface/TilePacket.h
   trunk/fox/disco_demo/scenes/disco_stack.cc
Log:

Improvements to ambient occlusion shader.

M    fox/disco_demo/Interface/TilePacket.h
M    fox/disco_demo/scenes/disco_stack.cc
M    fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
M    fox/disco_demo/Engine/Shaders/AOShader.cc


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     Tue Jan 31 
02:04:05 2006
@@ -136,7 +136,7 @@
       TilePacket sub_tile_packet(tile_packet, i, end);
       
       per_sample_shader->shade( context, sub_ray_packet, sub_tile_packet );
-      
+
       i=end;
       
     }
@@ -144,14 +144,15 @@
     // Call the background shader.
     else {
       int end = i+1;
-      while(end < ray_packet.end() && !ray_packet.wasHit(end))
+      while(end < ray_packet.end() && (!ray_packet.wasHit(end)))
         end++;
       
       RayPacket subPacket(ray_packet, i, end);
       context.scene->getBackground()->shade(context, subPacket);
 
       // Copy the background color over to the tile packet.
-      for (int j=i;j<end;++j) {
+      for (int j=subPacket.begin();j<subPacket.end();++j) {
+        tile_packet.get(j).flags &= (~TilePacket::WAS_HIT);
         tile_packet.get(j).color = ray_packet.getColor(j);
       }
       

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     Tue Jan 31 02:04:05 
2006
@@ -40,6 +40,7 @@
 #include <SCIRun/Core/Math/Trig.h>
 
 #include <iostream>
+#include <cassert>
 
 #include <disco_demo/Interface/DiscoTile.h>
 
@@ -176,41 +177,44 @@
 
   ///////////////////////////////////////////////////////////////////////////
   // Compute local coordinate system for each hit position.
-  Vector V[RayPacket::MaxSize];
-  Vector U[RayPacket::MaxSize];
-  Vector W[RayPacket::MaxSize];
 
   int kernel_size = kernel_width*kernel_width;
   int overlap     = (kernel_width-1)/2;
-  int task_size   = total_directions / kernel_size;
-  
-  for (int i=ray_packet.begin();i<ray_packet.end();++i) {
-
-    W[i] = ray_packet.getNormal(i);
-
-    // Determine if W can be crossed with 1,0,0.  Normally we would do
-    // this by checking the dot product of W and [1,0,0], but since
-    // this is simpley W[0]*1 or W[0] we can simplify the expression.
-    if ((1-W[i][0]) < (Real)1e-6)
-      U[i] = Cross( W[i], Vector(0,1,0) );
-    else
-      U[i] = Cross( W[i], Vector(1,0,0) );
-    V[i] = Cross( W[i], U[i] );
-  }
+  Real task_size   = total_directions / kernel_size;
 
   // Create a ray packet for shooting secondary rays.
   RayPacketData secondary_data;
   RayPacket     secondary_packet( secondary_data, 0, 0, 1, 0 );
 
-  int secondary_size = 0;
-    
-  ///////////////////////////////////////////////////////////////////////////
-  // Decide which directions to shoot based on TilePacket element task id.
+  // Keep track of which primary rays each secondary ray maps to.
+  int secondary_map[RayPacket::MaxSize];  
+  int secondary_size = secondary_packet.begin();
+
+  // Keep track of how many secondary rays hit something for each
+  // primary ray.
+  Real total_hits[RayPacket::MaxSize];
   
+  ///////////////////////////////////////////////////////////////////////////
+  // Decide which directions to shoot based on TilePacket element task id.  
+  Vector W, U, V;
   for (int i=ray_packet.begin();i<ray_packet.end();++i) {
-    
+
     TilePacket::Element &p = tile_packet.get( i );
 
+    // Initialize total secondary hits for this primary ray.
+    total_hits[i] = 0;
+    
+    W = ray_packet.getNormal(i);
+
+    // Determine if W can be crossed with 1,0,0.  Normally we would do
+    // this by checking the dot product of W and [1,0,0], but since
+    // this is simpley W[0]*1 or W[0] we can simplify the expression.
+    U = ((1-W[0]) < (Real)1e-6) ?
+      Cross( W, Vector(0,1,0) ) :
+      Cross( W, Vector(1,0,0) );
+    V = Cross( W, U );
+   
+    // Determine which directions to use.
     int task =
       ((p.tilex+overlap)%kernel_width) +
       ((p.tiley+overlap)%kernel_width) * kernel_width;
@@ -218,77 +222,75 @@
     int d     = task*task_size;
     int d_end = d+task_size;
 
-    Real total_hit  = 0.0;
-    Real total_sent = 0.0;
-      
+    // Iterate across directions.
     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];
-
-      p.color = Color(RGB(dir[0],dir[1],dir[2]));
+      {
+        Vector dir =
+          directions[d][0]*U +
+          directions[d][1]*V +
+          directions[d][2]*W;
+        
+        // Add a ray to the outgoing packet.
+        secondary_packet.setRay(secondary_size,
+                                ray_packet.getHitPosition(i), dir );
+      }
       
-      // Add a ray to the outgoing packet.
-      // Initialize the ray.
-      secondary_packet.setRay(secondary_size,
-                              ray_packet.getHitPosition(i), dir );
       secondary_packet.resetHit(secondary_size, ambient_cutoff );
+      secondary_map[secondary_size] = i;
+
       ++secondary_size;
-      ++total_sent;
 
+      ///////////////////////////////////////////////////////////////////////
       // Check to see if the packet is filled.
       if (secondary_size == RayPacket::MaxSize) {
 
-        /////////////////////////////////////////////////////////////////////
-        // Send the ray packet.
+      send_secondary_packet:
+        
+        // Send the packet.
         secondary_packet.resize( secondary_size );
-        context.scene->getObject()->intersect( context, secondary_packet );
+        secondary_packet.resetHits();        
 
+        // Send the ray packet.
+        context.scene->getObject()->intersect( context, secondary_packet );
+        
         // Count how many hit.
         for (int j=secondary_packet.begin();j<secondary_packet.end();++j) {
           if (secondary_packet.wasHit(j)) {
-            ++total_hit;
+            total_hits[secondary_map[j]]++;
           }
         }
-
-        /////////////////////////////////////////////////////////////////////
+        
         // Reset the secondary packet.
         secondary_packet.setAllFlags( 0 );
-        secondary_packet.resetHits();
-        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 );
-      
-    // Count how many hit.
-    for (int j=secondary_packet.begin();j<secondary_packet.end();++j) {
-      if (secondary_packet.wasHit(j)) {
-        ++total_hit;
+        secondary_packet.resize( 0 );
+        secondary_size = secondary_packet.begin();
       }
     }
+  }
 
-    secondary_packet.setAllFlags( 0 );
-    secondary_packet.resetHits();
-    secondary_size = 0;
-
-    ////////////////////////////////////////////////////////////////////////
-    // Determine hit ratio.
-    p.illuminance = ( total_hit / total_sent );
+  // Check to see if any additional secondary rays need to be sent.
+  if (secondary_size) {
+    goto send_secondary_packet;
+  }
+  
+  ////////////////////////////////////////////////////////////////////////
+  // Determine hit ratio.
+  for (int i=ray_packet.begin();i<ray_packet.end();++i) {
 
+    TilePacket::Element &p = tile_packet.get( i );
+    
+    p.illuminance = ( (Real)total_hits[i] / (Real)task_size );
+    
     // Copy over the material color and normal
-    p.color = ray_packet.getColor( i ); // Color(RGB(1,1,1));
-    p.normal = ray_packet.getNormal(i);
+    p.color  = ray_packet.getColor( i ); // Color(RGB(1,1,1));
+    p.normal = ray_packet.getNormal( i );
+    p.t      = ray_packet.getMinT( i );
   }
-           
 }
+
   
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
@@ -341,21 +343,23 @@
             disco_tile->get( x+x_offset,y+y_offset );
           
           if (neighbor.wasHit()) {
+
+            Real d = Abs(p.t-neighbor.t);
+            Real n = SCIRun::Max((Real)0.0,Dot( normal, neighbor.normal ));
+
+            if ((d < 0.1)) {
             
-            // Check dot product.
-            Real d = SCIRun::Max((Real)0.0,Dot( normal, neighbor.normal ));
-            
-            // Look up the neighbor value.
-            Real hit_ratio = d *
-              disco_tile->
-              get( x+x_offset,
-                   y+y_offset ).illuminance;
-            
-            // Sum up all of the neighbors.
-            sum += hit_ratio;
-            total += d;
+              // Look up the neighbor value.
+              Real hit_ratio = n * 
+                disco_tile->
+                get( x+x_offset,
+                     y+y_offset ).illuminance;
+              
+              // Sum up all of the neighbors.
+              sum += hit_ratio;
+              total += n;
+            }
           }
-          
         }
       }
       

Modified: trunk/fox/disco_demo/Interface/TilePacket.h
==============================================================================
--- trunk/fox/disco_demo/Interface/TilePacket.h (original)
+++ trunk/fox/disco_demo/Interface/TilePacket.h Tue Jan 31 02:04:05 2006
@@ -45,7 +45,7 @@
   // per sample results
   class TilePacket {
   public:
-    enum { MaxScratchpadSize = (RayPacketData::MaxScratchpadSize-16) };
+    enum { MaxScratchpadSize = (RayPacketData::MaxScratchpadSize) };
     enum { WAS_HIT = 0x01,
            OVERLAP = 0x02 };
 
@@ -60,6 +60,7 @@
 
       // Computed by per sampler shader.
       Real   illuminance;
+      Real   t;
       Vector normal;
       
       // Result

Modified: trunk/fox/disco_demo/scenes/disco_stack.cc
==============================================================================
--- trunk/fox/disco_demo/scenes/disco_stack.cc  (original)
+++ trunk/fox/disco_demo/scenes/disco_stack.cc  Tue Jan 31 02:04:05 2006
@@ -91,7 +91,7 @@
 
   // Defaults.
   manta_interface->selectLoadBalancer   ( "workqueue" );
-  manta_interface->selectShadowAlgorithm( "hard" );
+  manta_interface->selectShadowAlgorithm( "noshadows" );
 
   
/////////////////////////////////////////////////////////////////////////////
   // Create the disco shaders.




  • [MANTA] r876 - in trunk/fox/disco_demo: Engine/Renderers Engine/Shaders Interface scenes, abe, 01/31/2006

Archive powered by MHonArc 2.6.16.

Top of page