00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "samplers/bestcandidate.h"
00028 #include "camera.h"
00029 #include "montecarlo.h"
00030
00031
00032 #include "samplers/bestcandidate.out"
00033 Sampler *BestCandidateSampler::GetSubSampler(int num, int count) {
00034 int x0, x1, y0, y1;
00035 ComputeSubWindow(num, count, &x0, &x1, &y0, &y1);
00036 if (x0 == x1 || y0 == y1) return NULL;
00037 return new BestCandidateSampler(x0, x1, y0, y1, samplesPerPixel,
00038 shutterOpen, shutterClose);
00039 }
00040
00041
00042 int BestCandidateSampler::GetMoreSamples(Sample *sample, RNG &rng) {
00043 again:
00044 if (tableOffset == SAMPLE_TABLE_SIZE) {
00045
00046 tableOffset = 0;
00047 if (++xTile > xTileEnd) {
00048 xTile = xTileStart;
00049 if (++yTile > yTileEnd)
00050 return 0;
00051 }
00052
00053
00054 RNG tileRng(xTile + (yTile<<8));
00055 for (int i = 0; i < 3; ++i)
00056 sampleOffsets[i] = tileRng.RandomFloat();
00057 }
00058
00059 #define WRAP(x) ((x) > 1 ? ((x)-1) : (x))
00060 sample->imageX = (xTile + sampleTable[tableOffset][0]) * tableWidth;
00061 sample->imageY = (yTile + sampleTable[tableOffset][1]) * tableWidth;
00062 sample->time = Lerp(WRAP(sampleOffsets[0] + sampleTable[tableOffset][2]),
00063 shutterOpen, shutterClose);
00064 sample->lensU = WRAP(sampleOffsets[1] +
00065 sampleTable[tableOffset][3]);
00066 sample->lensV = WRAP(sampleOffsets[2] +
00067 sampleTable[tableOffset][4]);
00068
00069
00070 if (sample->imageX < xPixelStart || sample->imageX >= xPixelEnd ||
00071 sample->imageY < yPixelStart || sample->imageY >= yPixelEnd) {
00072 ++tableOffset;
00073 goto again;
00074 }
00075
00076
00077 for (uint32_t i = 0; i < sample->n1D.size(); ++i)
00078 LDShuffleScrambled1D(sample->n1D[i], 1, sample->oneD[i], rng);
00079 for (uint32_t i = 0; i < sample->n2D.size(); ++i)
00080 LDShuffleScrambled2D(sample->n2D[i], 1, sample->twoD[i], rng);
00081 ++tableOffset;
00082 return 1;
00083 }
00084
00085
00086 BestCandidateSampler *CreateBestCandidateSampler(const ParamSet ¶ms, const Film *film,
00087 const Camera *camera) {
00088
00089 int xstart, xend, ystart, yend;
00090 film->GetSampleExtent(&xstart, &xend, &ystart, ¥d);
00091 int nsamp = params.FindOneInt("pixelsamples", 4);
00092 if (PbrtOptions.quickRender) nsamp = 1;
00093 return new BestCandidateSampler(xstart, xend, ystart, yend, nsamp,
00094 camera->shutterOpen, camera->shutterClose);
00095 }
00096
00097