Exemplo n.º 1
0
  void SamplerFactory::init(int iteration, const Ref<Filter> filter)
  {
    this->iteration = iteration;
    samples = new PrecomputedSample*[sampleSets];

    int chunkSize = max((int)samplesPerPixel,64);
    int currentChunk = int(iteration*samplesPerPixel) / chunkSize;
    int offset = (iteration*samplesPerPixel) % chunkSize;
    Random rng;
    rng.setSeed(currentChunk * 5897);

    Vec2f* pixel = new Vec2f[chunkSize];
    float* time = new float[chunkSize];
    Vec2f* lens = new Vec2f[chunkSize];
    float* samples1D = new float[chunkSize];
    Vec2f* samples2D = new Vec2f[chunkSize];

    for (int set = 0; set < sampleSets; set++)
    {
      samples[set] = new PrecomputedSample[samplesPerPixel];

      /*! Generate pixel and lens samples. */
      multiJittered(pixel, chunkSize, rng);
      jittered(time, chunkSize, rng);
      multiJittered(lens, chunkSize, rng);
      for (int s = 0; s < samplesPerPixel; s++) {
        samples[set][s].pixel = pixel[offset + s];
        samples[set][s].time = time[offset + s];
        samples[set][s].lens = lens[offset + s];
        if (filter) {
          samples[set][s].pixel = filter->sample(samples[set][s].pixel) + Vec2f(0.5f, 0.5f);
        }
        samples[set][s].samples1D = new float[SamplerFactory::numSamples1D];
        samples[set][s].samples2D = new Vec2f[SamplerFactory::numSamples2D];
        samples[set][s].lightSamples = new LightSample[SamplerFactory::numLightSamples];
      }

      /*! Generate requested 1D samples. */
      for (int d = 0; d < SamplerFactory::numSamples1D; d++) {
        jittered(samples1D, chunkSize, rng);
        for (int s = 0; s < samplesPerPixel; s++) {
          samples[set][s].samples1D[d] = samples1D[offset + s];
        }
      }

      /*! Generate 2D samples. */
      for (int d = 0; d < SamplerFactory::numSamples2D; d++) {
        multiJittered(samples2D, chunkSize, rng);
        for (int s = 0; s < samplesPerPixel; s++) {
          samples[set][s].samples2D[d] = samples2D[offset + s];
        }
      }

      /*! Generate light samples. */
      for (int d = 0; d < SamplerFactory::numLightSamples; d++) {
        for (int s = 0; s < samplesPerPixel; s++) {
          LightSample ls;
          DifferentialGeometry dg;
          ls.L = lights[d]->sample(dg, ls.wi, ls.tMax, samples[set][s].samples2D[lightBaseSamples[d]]);
          samples[set][s].lightSamples[d] = ls;
        }
      }
    }
    
    delete[] pixel;
    delete[] time;
    delete[] lens;
    delete[] samples1D;
    delete[] samples2D;
  }
Exemplo n.º 2
0
  void SamplerFactory::init(float rcpWidth, float rcpHeight, int iteration, const Ref<Filter> filter)
  {
    this->iteration = iteration;
    samples = new PrecomputedSample*[sampleSets];
    if (samplesPerPixel != (1 << __bsf(samplesPerPixel)))
      throw std::runtime_error("Number of samples per pixel have to be a power of two.");

    int chunkSize = max((int)samplesPerPixel,64);
    int currentChunk = int(iteration*samplesPerPixel) / chunkSize;
    int offset = (iteration*samplesPerPixel) % chunkSize;
    Random rng;
    rng.setSeed(currentChunk * 5897);

    Vec2f* pixel = new Vec2f[chunkSize];
    float* time = new float[chunkSize];
    Vec2f* lens = new Vec2f[chunkSize];
    float* samples1D = new float[chunkSize];
    Vec2f* samples2D = new Vec2f[chunkSize];

  allSamples1D = static_cast<float*>(alignedMalloc(sizeof(float)*SamplerFactory::numSamples1D*sampleSets*samplesPerPixel));
  allSamples2D = static_cast<Vec2f*>(alignedMalloc(sizeof(Vec2f)*SamplerFactory::numSamples2D*sampleSets*samplesPerPixel));
  allLightSamples = new PackedLightSample[SamplerFactory::numLightSamples*sampleSets*samplesPerPixel];

    for (int set = 0; set < sampleSets; set++)
    {
      samples[set] = new PrecomputedSample[samplesPerPixel];

      /*! Generate pixel and lens samples. */
      multiJittered(pixel, chunkSize, rng);
      jittered(time, chunkSize, rng);
      multiJittered(lens, chunkSize, rng);
      for (int s = 0; s < samplesPerPixel; s++) {
        samples[set][s].pixel = pixel[offset + s];
        samples[set][s].time = time[offset + s];
        samples[set][s].lens = lens[offset + s];
        if (filter) {
          samples[set][s].pixel = filter->sample(samples[set][s].pixel) + Vec2f(0.5f, 0.5f);
        }
        samples[set][s].pixel = samples[set][s].pixel * Vec2f(rcpWidth, rcpHeight);
        samples[set][s].samples1D = allSamples1D + (s + samplesPerPixel*set)*SamplerFactory::numSamples1D;
    samples[set][s].samples2D = allSamples2D + (s + samplesPerPixel*set)*SamplerFactory::numSamples2D;
    samples[set][s].lightSamples = allLightSamples + (s + samplesPerPixel*set)*SamplerFactory::numLightSamples;
      }

      /*! Generate requested 1D samples. */
      for (int d = 0; d < SamplerFactory::numSamples1D; d++) {
        jittered(samples1D, chunkSize, rng);
        for (int s = 0; s < samplesPerPixel; s++) {
          samples[set][s].samples1D[d] = samples1D[offset + s];
        }
      }

      /*! Generate 2D samples. */
      for (int d = 0; d < SamplerFactory::numSamples2D; d++) {
        multiJittered(samples2D, chunkSize, rng);
        for (int s = 0; s < samplesPerPixel; s++) {
          samples[set][s].samples2D[d] = samples2D[offset + s];
        }
      }

      /*! Generate light samples. */
      for (int d = 0; d < SamplerFactory::numLightSamples; d++) {
        for (int s = 0; s < samplesPerPixel; s++) {
          LightSample ls;
          DifferentialGeometry dg;
          ls.L = lights[d]->sample(dg, ls.wi, ls.tMax, samples[set][s].samples2D[lightBaseSamples[d]]);
          samples[set][s].lightSamples[d] = ls;
        }
      }
    }
    
    delete[] pixel;
    delete[] time;
    delete[] lens;
    delete[] samples1D;
    delete[] samples2D;
  }