Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1226 - in trunk: Engine/Control Model/Materials SwigInterface UserInterface


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1226 - in trunk: Engine/Control Model/Materials SwigInterface UserInterface
  • Date: Fri, 20 Oct 2006 11:48:59 -0600 (MDT)

Author: bigler
Date: Fri Oct 20 11:48:58 2006
New Revision: 1226

Modified:
   trunk/Engine/Control/RTRT.cc
   trunk/Model/Materials/Phong.cc
   trunk/SwigInterface/wxManta.py
   trunk/UserInterface/XWindowUI.cc
   trunk/UserInterface/XWindowUI.h
Log:

Engine/Control/RTRT.cc

  Progress to a more general shootOneRay.  This function will
  eventually be shootRayPacket, and the number of rays you want will
  be based on the packet you send in.

  I turned off the forcing of the size of the ray packet to 1.  This
  helps when I want to send 4 rays to debug SSE code.

Model/Materials/Phong.cc

  Fixed 64 bit shadow ray mask issue.  Basically you need to use
  integer operations instead of double ones.  This is because the data
  we are working with are pointers and casting pointers to doubles can
  cause weird issues.  I've also included some documentation of what
  this code does, since it is so confusing.  This chuck of code will
  eventually be in a function that can be called from elsewhere, so I
  only have to fix it once.

  I also added some code that helps simulate 64 bit tricks on a 32 bit
  system.  This code will likely go away in the next revision, but I
  wanted a copy in subversion somewhere.

SwigInterface/wxManta.py

  More closely match where a ray is based on the code I found in the
  tiled image traverser and pixel sampler.  It was basically off by a
  pixel.

UserInterface/XWindowUI.cc
UserInterface/XWindowUI.h

  Added ability to shoot debug rays with CTRL-Left Click and SSE debug
  rays with SHIRT-Left Click.


Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Fri Oct 20 11:48:58 2006
@@ -1196,7 +1196,7 @@
 void RTRT::shootOneRay( Color &result_color, RayPacket &result_rays, Real 
image_x, Real image_y, int channel_index ) {
 
   // Only shoot one ray.
-  result_rays.resize( 1 );
+  //  result_rays.resize( 1 );
 
   // Set the image space coordinates of the pixel.
   result_rays.setPixel(0, 0, image_x, image_y);

Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc      (original)
+++ trunk/Model/Materials/Phong.cc      Fri Oct 20 11:48:58 2006
@@ -86,6 +86,10 @@
 
 void Phong::shade(const RenderContext& context, RayPacket& rays) const
 {
+  if (rays.getFlag(RayPacket::DebugPacket)) {
+    cerr << "Phong::shade called\n";
+    cerr << SCIRun::getStackTrace();
+  }
   // Shade a bunch of rays.  We know that they all have the same intersected
   // object and are all of the same material
   
@@ -185,27 +189,84 @@
       RayPacketData* shadowData = shadowRays.data;
       for(;i<e;i+=4){
 
+        // A note about all of this.  We are trying to figure out
+        // which rays are zero.  This is done by checking the hitMatl
+        // pointer for being NULL or not.  If it is NULL then the
+        // shadow ray didn't hit anything and we need to compute the
+        // diffuse and specular components.
+        //
+        // The mask is a funny thing, where (if
+        // !shadowRays.hitMatl[i]) meant "add direct illumination",
+        // for the mask it is opposite.  0 is where we don't want to
+        // add DI.  This is done by comparing the hitMatl pointers
+        // with zero.  If they are 0 then set the mask bits on.
+        //
+        // The 64 bit stuff is harder.  There isn't a good way of
+        // doing 64 bit integer comparisons.  We tried to cast the
+        // pointers to doubles, but this didn't seem to work properly.
+        // Probably because when cast to doubles 0xFFFF...FF is NaN.
+        //
+        // So we do the comparisons on the two halves of the pointer.
+        // In these diagrams, FF represents "bit on" and 00 represents
+        // "bit off".  We need to combine the results of the pairs
+        // (done with the SHUFFLEs later and "and" operator).
+        //
+        // Shadow Pointer  Mask (X == 0)  Mask Composite Result (and)
+        // --------------  ------------- ----------------------
+        // FF FF           00 00         00
+        // FF 00           00 FF         00
+        // 00 FF           FF 00         00
+        // 00 00           FF FF         FF
+        //
+        // 32 bit
+        // FF              00
+        // 00              FF
+        //
+        // So with 64 bit both 32 bit halves need to be 00 for the
+        // hitMatl to be shaded.
+        //
+        // For 32 bit: (mask = !(ShadowPointer == 0) or (mask = 
!ShadowPointer)
+        //
+        // For 64 bit: (mask = !((SP[0] == 0) || (SP[1] == 0)) or
+        //             (mask = !(SP[0] || SP[1])               or
+        //             (mask = !SP[0] && !SP[1])  <- which is what we compute
 #ifdef __x86_64
-
-#if 0
-        __m128 masklo1 = _mm_castpd_ps( 
_mm_cmpeq_pd(_mm_load_pd((double*)&shadowData->hitMatl[i]), _mm_setzero_pd()) 
);
-        __m128 maskhi1 = _mm_castpd_ps( 
_mm_cmpeq_pd(_mm_load_pd((double*)&shadowData->hitMatl[i+2]), 
_mm_setzero_pd()) );
+        // This is the golden code
         
-#else
-        __m128 masklo = _mm_castpd_ps( _mm_cmpeq_pd( 
_mm_set_pd((double)(size_t)shadowData->hitMatl[i+0],
-                                                                
(double)(size_t)shadowData->hitMatl[i+1]),
-                                                     _mm_setzero_pd() ));
-        __m128 maskhi = _mm_castpd_ps( _mm_cmpeq_pd ( 
_mm_set_pd((double)(size_t)shadowData->hitMatl[i+2],
-                                                                 
(double)(size_t)shadowData->hitMatl[i+3] ),
-                                                      _mm_setzero_pd() ));
+        __m128 masklo = 
cast_i2f(_mm_cmpeq_epi32(load44i((__m128i*)&shadowData->hitMatl[i]),
+                                                 _mm_setzero_si128()));
+        __m128 maskhi = 
cast_i2f(_mm_cmpeq_epi32(load44i((__m128i*)&shadowData->hitMatl[i+2]),
+                                                 _mm_setzero_si128()));
+        __m128 mask = _mm_and_ps(_mm_shuffle_ps(masklo, maskhi, 
_MM_SHUFFLE(2, 0, 2, 0)),
+                                 _mm_shuffle_ps(masklo, maskhi, 
_MM_SHUFFLE(3, 1, 3, 1)));
         
-#endif // _mm_load_pd hack
-        __m128 mask = _mm_shuffle_ps(masklo, maskhi, _MM_SHUFFLE(2, 0, 2, 
0));
-
-
-
-#else
-        __m128 mask = 
_mm_cmpeq_ps(_mm_load_ps((float*)&shadowData->hitMatl[i]), _mm_setzero_ps());
+#else // __x86_64
+#ifndef SIMULATE_64BIT
+        __m128 mask = 
cast_i2f(_mm_cmpeq_epi32(load44i((__m128i*)&shadowData->hitMatl[i]), 
_mm_setzero_si128()));
+#else // SIMULATE_64BIT
+        __m128 mask;
+        {
+          bool debug = rays.getFlag(RayPacket::DebugPacket);
+          if (debug) { cerr << "mask  = ";simd_cerr(mask); }
+          
+          if (debug) { cerr << "mask2 = ";simd_cerr(mask); }
+          //        MANTA_ALIGN(16) int vals[8] = {0,0,0,0, 0,0,0,0};
+          MANTA_ALIGN(16) unsigned long long vals[4];
+          
+          for(int j = 0; j < 4; ++j)
+            vals[j] = (unsigned long long)(shadowData->hitMatl[i+j]);
+          __m128 masklo = 
cast_i2f(_mm_cmpeq_epi32(load44i((__m128i*)&vals[0]),
+                                                   _mm_setzero_si128()));
+          __m128 maskhi = 
cast_i2f(_mm_cmpeq_epi32(load44i((__m128i*)&vals[2]),
+                                                   _mm_setzero_si128()));
+          if (debug) { cerr << "masklo = ";simd_cerr(masklo); }
+          if (debug) { cerr << "maskhi = ";simd_cerr(maskhi); }
+          __m128 mask3 = _mm_and_ps(_mm_shuffle_ps(masklo, maskhi, 
_MM_SHUFFLE(2, 0, 2, 0)),
+                                    _mm_shuffle_ps(masklo, maskhi, 
_MM_SHUFFLE(3, 1, 3, 1)));
+          if (debug) { cerr << "mask3 = ";simd_cerr(mask3); cerr << "\n"; }
+          mask = mask3;
+        }
+#endif // SIMULATE_64BIT
 #endif // __x86_64
 
         if(_mm_movemask_ps(mask) == 0)

Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py      (original)
+++ trunk/SwigInterface/wxManta.py      Fri Oct 20 11:48:58 2006
@@ -639,8 +639,8 @@
         # Compute pixel coordinates.
         mouse_pos = event.GetPosition()
         window_size = self.canvas.GetSize()
-        xpos = 2.0*mouse_pos.x/window_size.width - 1.0
-        ypos = 1.0 - 2.0*mouse_pos.y/window_size.height
+        xpos = (2.0*mouse_pos.x+1.0)/window_size.width - 1.0
+        ypos = 1.0 - (2.0*mouse_pos.y+1.0)/window_size.height
 
         self.engine.addTransaction("shootOneRay",
                                    
manta_new(createMantaTransaction(self.shootOneRay, (xpos, ypos, 
self.channelID) )))

Modified: trunk/UserInterface/XWindowUI.cc
==============================================================================
--- trunk/UserInterface/XWindowUI.cc    (original)
+++ trunk/UserInterface/XWindowUI.cc    Fri Oct 20 11:48:58 2006
@@ -8,6 +8,7 @@
 #include <Interface/XWindow.h>
 #include <Interface/Scene.h>
 #include <Interface/Object.h>
+#include <Interface/RayPacket.h>
 #include <Core/Exceptions/ErrnoException.h>
 #include <Core/Exceptions/InternalError.h>
 #include <Core/Exceptions/IllegalArgument.h>
@@ -511,6 +512,12 @@
   register_mouse(0, Button1,
                  "translate",
                  Callback::create(this, &XWindowUI::mouse_translate));
+  register_mouse(ControlMask, Button1,
+                 "Debug ray",
+                 Callback::create(this, &XWindowUI::mouse_debug_ray));
+  register_mouse(ShiftMask, Button1,
+                 "Debug SSE ray",
+                 Callback::create(this, &XWindowUI::mouse_debug_sse_ray));
 }
 
 void XWindowUI::helpkey(unsigned int, unsigned long, int)
@@ -740,6 +747,67 @@
   }
 }
 
+void XWindowUI::mouse_debug_ray(unsigned int, unsigned int,
+                                int event, int channel,
+                                int mouse_x, int mouse_y)
+{
+  if(event != ButtonPress) {
+    return;
+  }
+  XWindow* window = windows[channel];
+  Real image_x = (2.0*mouse_x+1)/window->xres - 1.0;
+  Real image_y = 1.0 - (2.0*mouse_y+1)/window->yres;
+  //  std::cerr << "Debug ray at ("<<image_x<<", "<<image_y<<")\n";
+  std::cerr << "Debug ray at ("<<mouse_x<<", "<<mouse_y<<")\n";
+
+  RayPacketData data;
+  RayPacket rays( data, RayPacket::UnknownShape, 0, 1, 0, 0 );
+
+  rays.setFlag( RayPacket::DebugPacket );
+
+       // Shoot the ray.
+       Color color;
+       rtrt_interface->shootOneRay( color, rays, image_x, image_y, channel );
+
+  if (rays.wasHit(0)) {
+    std::cerr << "t:       " << rays.getMinT(0) << "\n";
+    std::cerr << "hit pos: " << rays.getHitPosition(0) << "\n";
+  }
+}
+
+void XWindowUI::mouse_debug_sse_ray(unsigned int, unsigned int,
+                                    int event, int channel,
+                                    int mouse_x, int mouse_y)
+{
+  if(event != ButtonPress) {
+    return;
+  }
+  XWindow* window = windows[channel];
+  RayPacketData data;
+  RayPacket rays( data, RayPacket::LinePacket, 0, 4, 0, 0 );
+
+  Real image_x = (2.0*mouse_x+1)/window->xres - 1.0;
+  Real image_y = 1.0 - (2.0*mouse_y+1)/window->yres;
+  for(int i = 0; i < 4; ++i) {
+    Real x = (2.0*mouse_x+i+1)/window->xres - 1.0;
+    rays.setPixel(i, 0, x, image_y);
+  }
+  //  std::cerr << "Debug ray at ("<<image_x<<", "<<image_y<<")\n";
+  std::cerr << "Debug sse ray at ("<<mouse_x<<", "<<mouse_y<<")\n";
+
+  rays.setFlag( RayPacket::DebugPacket );
+
+       // Shoot the ray.
+       Color color;
+       rtrt_interface->shootOneRay( color, rays, image_x, image_y, channel );
+
+  for(int i = 0; i < 4; ++i) {
+    if (rays.wasHit(i)) {
+      std::cerr << "t("<<i<<"):       " << rays.getMinT(i) << "\n";
+      std::cerr << "hit pos("<<i<<"): " << rays.getHitPosition(i) << "\n";
+    }
+  }
+}
 
 void XWindowUI::handle_event(XEvent& e)
 {

Modified: trunk/UserInterface/XWindowUI.h
==============================================================================
--- trunk/UserInterface/XWindowUI.h     (original)
+++ trunk/UserInterface/XWindowUI.h     Fri Oct 20 11:48:58 2006
@@ -90,6 +90,8 @@
     void mouse_translate(unsigned int, unsigned int, int, int, int, int);
     void mouse_dolly(unsigned int, unsigned int, int, int, int, int);
     void mouse_rotate(unsigned int, unsigned int, int, int, int, int);
+    void mouse_debug_ray(unsigned int, unsigned int, int, int, int, int);
+    void mouse_debug_sse_ray(unsigned int, unsigned int, int, int, int, int);
 
     void animation_callback(int, int, bool&);
 




  • [MANTA] r1226 - in trunk: Engine/Control Model/Materials SwigInterface UserInterface, bigler, 10/20/2006

Archive powered by MHonArc 2.6.16.

Top of page