Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r875 - trunk/Model/Groups


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r875 - trunk/Model/Groups
  • Date: Mon, 30 Jan 2006 16:34:02 -0700 (MST)

Author: abe
Date: Mon Jan 30 16:34:02 2006
New Revision: 875

Modified:
   trunk/Model/Groups/KDTree.h
   trunk/Model/Groups/SSEKDTree.cc
Log:

Added hit_index field to kdtree scratch pad. Moved normal interpolation to 
computeNormals method in SSE traversal.
M    Model/Groups/KDTree.h
M    Model/Groups/SSEKDTree.cc


Modified: trunk/Model/Groups/KDTree.h
==============================================================================
--- trunk/Model/Groups/KDTree.h (original)
+++ trunk/Model/Groups/KDTree.h Mon Jan 30 16:34:02 2006
@@ -377,9 +377,10 @@
 
       // This structure is used to record info about the hit.
       struct ScratchPadInfo {
-        Vector normal; // Normal of the intersected face.
-        Color payload; // Payload of the intersected face.
-        Real a, b;
+        Vector normal;          // Normal of the intersected face.
+        Color payload;          // Payload of the intersected face.
+        unsigned int hit_index; // Triangle index for defered normal 
interpolation.
+        Real a, b;              // Barycentric coordinates of the hit.
       };
 
       virtual ~KDTree() {}

Modified: trunk/Model/Groups/SSEKDTree.cc
==============================================================================
--- trunk/Model/Groups/SSEKDTree.cc     (original)
+++ trunk/Model/Groups/SSEKDTree.cc     Mon Jan 30 16:34:02 2006
@@ -431,9 +431,18 @@
         if (intersect_packet.hit_mask[p]) {
 
           // Check the hit t against the ray packet min t.
-          intersect_packet.hit_mask[p] = rays.hit( which+p,
-                                                   intersect_packet.t[p],
-                                                   getMaterial(), this, 0 );
+          if (rays.hit( which+p,
+                        intersect_packet.t[p],
+                        getMaterial(), this, 0 )) {
+
+            // Copy values the the scratchpad.
+            ScratchPadInfo& scratch_pad = 
rays.scratchpad<ScratchPadInfo>(which+p);
+
+            scratch_pad.hit_index = intersect_packet.hit_index[p];
+            scratch_pad.payload = 
tris->get(intersect_packet.hit_index[p]).payload;
+            scratch_pad.a = intersect_packet.u[p];
+            scratch_pad.b = intersect_packet.v[p];
+          }
         }
       }
 
@@ -451,20 +460,7 @@
 
           // assert( intersect_packet.hit_index[p] < tris->getLen() );
           
-          // Interpolate between the three vertices.
-          Vectorf &n0 = normals[intersect_packet.hit_index[p]][0];
-          Vectorf &n1 = normals[intersect_packet.hit_index[p]][1];
-          Vectorf &n2 = normals[intersect_packet.hit_index[p]][2];
-          
-          float u = intersect_packet.u[p];
-          float v = intersect_packet.v[p];
 
-          // Copy values to the scratchpad.
-          ScratchPadInfo& scratch_pad = 
rays.scratchpad<ScratchPadInfo>(which+p);
-          scratch_pad.normal = (n1 * u) + (n2 * v) + (n0 * (1 - u - v));
-          scratch_pad.payload = 
tris->get(intersect_packet.hit_index[p]).payload;
-          scratch_pad.a = u;
-          scratch_pad.b = v;
         }          
       }
 
@@ -510,7 +506,23 @@
 
   // Copy the normal out of the KDTree::ScratchPadInfo structure.
   for (int i=rays.begin();i<rays.end();++i) {
-    rays.setNormal(i, rays.scratchpad<ScratchPadInfo>(i).normal);
+
+    // Obtain the scratch pad.
+    const ScratchPadInfo& scratch_pad = rays.scratchpad<ScratchPadInfo>(i);
+    
+    const unsigned int hit_index = scratch_pad.hit_index;
+    
+    const Vectorf &n0 = normals[hit_index][0];
+    const Vectorf &n1 = normals[hit_index][1];
+    const Vectorf &n2 = normals[hit_index][2];
+
+    // Interpolate the normal.
+    const float u = scratch_pad.a;
+    const float v = scratch_pad.b;
+    const Vector normal = (n1 * u) + (n2 * v) + (n0 * (1 - u - v));
+
+    // Set the normal.
+    rays.setNormal(i, normal);
   }
 }
 




  • [MANTA] r875 - trunk/Model/Groups, abe, 01/30/2006

Archive powered by MHonArc 2.6.16.

Top of page