Skip to content

Commit

Permalink
Add "samplepixelcenter" option to HaltonSampler.
Browse files Browse the repository at this point in the history
This forces all image samples to be at the center of the pixel. (Not so good
for anti-aliasing, but useful for some applications.)
  • Loading branch information
mmp committed Dec 22, 2016
1 parent 3abd7bc commit 6a9eec8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/samplers/halton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ static void extendedGCD(uint64_t a, uint64_t b, int64_t *x, int64_t *y) {
}

// HaltonSampler Method Definitions
HaltonSampler::HaltonSampler(int samplesPerPixel, const Bounds2i &sampleBounds)
: GlobalSampler(samplesPerPixel) {
HaltonSampler::HaltonSampler(int samplesPerPixel, const Bounds2i &sampleBounds,
bool sampleAtPixelCenter)
: GlobalSampler(samplesPerPixel), sampleAtPixelCenter(sampleAtPixelCenter) {
// Generate random digit permutations for Halton sampler
if (radicalInversePermutations.empty()) {
RNG rng;
Expand Down Expand Up @@ -115,6 +116,7 @@ int64_t HaltonSampler::GetIndexForSample(int64_t sampleNum) const {
}

Float HaltonSampler::SampleDimension(int64_t index, int dim) const {
if (sampleAtPixelCenter && (dim == 0 || dim == 1)) return 0.5f;
if (dim == 0)
return RadicalInverse(dim, index >> baseExponents[0]);
else if (dim == 1)
Expand All @@ -132,7 +134,8 @@ HaltonSampler *CreateHaltonSampler(const ParamSet &params,
const Bounds2i &sampleBounds) {
int nsamp = params.FindOneInt("pixelsamples", 16);
if (PbrtOptions.quickRender) nsamp = 1;
return new HaltonSampler(nsamp, sampleBounds);
bool sampleAtCenter = params.FindOneBool("samplepixelcenter", false);
return new HaltonSampler(nsamp, sampleBounds, sampleAtCenter);
}

} // namespace pbrt
6 changes: 5 additions & 1 deletion src/samplers/halton.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace pbrt {
class HaltonSampler : public GlobalSampler {
public:
// HaltonSampler Public Methods
HaltonSampler(int nsamp, const Bounds2i &sampleBounds);
HaltonSampler(int nsamp, const Bounds2i &sampleBounds,
bool sampleAtCenter = false);
int64_t GetIndexForSample(int64_t sampleNum) const;
Float SampleDimension(int64_t index, int dimension) const;
std::unique_ptr<Sampler> Clone(int seed);
Expand All @@ -62,6 +63,9 @@ class HaltonSampler : public GlobalSampler {
mutable Point2i pixelForOffset = Point2i(std::numeric_limits<int>::max(),
std::numeric_limits<int>::max());
mutable int64_t offsetForCurrentPixel;
// Added after book publication: force all image samples to be at the
// center of the pixel area.
bool sampleAtPixelCenter;

// HaltonSampler Private Methods
const uint16_t *PermutationForDimension(int dim) const {
Expand Down

0 comments on commit 6a9eec8

Please sign in to comment.