Text archives Help
- From: rocky@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r390 - in branches/itanium2: Core/Math Engine/Display Engine/PixelSamplers
- Date: Thu, 16 Jun 2005 15:18:06 -0600 (MDT)
Author: rocky
Date: Thu Jun 16 15:17:50 2005
New Revision: 390
Modified:
branches/itanium2/Core/Math/MT_RNG.cc
branches/itanium2/Core/Math/MT_RNG.h
branches/itanium2/Core/Math/vector2d.h
branches/itanium2/Engine/Display/FileDisplay.cc
branches/itanium2/Engine/PixelSamplers/HammersleySampler.cc
branches/itanium2/Engine/PixelSamplers/InterLeaveSampler.cc
branches/itanium2/Engine/PixelSamplers/JitterSampler.cc
branches/itanium2/Engine/PixelSamplers/JitterSampler.h
branches/itanium2/Engine/PixelSamplers/MultiJitterSampler.cc
branches/itanium2/Engine/PixelSamplers/NRooksSampler.cc
branches/itanium2/Engine/PixelSamplers/Sample.cc
branches/itanium2/Engine/PixelSamplers/Sample.h
branches/itanium2/Engine/PixelSamplers/SingleSampler.cc
Log:
updated jittersample code from main trunk and add thread test to
FileDisplay::imageDisplay
Modified: branches/itanium2/Core/Math/MT_RNG.cc
==============================================================================
--- branches/itanium2/Core/Math/MT_RNG.cc (original)
+++ branches/itanium2/Core/Math/MT_RNG.cc Thu Jun 16 15:17:50 2005
@@ -29,7 +29,9 @@
/* matumoto@math.keio.ac.jp */
#include <stdio.h> // used only for test_print
-#include "MT_RNG.h"
+#include <Core/Math/MT_RNG.h>
+
+using namespace Manta;
/* Period parameters */
#define MATRIX_A 0x9908b0df /* constant vector a */
@@ -110,5 +112,17 @@
if (j%8==7) printf("\n");
}
printf("\n");
+}
+
+template<>
+float MT_RNG::genRealRand<float>()
+{
+ return genfrand();
+}
+
+template<>
+double MT_RNG::genRealRand<double>()
+{
+ return gendrand();
}
Modified: branches/itanium2/Core/Math/MT_RNG.h
==============================================================================
--- branches/itanium2/Core/Math/MT_RNG.h (original)
+++ branches/itanium2/Core/Math/MT_RNG.h Thu Jun 16 15:17:50 2005
@@ -31,7 +31,7 @@
#ifndef __MT19937_H__
#define __MT19937_H__
-
+namespace Manta {
// Period parameters
#define MT_RNG_N 624
@@ -47,7 +47,21 @@
double gendrand();
float genfrand();
+ // Default to returning a double. In actuallity this should never
+ // be used.
+ template<class T>
+ T genRealRand() { return static_cast<T>(gendrand()); }
+
+
void test_print(); // prints some random numbers to the console
};
+
+template<>
+float MT_RNG::genRealRand<float>();
+
+template<>
+double MT_RNG::genRealRand<double>();
+
+} // end namespace Manta
#endif // __MT19937_H__
Modified: branches/itanium2/Core/Math/vector2d.h
==============================================================================
--- branches/itanium2/Core/Math/vector2d.h (original)
+++ branches/itanium2/Core/Math/vector2d.h Thu Jun 16 15:17:50 2005
@@ -4,47 +4,13 @@
#ifndef Manta_Core_vector2d_h
#define Manta_Core_vector2d_h
-class vector2d {
-public:
- vector2d()
- {
- e[0] = 0.0;
- e[1] = 0.0;
- }
-
-
- vector2d(float a, float b)
- {
- e[0] = a;
- e[1] = b;
- }
-
- //vector3d(double e0, double e1, double e2);
-
- void setX(float num)
- {
- e[0] = num;
- }
-
- void setY(float num)
- {
- e[1] = num;
- }
-
- float x()
- {
- return e[0];
- }
-
- float y()
- {
- return e[1];
- }
-
- float e[2];
-};
+#include <MantaTypes.h>
+#include <Core/Geometry/PointVector.h>
+namespace Manta {
+ typedef VectorT<Real, 2> vector2d;
+} // end namespace Manta
#endif
Modified: branches/itanium2/Engine/Display/FileDisplay.cc
==============================================================================
--- branches/itanium2/Engine/Display/FileDisplay.cc (original)
+++ branches/itanium2/Engine/Display/FileDisplay.cc Thu Jun 16 15:17:50
2005
@@ -10,6 +10,7 @@
#include <Image/Pixel.h>
#include <Image/SimpleImage.h>
#include <Image/TGAFile.h>
+#include <Interface/Context.h>
using namespace Manta;
using namespace std;
@@ -44,6 +45,9 @@
const DisplayContext &context,
const Image *image )
{
+ if(context.proc != 0)
+ return;
+
bool stereo;
int xres, yres;
image->getResolution( stereo, xres, yres );
Modified: branches/itanium2/Engine/PixelSamplers/HammersleySampler.cc
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/HammersleySampler.cc (original)
+++ branches/itanium2/Engine/PixelSamplers/HammersleySampler.cc Thu Jun 16
15:17:50 2005
@@ -123,8 +123,8 @@
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+samples[x].e[0])*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+samples[x].e[1])*ci.yscale+ci.yoffset;
+ px = ((fe0.x+samples[x][0])*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py = (fe0.y+samples[x][1])*ci.yscale+ci.yoffset;
rays.setPixel(i, 0, px, py, &result[i]);
i++;
@@ -152,8 +152,8 @@
Sample::hammersley(samples, num_samples, random[thd_num]);
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+samples[x].e[0])*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+samples[x].e[1])*ci.yscale+ci.yoffset;
+ px = ((fe0.x+samples[x][0])*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py = (fe0.y+samples[x][1])*ci.yscale+ci.yoffset;
rays.setPixel(i, 1, px, py, &result[i]);
i++;
Modified: branches/itanium2/Engine/PixelSamplers/InterLeaveSampler.cc
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/InterLeaveSampler.cc (original)
+++ branches/itanium2/Engine/PixelSamplers/InterLeaveSampler.cc Thu Jun 16
15:17:50 2005
@@ -128,8 +128,8 @@
while(i < size){
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+interLeavedSamples[i%num_grid][x].e[0])*ci.xscale+ci.xoffset)+count*ci.xscale;
- py =
(fe0.y+interLeavedSamples[i%num_grid][x].e[1])*ci.yscale+ci.yoffset;
+ px =
((fe0.x+interLeavedSamples[i%num_grid][x][0])*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py =
(fe0.y+interLeavedSamples[i%num_grid][x][1])*ci.yscale+ci.yoffset;
rays.setPixel(i, 0, px, py, &result[i]);
i++;
@@ -154,8 +154,8 @@
Fragment::Element& fe0 = fragment.get(f+i);
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+interLeavedSamples[i%num_grid][x].e[0])*ci.xscale+ci.xoffset)+count*ci.xscale;
- py =
(fe0.y+interLeavedSamples[i%num_grid][x].e[1])*ci.yscale+ci.yoffset;
+ px =
((fe0.x+interLeavedSamples[i%num_grid][x][0])*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py =
(fe0.y+interLeavedSamples[i%num_grid][x][1])*ci.yscale+ci.yoffset;
rays.setPixel(i, 1, px, py, &result[i]);
i++;
Modified: branches/itanium2/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/JitterSampler.cc (original)
+++ branches/itanium2/Engine/PixelSamplers/JitterSampler.cc Thu Jun 16
15:17:50 2005
@@ -13,6 +13,11 @@
using namespace Manta;
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+using namespace std;
+
PixelSampler* JitterSampler::create(const vector<string>& args)
{
@@ -22,42 +27,35 @@
JitterSampler::JitterSampler(const vector<string>& args)
{
num_samples = 4;
- samples = 0;
int argc = static_cast<int>(args.size());
for(int i = 0; i<argc;i++){
string arg = args[i];
if(arg == "-numberOfSamples"){
if(!getIntArg(i, args, num_samples))
throw IllegalArgument("JitterSampler -numberOfSamples", i, args);
+ if (num_samples < 1)
+ throw IllegalArgument("-numberOfSamples must be greater than 0",
+ i, args);
}
else {
throw IllegalArgument("JitterSampler", i, args);
}
}
- if (num_samples > 25)
- {
- printf("Maximum number of samples allowed is 25\n\n");
- exit(0);
- }
+
+ // Compute nx and ny
+ Sample::nearest_square_finder(num_samples, nx, ny);
}
JitterSampler::~JitterSampler()
{
- delete [] samples;
+ if (random) delete[] random;
}
void JitterSampler::setupBegin(const SetupContext& context, int numChannels)
{
channelInfo.resize(numChannels);
random = new MT_RNG[context.numProcs];
- for(int i = 0; i < context.numProcs; i++)
- {
- random[i] = MT_RNG();
- random[i].seed_rng((unsigned long) i);
- }
- if(samples == 0)
- samples = new vector2d[num_samples];
context.renderer->setupBegin(context, numChannels);
}
@@ -65,14 +63,13 @@
{
ChannelInfo& ci = channelInfo[context.channelIndex];
bool stereo;
- int xres, yres;
- context.getResolution(stereo, xres, yres);
+ context.getResolution(stereo, ci.xres, ci.yres);
// Set up the scale from -1 to 1
- ci.xscale = 2./xres;
+ ci.xscale = (Real)2/ci.xres;
ci.yscale = ci.xscale;
- ci.xoffset = (-xres/2.+0.5)*ci.xscale; // Offset to pixel center
- ci.yoffset = (-yres/2.+0.5)*ci.yscale;
+ 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);
}
@@ -83,6 +80,63 @@
}
+// 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) {
+ // At this point we have rays.getSize() number of samples
+ // that can belong to at most fragment.getSize() number of
+ // fragments. We need to sum the colors from the samples
+ // for a single fragment then divide it by the total
+ // number of samples and add it to the fragment's total.
+ int slot_index = 0;
+ int num_samples_per_fragment = 1;
+ int current_fragment = fragment_owning_sample[slot_index];
+ Color fragment_color = sample_color[slot_index];
+ // 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]) {
+ 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)
+ 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) {
+ // Divide the color by the number of samples and
+ // increment it with the fragment.
+ fragment.get(current_fragment).color +=
+ fragment_color / num_samples;
+ // Now update for the next fragment run
+ fragment_color = sample_color[slot_index];
+ current_fragment = fragment_owning_sample[slot_index];
+ num_samples_per_fragment = 1;
+ }
+ } // end slot_index loop
+
+ // 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)
@@ -93,91 +147,77 @@
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;
+ int next_slot = 0;
+ Color sample_color[RayPacket::MaxSize];
+ int fragment_owning_sample[RayPacket::MaxSize];
+
+ 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);
+ }
- // 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);
- int i = 0;
- int count = 0;
- double px, py;
- while(i < size){
- Sample::jitter(samples, num_samples, random[thd_num]);
-
- for(int x = 0; x < num_samples; x++)
- {
- px =
((fe0.x+(samples[x].e[0]))*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+(samples[x].e[1]))*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;
-
- double px, py;
- while(i < size){
- Fragment::Element& fe0 = fragment.get(f+i);
-
-
- Sample::jitter(samples, num_samples, random[thd_num]);
- for(int x = 0; x < num_samples; x++)
- {
- px =
((fe0.x+samples[x].e[0])*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+samples[x].e[1])*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;
-
- float inv_num_samples = 1.0f/num_samples;
- for(int k = 0; k < size; k+=num_samples)
- {
- Color final_col = Color::black();
- for(int l = 0; 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++;
-
- }
+ int depth = 0;
+ RayPacketData raydata;
+ RayPacket rays(raydata, RayPacket::MaxSize, depth, flags);
+
+ Real inx = (Real)1/nx;
+ Real iny = (Real)1/ny;
+ Real px, py;
+
+ // We can compute at most RayPacket::MaxSize number of rays at time.
+ for(int frag_index = 0; frag_index < fragment.getSize(); frag_index++) {
+ // Initialize the color
+ fragment.get(frag_index).color = Color::black();
+
+ Fragment::Element& fe0 = fragment.get(frag_index);
+
+ if (!consecutivex_flag) {
+ random[thd_num].seed_rng(fe0.x*ci.xres+fe0.y);
+ }
+
+ // 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.
+ 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;
+ 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);
+
+ computeAverages(fragment, rays,
+ sample_color, fragment_owning_sample);
+
+ // Now reset the index, so that we can start filling up
+ // the RayPacket again.
+ next_slot = 0;
+ // Make sure we start with a fresh slate
+ rays.resetHit();
+ // rays.resetFlag(flags);
+ }
+ } // end sample filling loops
+ } // end fragment loop
+
+ // Pick up any stragling samples
+ if (next_slot > 0) {
+ rays.resize(next_slot);
+ context.renderer->traceEyeRays(context, rays);
+ computeAverages(fragment, rays, sample_color, fragment_owning_sample);
}
-
-
-}
+}
Modified: branches/itanium2/Engine/PixelSamplers/JitterSampler.h
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/JitterSampler.h (original)
+++ branches/itanium2/Engine/PixelSamplers/JitterSampler.h Thu Jun 16
15:17:50 2005
@@ -14,6 +14,8 @@
namespace Manta {
using namespace std;
+ class RayPacket;
+
class JitterSampler : public PixelSampler {
public:
JitterSampler(const vector<string>& args);
@@ -28,15 +30,22 @@
private:
JitterSampler(const JitterSampler&);
JitterSampler& operator=(const JitterSampler&);
+
+ void computeAverages(Fragment& fragment, RayPacket& rays,
+ Color* sample_color, int* fragment_owning_sample);
+
int num_samples;
+ // nx*ny == num_samples where nx~=ny (or as close as you can get it).
+ int nx, ny;
+
struct ChannelInfo {
- double xscale;
- double xoffset;
- double yscale;
- double yoffset;
+ Real xscale;
+ Real xoffset;
+ Real yscale;
+ Real yoffset;
+ int xres, yres;
};
- vector2d *samples;
MT_RNG *random;
vector<ChannelInfo> channelInfo;
};
Modified: branches/itanium2/Engine/PixelSamplers/MultiJitterSampler.cc
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/MultiJitterSampler.cc
(original)
+++ branches/itanium2/Engine/PixelSamplers/MultiJitterSampler.cc Thu
Jun 16 15:17:50 2005
@@ -120,8 +120,8 @@
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+((samples[x].e[0]*2.0)-1.0))*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+((samples[x].e[1]*2.0)-1.0))*ci.yscale+ci.yoffset;
+ px =
((fe0.x+((samples[x][0]*2.0)-1.0))*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py = (fe0.y+((samples[x][1]*2.0)-1.0))*ci.yscale+ci.yoffset;
rays.setPixel(i, 0, px, py, &result[i]);
i++;
@@ -149,8 +149,8 @@
Sample::multiJitter(samples, num_samples, random[thd_num]);
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+samples[x].e[0])*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+samples[x].e[1])*ci.yscale+ci.yoffset;
+ px = ((fe0.x+samples[x][0])*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py = (fe0.y+samples[x][1])*ci.yscale+ci.yoffset;
rays.setPixel(i, 1, px, py, &result[i]);
i++;
Modified: branches/itanium2/Engine/PixelSamplers/NRooksSampler.cc
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/NRooksSampler.cc (original)
+++ branches/itanium2/Engine/PixelSamplers/NRooksSampler.cc Thu Jun 16
15:17:50 2005
@@ -124,8 +124,8 @@
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+(samples[x].e[0]))*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+(samples[x].e[1]))*ci.yscale+ci.yoffset;
+ px =
((fe0.x+(samples[x][0]))*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py = (fe0.y+(samples[x][1]))*ci.yscale+ci.yoffset;
rays.setPixel(i, 0, px, py, &result[i]);
i++;
@@ -152,8 +152,8 @@
Sample::nrooks(samples, num_samples, random[thd_num]);
for(int x = 0; x < num_samples; x++)
{
- px =
((fe0.x+samples[x].e[0])*ci.xscale+ci.xoffset)+count*ci.xscale;
- py = (fe0.y+samples[x].e[1])*ci.yscale+ci.yoffset;
+ px = ((fe0.x+samples[x][0])*ci.xscale+ci.xoffset)+count*ci.xscale;
+ py = (fe0.y+samples[x][1])*ci.yscale+ci.yoffset;
rays.setPixel(i, 1, px, py, &result[i]);
i++;
Modified: branches/itanium2/Engine/PixelSamplers/Sample.cc
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/Sample.cc (original)
+++ branches/itanium2/Engine/PixelSamplers/Sample.cc Thu Jun 16 15:17:50
2005
@@ -5,28 +5,27 @@
#include <math.h>
#include <stdio.h>
-
+using namespace Manta;
void Sample::random(vector2d *samples, int num_samples, MT_RNG seed)
{
for (int i = 0; i < num_samples; i++)
{
- samples[i].setX(seed.gendrand());
- samples[i].setY(seed.gendrand());
+ samples[i][0] = seed.genRealRand<Real>();
+ samples[i][1] = seed.genRealRand<Real>();
}
}
-void Sample::jitter(vector2d *samples, int num_samples, MT_RNG seed)
+void Sample::jitter(vector2d *samples, int nx, int ny, MT_RNG seed)
{
- int sqrt_samples = (int)(sqrt(float(num_samples)));
- for(int i = 0; i < sqrt_samples; i++)
- for(int j = 0; j < sqrt_samples; j++)
+ for(int i = 0; i < nx; i++)
+ for(int j = 0; j < ny; j++)
{
- float x = ((double)i + seed.gendrand()) / (double)sqrt_samples;
- float y = ((double)j + seed.gendrand()) / (double)sqrt_samples;
- (samples[i*sqrt_samples +j]).setX(x);
- (samples[i*sqrt_samples +j]).setY(y);
+ Real x = ((Real)i + seed.genRealRand<Real>()) / (Real)nx;
+ Real y = ((Real)j + seed.genRealRand<Real>()) / (Real)ny;
+ samples[i*nx +j][0] = x;
+ samples[i*nx +j][1] = y;
}
}
@@ -35,16 +34,16 @@
{
for (int i = 0; i < num_samples; i++)
{
- samples[i].setX(((double)i + seed.gendrand()) / (double)num_samples);
- samples[i].setY(((double)i + seed.gendrand()) / (double)num_samples);
+ samples[i][0] = ((Real)i + seed.genRealRand<Real>()) /
(Real)num_samples;
+ samples[i][1] = ((Real)i + seed.genRealRand<Real>()) /
(Real)num_samples;
}
// shuffle the x coords
for (int i = num_samples - 2; i >= 0; i--)
{
- int target = int(seed.gendrand() * (double)i);
+ int target = int(seed.genRealRand<Real>() * (Real)i);
float temp = samples[i+1].x();
- samples[i+1].setX(samples[target].x());
- samples[target].setX(temp);
+ samples[i+1][0] = samples[target].x();
+ samples[target][0] = temp;
}
}
@@ -62,10 +61,10 @@
for(int i = 0; i < sqrt_samples; i++)
for(int j = 0; j < sqrt_samples; j++)
{
- samples[i*sqrt_samples + j].e[0] = i*sqrt_samples*subcell_width +
- j*subcell_width + seed.gendrand() * subcell_width;
- samples[i*sqrt_samples + j].e[1] = j*sqrt_samples *subcell_width +
- i*subcell_width + seed.gendrand() * subcell_width;
+ samples[i*sqrt_samples + j][0] = i*sqrt_samples*subcell_width +
+ j*subcell_width + seed.genRealRand<Real>() * subcell_width;
+ samples[i*sqrt_samples + j][1] = j*sqrt_samples *subcell_width +
+ i*subcell_width + seed.genRealRand<Real>() * subcell_width;
}
@@ -73,15 +72,15 @@
for(int i = 0; i < sqrt_samples; i++)
for(int j = 0; j < sqrt_samples; j++)
{
- int k = j + int(seed.gendrand() * (sqrt_samples - j - 1));
- float t = samples[i*sqrt_samples + j].e[0];
- samples[i*sqrt_samples + j].e[0] = samples[i*sqrt_samples + k].e[0];
- samples[i*sqrt_samples + k].e[0] = t;
-
- k = j+int(seed.gendrand() * (sqrt_samples - j - 1));
- t = samples[j*sqrt_samples + i].e[1];
- samples[j*sqrt_samples + i].e[1] = samples[k*sqrt_samples + i].e[1];
- samples[k*sqrt_samples + i].e[1] = t;
+ int k = j + int(seed.genRealRand<Real>() * (sqrt_samples - j - 1));
+ float t = samples[i*sqrt_samples + j][0];
+ samples[i*sqrt_samples + j][0] = samples[i*sqrt_samples + k][0];
+ samples[i*sqrt_samples + k][0] = t;
+
+ k = j+int(seed.genRealRand<Real>() * (sqrt_samples - j - 1));
+ t = samples[j*sqrt_samples + i][1];
+ samples[j*sqrt_samples + i][1] = samples[k*sqrt_samples + i][1];
+ samples[k*sqrt_samples + i][1] = t;
}
}
@@ -90,8 +89,8 @@
{
double p, u, v;
int k, kk;
- double offu = (seed.gendrand() +.75f) / 2.0f;
- double offv = (seed.gendrand() +.75f) / 2.0f;
+ double offu = (seed.genRealRand<Real>() +.75f) / 2.0f;
+ double offv = (seed.genRealRand<Real>() +.75f) / 2.0f;
for (k=0 ; k<num_samples ; k++)
{
@@ -114,7 +113,7 @@
{
for (int i = num_samples - 2; i >= 0; i--)
{
- int target = int(seed.gendrand() * (double)i);
+ int target = int(seed.genRealRand<Real>() * (double)i);
vector2d temp = samples[i+1];
samples[i+1] = samples[target];
samples[target] = temp;
@@ -127,8 +126,8 @@
{
for (int i = 0; i < num_samples; i++)
{
- samples[i].setX(samples[i].x() - 0.5f);
- samples[i].setY(samples[i].y() - 0.5f);
+ samples[i][0] = samples[i][0] - (Real)0.5;
+ samples[i][1] = samples[i][1] - (Real)0.5;
}
}
@@ -138,12 +137,16 @@
for (int i = 0; i < num_samples; i++)
{
- float x = samples[i].x();
- float y = samples[i].y();
- if (x < 0.5f) samples[i].setX((float)sqrt(2.0*(double)x) - 1.0f);
- else samples[i].setX(1.0f - (float)sqrt(2.0 - 2.0 * (double)x));
- if (y < 0.5f) samples[i].setY((float)sqrt(2.0*(double)y) - 1.0f);
- else samples[i].setY(1.0f - (float)sqrt(2.0 - 2.0 * (double)y));
+ Real x = samples[i].x();
+ Real y = samples[i].y();
+ if (x < 0.5f)
+ samples[i][0] = (Real)sqrt(2.0*(Real)x) - 1.0f;
+ else
+ samples[i][0] = 1.0f - (Real)sqrt(2.0 - 2.0 * x);
+ if (y < 0.5f)
+ samples[i][1] = (Real)sqrt(2.0*(Real)y) - 1.0f;
+ else
+ samples[i][1] = 1.0f - (Real)sqrt(2.0 - 2.0 * y);
}
}
@@ -153,10 +156,10 @@
for (int i = 0; i < num_samples; i++)
{
- float x = samples[i].x();
- float y = samples[i].y();
- samples[i].e[0] = cubicFilter(x);
- samples[i].e[1] = cubicFilter(y);
+ Real x = samples[i].x();
+ Real y = samples[i].y();
+ samples[i][0] = cubicFilter(x);
+ samples[i][1] = cubicFilter(y);
}
}
@@ -188,6 +191,26 @@
}
}
+
+void Sample::nearest_square_finder(const int size, int &nx, int &ny) {
+ int x,y;
+ x = y = (int) sqrt((double)size);
+ // now we are basically looking for a pair of multiples that are closest to
+ // the square root.
+ while ((x * y) != size) {
+ // look for another multiple
+ for(int i = x+1; i <= size; i++) {
+ if (size%i == 0) {
+ // we've found a root
+ x = i;
+ y = size/x;
+ break;
+ }
+ }
+ }
+ nx = x;
+ ny = y;
+}
Modified: branches/itanium2/Engine/PixelSamplers/Sample.h
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/Sample.h (original)
+++ branches/itanium2/Engine/PixelSamplers/Sample.h Thu Jun 16 15:17:50
2005
@@ -11,15 +11,17 @@
#include <Core/Math/MT_RNG.h>
#include <math.h>
-class Sample{
+namespace Manta {
+
+class Sample {
public:
//2D sampling
static void random(vector2d *samples, int num_samples, MT_RNG seed);
- //jitter assumes num_samples is a perfect square
- static void jitter(vector2d* samples, int num_samples, MT_RNG seed);
+ // This Assums you have nx*ny samples available in samples.
+ static void jitter(vector2d* samples, int nx, int ny, MT_RNG seed);
static void nrooks(vector2d* samples, int num_samples, MT_RNG seed);
//multiJitter assumes num_samples is a perfect square
@@ -66,10 +68,13 @@
return 2 - pow(24.0f * (1.0f-x), 0.25f);
}
-
+ static void nearest_square_finder(const int size, int &nx, int &ny);
};
+
+} // end namespace Manta
+
#endif
Modified: branches/itanium2/Engine/PixelSamplers/SingleSampler.cc
==============================================================================
--- branches/itanium2/Engine/PixelSamplers/SingleSampler.cc (original)
+++ branches/itanium2/Engine/PixelSamplers/SingleSampler.cc Thu Jun 16
15:17:50 2005
@@ -54,8 +54,13 @@
if(fragment.getFlags() & Fragment::ConstantEye)
flags |= RayPacket::ConstantEye;
for(int f=0;f<fragment.getSize();f+=RayPacket::MaxSize){
+ // We want to fill our RayPacket with as many as
+ // RayPacket::MaxSize rays.
int size = RayPacket::MaxSize;
if(size >= fragment.getSize()-f)
+ // We don't have enough fragments left to fill a ray packet, so
+ // set the size of the RayPacket to the number of fragments we
+ // have left.
size = fragment.getSize()-f;
// Create a ray packet
int depth = 0;
- [MANTA] r390 - in branches/itanium2: Core/Math Engine/Display Engine/PixelSamplers, rocky, 06/16/2005
Archive powered by MHonArc 2.6.16.