Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r376 - swig/Engine/PixelSamplers


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r376 - swig/Engine/PixelSamplers
  • Date: Fri, 10 Jun 2005 18:09:12 -0600 (MDT)

Author: bigler
Date: Fri Jun 10 18:09:11 2005
New Revision: 376

Modified:
   swig/Engine/PixelSamplers/JitterSampler.cc
Log:

Use the new prototype code (that is now fixed).  Remove the old
implementation.  It wouldn't allow you to use more than
RayPacket::MaxSize number of samples anyway.  I've tested up to 100
with the new code.


Modified: swig/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- swig/Engine/PixelSamplers/JitterSampler.cc  (original)
+++ swig/Engine/PixelSamplers/JitterSampler.cc  Fri Jun 10 18:09:11 2005
@@ -80,7 +80,15 @@
 }
 
 
-
+// Ohh, man.  Is this code wacked or what?  Anyway, the point of this
+// code it to gather up all the samples that belong to a single
+// fragment, then update the color in the fragment.  Fagments' samples
+// can exists across multiple RayPackets, so we have to be careful
+// here.  Also with the way the loop works you have to make sure you
+// pick up the last sample if it is part of a newrun (see
+// compute_last_ave below).  Anyway, I know there is probably a more
+// elegant solution out there, but this works for all sorts of
+// combinations of fragment sizes and number of samples.
 void JitterSampler::computeAverages(Fragment& fragment, RayPacket& rays,
                                     Color* sample_color,
                                     int* fragment_owning_sample) {
@@ -93,29 +101,27 @@
   int num_samples_per_fragment = 1;
   int current_fragment = fragment_owning_sample[slot_index];
   Color fragment_color = sample_color[slot_index];
-  cerr << "=============================================================\n";
-  cerr << "rays.getSize() = "<<rays.getSize()<<"\n";
-  //  cerr << "slot_index = "<<slot_index<<", num_samples_per_fragment = 
"<<num_samples_per_fragment<<", "<<current_fragment<<"\n";
-  for(slot_index = 1; slot_index < rays.getSize(); slot_index++){
-    cerr << "slot_index = "<<slot_index<<", nspf = 
"<<num_samples_per_fragment<<", cf = "<<current_fragment<<", 
fragment_owning_sample_own_samp["<<slot_index<<"] = 
"<<fragment_owning_sample[slot_index]<<"\n";
+  // If the last sample is a new run, you need to add it after the for loop.
+  bool compute_last_ave = false; 
+  for(int slot_index = 1; slot_index < rays.getSize(); slot_index++){
     bool compute_average = false;
     if (current_fragment == fragment_owning_sample[slot_index]) {
-      cerr << "current_fragment == fragment_owning_sample[slot_index]\n";
       fragment_color += sample_color[slot_index];
       num_samples_per_fragment++;
       // Now the case where the last sample is has been
       // reached, we must force it to be averaged.
-      if (slot_index == rays.getSize()-1) {
-        cerr << "slot_index == rays.getSize()-1\n";
+      if (slot_index == rays.getSize()-1)
         compute_average = true;
-      }
     } else {
       // Now we have a break in the fragment, so time to
       // compute the average.
       compute_average = true;
+      // If however we have a break at the last pixel, we need to
+      // signal to pick up that extra sample.
+      if (slot_index == rays.getSize()-1)
+        compute_last_ave = true;
     }
     if (compute_average) {
-      cerr << "computing average for fragment " << current_fragment <<"\n";
       // Divide the color by the number of samples and
       // increment it with the fragment.
       fragment.get(current_fragment).color +=
@@ -126,9 +132,11 @@
       num_samples_per_fragment = 1;
     }
   } // end slot_index loop
-}
 
-#if 0
+  // Pick up the last sample if we need to
+  if (compute_last_ave)
+    fragment.get(current_fragment).color += fragment_color / num_samples;
+}
 
 void JitterSampler::renderFragment(const RenderContext& context,
                                   Fragment& fragment)
@@ -146,10 +154,10 @@
 
   int consecutivex_flag = fragment.getFlags() & Fragment::ConsecutiveX;
 
-//   if (consecutivex_flag) {
-//     Fragment::Element& fe = fragment.get(0);
-//     random[thd_num].seed_rng(fe.x*ci.xres+fe.y);
-//   }
+  if (consecutivex_flag) {
+    Fragment::Element& fe = fragment.get(0);
+    random[thd_num].seed_rng(fe.x*ci.xres+fe.y);
+  }
 
   int depth = 0;
   RayPacketData raydata;
@@ -178,15 +186,16 @@
         {
           Real x_sample = (xs + random[thd_num].genRealRand<Real>()) * inx;
           Real y_sample = (ys + random[thd_num].genRealRand<Real>()) * iny;
-          px = ((fe0.x+(x_sample))*ci.xscale+ci.xoffset);
-          py =  (fe0.y+(y_sample))*ci.yscale+ci.yoffset;
+          px = (fe0.x+(x_sample))*ci.xscale+ci.xoffset;
+          py = (fe0.y+(y_sample))*ci.yscale+ci.yoffset;
           rays.setPixel(next_slot, 0, px, py, &sample_color[next_slot]);
           fragment_owning_sample[next_slot] = frag_index;
           next_slot++;
           
           if (next_slot == RayPacket::MaxSize) {
+            // Filled up the ray packet, so send them off!
             rays.resize(next_slot);
-            (context.renderer->traceEyeRays(context, rays));
+            context.renderer->traceEyeRays(context, rays);
 
             computeAverages(fragment, rays,
                             sample_color, fragment_owning_sample);
@@ -204,105 +213,11 @@
   // Pick up any stragling samples
   if (next_slot > 0) {
     rays.resize(next_slot);
-    (context.renderer->traceEyeRays(context, rays));
+    context.renderer->traceEyeRays(context, rays);
     
     computeAverages(fragment, rays, sample_color, fragment_owning_sample);
   }
 }  
-#else
-void JitterSampler::renderFragment(const RenderContext& context,
-                                  Fragment& fragment)
-{
-  ChannelInfo& ci = channelInfo[context.channelIndex];
-  int thd_num = context.proc;
-    
-  int flags = RayPacket::HaveImageCoordinates;
-  if(fragment.getFlags() & Fragment::ConstantEye)
-    flags |= RayPacket::ConstantEye;
-  
-
-  for(int f=0;f<fragment.getSize();f+=(RayPacket::MaxSize)/num_samples) {
-    int size = RayPacket::MaxSize;
-
-    // Create a ray packet
-    int depth = 0;
-    RayPacketData raydata;
-    RayPacket rays(raydata, size, depth, flags);
-    Color result[RayPacket::MaxSize];
-    if(fragment.getFlags() & Fragment::ConsecutiveX) {
-      Fragment::Element& fe0 = fragment.get(f);
-      random[thd_num].seed_rng(fe0.x*ci.xres+fe0.y);
-      int i = 0;
-      int count = 0;
-      Real px, py;
-      Real inx = (Real)1/nx;
-      Real iny = (Real)1/ny;
-      
-      while(i < size){
-        for(int xs = 0; xs < nx; xs++)
-          for(int ys = 0; ys  < ny; ys++)
-         {
-            Real x_sample = (xs + random[thd_num].genRealRand<Real>()) * inx;
-            Real y_sample = (ys + random[thd_num].genRealRand<Real>()) * iny;
-           px = ((fe0.x+(x_sample))*ci.xscale+ci.xoffset)+count*ci.xscale;
-           py =  (fe0.y+(y_sample))*ci.yscale+ci.yoffset;
-           rays.setPixel(i, 0, px, py, &result[i]);
-           i++;
-         } 
-       
-       if(i%num_samples == 0){
-         count++;
-       }
-      }
-    } else {
-      
-      int i = 0;
-      int count = 0;
-      Real px, py;
-      Real inx = (Real)1/nx;
-      Real iny = (Real)1/ny;
-
-      while(i < size){
-       Fragment::Element& fe0 = fragment.get(f+i);
-        random[thd_num].seed_rng(fe0.x*ci.xres+fe0.y);
-        for(int xs = 0; xs < nx; xs++)
-          for(int ys = 0; ys  < ny; ys++)
-         {
-            Real x_sample = (xs + random[thd_num].genRealRand<Real>()) * inx;
-            Real y_sample = (ys + random[thd_num].genRealRand<Real>()) * iny;
-           px = ((fe0.x+x_sample)*ci.xscale+ci.xoffset)+count*ci.xscale;
-           py =  (fe0.y+y_sample)*ci.yscale+ci.yoffset;
-           rays.setPixel(i, 1, px, py, &result[i]);
-           i++;
-         } 
-       
-       if(i%num_samples == 0){
-         count++;
-       }
-       
-      }
-    }
-    
-    // Trace the rays.  The results will automatically go into the fragment
-    (context.renderer->traceEyeRays(context, rays));
-    
-    int element_index = 0;
-    
-    ColorComponent inv_num_samples = (ColorComponent)1/num_samples;
-    for(int k = 0; k < size; k+=num_samples) {
-      Color final_col = result[k];
-      for(int l = 1; l < num_samples; l++) {
-        final_col += result[k+l];
-      }
-      
-      Fragment::Element& fe = fragment.get(f+element_index);
-      fe.color = final_col * inv_num_samples;
-      element_index++;
-    }
-    
-  } // end fragment iterator
-}
-#endif
 
 
 




  • [MANTA] r376 - swig/Engine/PixelSamplers, bigler, 06/10/2005

Archive powered by MHonArc 2.6.16.

Top of page