Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1233 - in trunk/Model: Groups Materials


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1233 - in trunk/Model: Groups Materials
  • Date: Fri, 10 Nov 2006 19:43:37 -0700 (MST)

Author: boulos
Date: Fri Nov 10 19:43:35 2006
New Revision: 1233

Modified:
   trunk/Model/Groups/DynBVH.cc
   trunk/Model/Materials/Flat.cc
Log:
Fixing a bug in the BVH code where min_org and
max_org were not properly initialized.

Changing Flat Material to be more like DynBVHs
EyelightShader.

Manta is now faster than DynBVH on my laptop.


Modified: trunk/Model/Groups/DynBVH.cc
==============================================================================
--- trunk/Model/Groups/DynBVH.cc        (original)
+++ trunk/Model/Groups/DynBVH.cc        Fri Nov 10 19:43:35 2006
@@ -22,6 +22,8 @@
     {
         ia_data.min_rcp[axis]     =  std::numeric_limits<float>::max();
         ia_data.max_rcp[axis]     = -std::numeric_limits<float>::max();
+        ia_data.min_org[axis]     =  std::numeric_limits<float>::max();
+        ia_data.max_org[axis]     = -std::numeric_limits<float>::max();
         ia_data.min_org_rcp[axis] =  std::numeric_limits<float>::max();
         ia_data.max_org_rcp[axis] = -std::numeric_limits<float>::max();
     }
@@ -234,9 +236,16 @@
 
                 // [a,b] is valid intersection interval so a is min
                 // and b is max t-value
-                // TODO(boulos): Replace these std::min calls
-                a = std::min(ar0, std::min(ar1, std::min(br0, br1)));
-                b = std::max(ar0, std::max(ar1, std::max(br0, br1)));
+
+                //a = std::min(ar0, std::min(ar1, std::min(br0, br1)));
+                a = (br0 < br1) ? br0 : br1;
+                a = (a   < ar1) ?   a : ar1;
+                a = (a   < ar0) ?   a : ar0;
+
+                //b = std::max(ar0, std::max(ar1, std::max(br0, br1)));
+                b = (br0 < br1) ? br1 : br0;
+                b = (b   < ar1) ? ar1 : b;
+                b = (b   < ar0) ? ar0 : b;
 #else //box * rcpIA - org_rcpIA
                 float a = box[0][axis]*ia_data.min_rcp[axis];
                 float b = box[0][axis]*ia_data.max_rcp[axis];
@@ -276,7 +285,7 @@
     // process simds now
 
     // TODO(boulos): replace operator overloads with direct access
-#if 0
+#if 1
     int pack_begin = sse_begin >> 2;
     int pack_end   = sse_end   >> 2;
     __m128 box_x0 = _mm_set1_ps(box[0][0]);
@@ -424,7 +433,7 @@
 int DynBVH::lastIntersects(const BBox& box, const RayPacket& rays) const
 {
     // TODO(boulos): Consider adding SIMD march here too
-    for (int ray = rays.end() - 1; ray >= rays.begin(); ray-- )
+    for (int ray = rays.end() - 1; ray > rays.begin(); ray-- )
     {
         float maximum_minimum = 1e-5;
         float minimum_maximum = rays.getMinT(ray);

Modified: trunk/Model/Materials/Flat.cc
==============================================================================
--- trunk/Model/Materials/Flat.cc       (original)
+++ trunk/Model/Materials/Flat.cc       Fri Nov 10 19:43:35 2006
@@ -57,12 +57,51 @@
 
 void Flat::shade(const RenderContext& context, RayPacket& rays) const
 {
-
+  rays.normalizeDirections();
+  rays.computeFFNormals(context);
   // Compute colors
   Packet<Color> colors;
   colortex->mapValues(colors, context, rays);
 
+#ifndef MANTA_SSE
   // Copy the colors into the ray packet.
-  for(int i=rays.begin();i<rays.end();i++)
-    rays.setColor( i, colors.get(i) );
+  for(int i=rays.begin();i<rays.end();i++) {
+    ColorComponent cosine = fabs(Dot(rays.getFFNormal(i), 
rays.getDirection(i)));
+    rays.setColor( i, colors.get(i) * cosine );
+  }
+#else
+  int b = (rays.rayBegin + 3) & ~3;
+  int e = (rays.rayEnd) & ~3;
+  if (b == e) {
+    for (int i = rays.begin(); i < rays.end(); i++) {
+      ColorComponent cosine = fabs(Dot(rays.getFFNormal(i), 
rays.getDirection(i)));
+      rays.setColor(i, colors.get(i) * cosine);
+    }
+  } else {
+    int i = rays.rayBegin;
+    for (; i < b; i++) {
+      ColorComponent cosine = fabs(Dot(rays.getFFNormal(i), 
rays.getDirection(i)));
+      rays.setColor(i, colors.get(i) * cosine);
+    }
+    // SIMD now
+    RayPacketData* data = rays.data;
+    for (; i < e; i+= 4) {
+      __m128 dot = _mm_mul_ps(_mm_set_ps1(-1.f),
+                              
_mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_load_ps(&data->direction[0][i]),
+                                                               
_mm_load_ps(&data->ffnormal[0][i])),
+                                                    
_mm_mul_ps(_mm_load_ps(&data->direction[1][i]),
+                                                               
_mm_load_ps(&data->ffnormal[1][i]))),
+                                         
_mm_mul_ps(_mm_load_ps(&data->direction[2][i]),
+                                                    
_mm_load_ps(&data->ffnormal[2][i]))));
+
+      _mm_store_ps(&data->color[0][i], _mm_mul_ps(dot, 
_mm_load_ps(&colors.colordata[0][i])));
+      _mm_store_ps(&data->color[1][i], _mm_mul_ps(dot, 
_mm_load_ps(&colors.colordata[1][i])));
+      _mm_store_ps(&data->color[2][i], _mm_mul_ps(dot, 
_mm_load_ps(&colors.colordata[2][i])));
+    }
+    for (; i < rays.rayEnd; i++) {
+      ColorComponent cosine = fabs(Dot(rays.getFFNormal(i), 
rays.getDirection(i)));
+      rays.setColor(i, colors.get(i) * cosine);
+    }
+  }
+#endif
 }




  • [MANTA] r1233 - in trunk/Model: Groups Materials, boulos, 11/10/2006

Archive powered by MHonArc 2.6.16.

Top of page