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/halton.h"
00028 #include "paramset.h"
00029 #include "camera.h"
00030 #include "montecarlo.h"
00031
00032
00033 Sampler *HaltonSampler::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 HaltonSampler(x0, x1, y0, y1, samplesPerPixel, shutterOpen,
00038 shutterClose);
00039 }
00040
00041
00042 HaltonSampler::HaltonSampler(int xs, int xe, int ys, int ye, int ps,
00043 float sopen, float sclose)
00044 : Sampler(xs, xe, ys, ye, ps, sopen, sclose) {
00045 int delta = max(xPixelEnd - xPixelStart,
00046 yPixelEnd - yPixelStart);
00047 wantedSamples = samplesPerPixel * delta * delta;
00048 currentSample = 0;
00049 }
00050
00051
00052 int HaltonSampler::GetMoreSamples(Sample *samples, RNG &rng) {
00053 retry:
00054 if (currentSample >= wantedSamples) return 0;
00055
00056 float u = (float)RadicalInverse(currentSample, 3);
00057 float v = (float)RadicalInverse(currentSample, 2);
00058 float lerpDelta = float(max(xPixelEnd - xPixelStart,
00059 yPixelEnd - yPixelStart));
00060 samples->imageX = Lerp(u, xPixelStart, xPixelStart + lerpDelta);
00061 samples->imageY = Lerp(v, yPixelStart, yPixelStart + lerpDelta);
00062 ++currentSample;
00063 if (samples->imageX >= xPixelEnd || samples->imageY >= yPixelEnd)
00064 goto retry;
00065
00066
00067 samples->lensU = (float)RadicalInverse(currentSample, 5);
00068 samples->lensV = (float)RadicalInverse(currentSample, 7);
00069 samples->time = Lerp((float)RadicalInverse(currentSample, 11),
00070 shutterOpen, shutterClose);
00071 for (uint32_t i = 0; i < samples->n1D.size(); ++i)
00072 LatinHypercube(samples->oneD[i], samples->n1D[i], 1, rng);
00073 for (uint32_t i = 0; i < samples->n2D.size(); ++i)
00074 LatinHypercube(samples->twoD[i], samples->n2D[i], 2, rng);
00075 return 1;
00076 }
00077
00078
00079 HaltonSampler *CreateHaltonSampler(const ParamSet ¶ms, const Film *film,
00080 const Camera *camera) {
00081
00082 int xstart, xend, ystart, yend;
00083 film->GetSampleExtent(&xstart, &xend, &ystart, ¥d);
00084 int nsamp = params.FindOneInt("pixelsamples", 4);
00085 if (PbrtOptions.quickRender) nsamp = 1;
00086 return new HaltonSampler(xstart, xend, ystart, yend, nsamp,
00087 camera->shutterOpen, camera->shutterClose);
00088 }
00089
00090