Text archives Help
- From: boulos@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1489 - trunk/Engine/PixelSamplers
- Date: Tue, 17 Jul 2007 17:41:49 -0600 (MDT)
Author: boulos
Date: Tue Jul 17 17:41:49 2007
New Revision: 1489
Modified:
trunk/Engine/PixelSamplers/JitterSampler.cc
Log:
Engine/PixelSamplers/JitterSampler.cc
Using new Packet sample interface (nice speedup for 16 spp)
Modified: trunk/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.cc Tue Jul 17 17:41:49 2007
@@ -19,7 +19,7 @@
PixelSampler* JitterSampler::create(const vector<string>& args)
{
-
+
return new JitterSampler(args);
}
@@ -31,14 +31,14 @@
string arg = args[i];
if(arg == "-numberOfSamples"){
if(!getIntArg(i, args, num_samples))
- throw IllegalArgument("JitterSampler -numberOfSamples", i, args);
+ throw IllegalArgument("JitterSampler -numberOfSamples", i, args);
if (num_samples < 1)
throw IllegalArgument("-numberOfSamples must be greater than 0",
i, args);
} else if (arg == "-nocheap") {
use_cheaprng = false;
}
-
+
else {
throw IllegalArgument("JitterSampler", i, args);
}
@@ -71,7 +71,7 @@
ci.yscale = ci.xscale;
ci.xoffset = (-ci.xres+1)*(Real)0.5*ci.xscale; // Offset to pixel center
ci.yoffset = (-ci.yres+1)*(Real)0.5*ci.yscale;
-
+
context.renderer->setupDisplayChannel(context);
}
@@ -114,7 +114,7 @@
// Pick up left over fragments. It is OK if this is a partial sum.
// The remaining sum will be picked up in the next call to
// computeAverages.
- if (samples_collected > 0)
+ if (samples_collected > 0)
fragment.addColor(current_fragment, fragment_color / num_samples);
// Assign the values back to the parameters.
@@ -123,11 +123,11 @@
}
void JitterSampler::renderFragment(const RenderContext& context,
- Fragment& fragment)
+ Fragment& fragment)
{
ChannelInfo& ci = channelInfo[context.channelIndex];
int thd_num = context.proc;
-
+
int flags = RayPacket::HaveImageCoordinates;
if(fragment.getFlag(Fragment::ConstantEye))
flags |= RayPacket::ConstantEye;
@@ -150,13 +150,23 @@
Real inx = (Real)1/nx;
Real iny = (Real)1/ny;
Real px, py;
-
+
int sample_count = 0;
// No samples accumulated yet.
int samples_collected = 0;
// Index to the first fragment's element.
int current_fragment = 0;
+ Packet<Real> r1;
+ Packet<Real> r2;
+ if (use_cheaprng) {
+ rng.nextPacket(r1);
+ rng.nextPacket(r2);
+ } else {
+ random[thd_num].nextPacket(r1);
+ random[thd_num].nextPacket(r2);
+ }
+
// We can compute at most RayPacket::MaxSize number of rays at time.
for(int frag_index = fragment.begin(); frag_index < fragment.end();
frag_index++) {
// Initialize the color
@@ -168,32 +178,22 @@
else
random[thd_num].seed(fragment.getX(frag_index)*ci.xres+fragment.getY(frag_index));
}
-
+
// For each fragment start filling up the RayPacket with samples.
// When you filled up the empty_slots compute the rays, do the
// average, and store the results in the fragment.
int fx = fragment.getX(frag_index);
int fy = fragment.getY(frag_index);
- for(int xs = 0; xs < nx; xs++)
- for(int ys = 0; ys < ny; ys++)
- {
- Real x_sample, y_sample;
- if (use_cheaprng) {
- // I'm using the float version, because it seems to make a
- // differnce in performance. This is likely due the
- // compiler's ability to inline all the necessary
- // functions which using next<Real> prevents.
- x_sample = (xs + rng.nextFloat()) * inx;
- y_sample = (ys + rng.nextFloat()) * iny;
- } else {
- x_sample = (xs + random[thd_num].next<Real>()) * inx;
- y_sample = (ys + random[thd_num].next<Real>()) * iny;
- }
+ for(int xs = 0; xs < nx; xs++) {
+ for(int ys = 0; ys < ny; ys++) {
+ Real x_sample = (xs + r1.get(sample_count)) * inx;
+ Real y_sample = (ys + r2.get(sample_count)) * iny;
+
px = (fx+x_sample)*ci.xscale+ci.xoffset;
py = (fy+y_sample)*ci.yscale+ci.yoffset;
rays.setPixel(sample_count, 0, px, py);
sample_count++;
-
+
if (sample_count == RayPacket::MaxSize) {
// Filled up the ray packet, so send them off!
rays.resize(sample_count);
@@ -201,23 +201,33 @@
computeAverages(fragment, rays,
samples_collected, current_fragment);
-
+
// Now reset the index, so that we can start filling up
// the RayPacket again.
sample_count = 0;
+
+ // Grab more samples
+ if (use_cheaprng) {
+ rng.nextPacket(r1);
+ rng.nextPacket(r2);
+ } else {
+ random[thd_num].nextPacket(r1);
+ random[thd_num].nextPacket(r2);
+ }
// Make sure we start with a fresh slate
rays.resetHits();
rays.setAllFlags(flags);
- }
- } // end sample filling loops
+ } // end packet shoot and reset test
+ }
+ } // end sample filling loops
} // end fragment loop
// Pick up any stragling samples
if (sample_count > 0) {
rays.resize(sample_count);
context.renderer->traceEyeRays(context, rays);
-
+
computeAverages(fragment, rays,
samples_collected, current_fragment);
}
-}
+}
- [MANTA] r1489 - trunk/Engine/PixelSamplers, boulos, 07/17/2007
Archive powered by MHonArc 2.6.16.