Manta Interactive Ray Tracer Development Mailing List

Text archives Help


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


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r840 - trunk/fox/disco_demo/Engine/Shaders
  • Date: Wed, 11 Jan 2006 17:24:17 -0700 (MST)

Author: abe
Date: Wed Jan 11 17:24:16 2006
New Revision: 840

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

Added term to kernel, naively based on normal dot product (no threshold), to 
avoid filtering over geometric edges.

M    fox/disco_demo/Engine/Shaders/AOShader.cc


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     Wed Jan 11 17:24:16 
2006
@@ -43,7 +43,7 @@
 
 #include <disco_demo/Interface/DiscoTile.h>
 
-
+using namespace SCIRun;
 using namespace Manta;
 using namespace disco;
 using namespace disco::ambient_occlusion;
@@ -150,7 +150,7 @@
       Real x   = r * Cos(phi);
       Real y   = r * Sin(phi);
       Real z   = 1.0 - x*x - y*y;
-      z = (z > 0.0) ? Sqrt(z) : 0.0;
+      z = (z > 0.0) ? SCIRun::Sqrt(z) : 0.0;
         
       directions[i] = Vector(x, y, z);
     }
@@ -318,6 +318,9 @@
                                 DiscoTile *disco_tile,
                                 TilePacket &packet ) {
 
+  // Compute normals.
+  packet.computeNormals( context );
+  
   
/////////////////////////////////////////////////////////////////////////////
   // Filter the hit ratios from neighboring pixels.
   for (int i=0;i<packet.getSize();++i) {
@@ -335,38 +338,47 @@
         int x = p.tilex;
         int y = p.tiley;
 
+        // Find normal.
+        Vector &normal = e.normal;
+        
         Real sum = 0.0;
+        Real total = 0.0;
         
         
///////////////////////////////////////////////////////////////////////
         // Convolve.
         int half_width = (kernel_width-1)/2;
 
         // Use an averaging filter.
-        Real filter_value = 1.0/(Real)(kernel_width*kernel_width);
+        // Real filter_value = 1.0/(Real)(kernel_width*kernel_width);
         
         for (int y_offset=-half_width;y_offset<=half_width;++y_offset) {
           for (int x_offset=-half_width;x_offset<=half_width;++x_offset) {
+
+            RayPacket::Element &neighbor_ray =
+              disco_tile->getRayPacketElement( x+x_offset,y+y_offset );
             
-            if (disco_tile->getRayPacketElement( x+x_offset,y+y_offset 
).hitInfo.wasHit()) {
-            
+            if (neighbor_ray.hitInfo.wasHit()) {
+
+              // Check dot product.
+              Real d = SCIRun::Max((Real)0.0,Dot( normal, 
neighbor_ray.normal ));
+                            
               // Look up the neighbor value.
-              Real hit_ratio =
+              Real hit_ratio = d *
                 disco_tile->
                 getTilePacketElement( x+x_offset,
                                       y+y_offset 
).scratch_pad<DiscoInfo>().hit_ratio;
 
               // Sum up all of the neighbors.
-              sum += hit_ratio * filter_value;
+              sum += hit_ratio;
+              total += d;
             }
 
             
           }
         }
 
-        // sum = p.scratch_pad<DiscoInfo>().hit_ratio;
-        
         // Color the pixel
-        sum = 1.0 - sum;
+        sum = 1.0 - (sum/total);
         e.color = Color(RGB(sum,sum,sum));
       }
       else {




  • [MANTA] r840 - trunk/fox/disco_demo/Engine/Shaders, abe, 01/11/2006

Archive powered by MHonArc 2.6.16.

Top of page