Пример #1
0
void Worker::AccumulateFluxSPPM(uint iteration, u_int64_t photonTraced) {

  photonTraced += engine->getPhotonTracedTotal();

#ifndef __DEBUG
  omp_set_num_threads(config->max_threads);
#pragma omp parallel for schedule(guided)
#endif
  for (uint i = 0; i < engine->hitPointTotal; i++) {
    HitPointStaticInfo *ehp = GetHitPointInfo(i);
    HitPoint *ihp = GetHitPoint(i);

    switch (ehp->type) {
      case CONSTANT_COLOR:
      ihp->accumRadiance += ehp->throughput;
      ihp->constantHitsCount += 1;
      break;
      case SURFACE:

      if ((ihp->accumPhotonCount > 0)) {

        const unsigned long long pcount = ihp->photonCount + ihp->accumPhotonCount;
        const float alpha = engine->alpha;

        const float g = alpha * pcount / (ihp->photonCount * alpha + ihp->accumPhotonCount);

        ihp->accumPhotonRadius2 *= g;

        ihp->reflectedFlux = (ihp->reflectedFlux + ihp->accumReflectedFlux) * g;

        ihp->photonCount = pcount;

        ihp->accumPhotonCount = 0;
        ihp->accumReflectedFlux = Spectrum();
      }

      ihp->surfaceHitsCount += 1;
      break;
      default:
      assert (false);
    }
    const unsigned int hitCount = ihp->constantHitsCount + ihp->surfaceHitsCount;
    if (hitCount > 0) {

      const double k = 1.0 / (M_PI * ihp->accumPhotonRadius2 * photonTraced);
      Spectrum radiance_r;
      radiance_r = (ihp->accumRadiance + ihp->surfaceHitsCount * ihp->reflectedFlux * k)
      / hitCount;
      ihp->radiance = radiance_r;
    }
  }

  fprintf(stderr, "Iteration %d hit point 0 reducted radius: %f\n", iteration,
      GetHitPoint(0)->accumPhotonRadius2);
}
Пример #2
0
void Worker::AccumulateFluxSPPMPA(uint iteration, u_int64_t photonTraced) {

#ifndef __DEBUG
  omp_set_num_threads(config->max_threads);
#pragma omp parallel for schedule(guided)
#endif
  for (uint i = 0; i < engine->hitPointTotal; i++) {
    HitPointPositionInfo *ehp = GetHitPointInfo(i);
    HitPointRadianceFlux *ihp = GetHitPoint(i);

    switch (ehp->type) {
      case CONSTANT_COLOR:
      ihp->accumRadiance += ehp->throughput;
      ihp->constantHitsCount += 1;
      break;
      case SURFACE:

      if ((ihp->accumPhotonCount > 0)) {

        ihp->reflectedFlux = ihp->accumReflectedFlux;
        ihp->accumPhotonCount = 0;
        ihp->accumReflectedFlux = Spectrum();
      }
      ihp->surfaceHitsCount += 1;
      break;
      default:
      assert (false);
    }

    const unsigned int hitCount = ihp->constantHitsCount + ihp->surfaceHitsCount;

    if (hitCount > 0) {

      const double k = 1.0 / (M_PI * currentPhotonRadius2 * photonTraced);

      ihp->radiance = (ihp->accumRadiance + ihp->reflectedFlux * k);
    }

  }

  for (uint i = 0; i < engine->hitPointTotal; i++) {
    HitPointRadianceFlux *ihp = GetHitPoint(i);

    ihp->constantHitsCount = 0;
    ihp->surfaceHitsCount = 0;
    ihp ->accumRadiance = Spectrum();
  }

  //fprintf(stderr, "Iteration %d hit point 0 reducted radius: %f\n", iteration,
  //    currentPhotonRadius2);
}
Пример #3
0
void Worker::UpdateBBox() {

  // Calculate hit points bounding box
  //std::cerr << "Building hit points bounding box: ";

  BBox hitPointsbbox = BBox();

  for (unsigned int i = 0; i < engine->hitPointTotal; ++i) {
    HitPointPositionInfo *hp = GetHitPointInfo(i);

    if (hp->type == SURFACE)
      hitPointsbbox = Union(hitPointsbbox, hp->position);
  }
  SetBBox(hitPointsbbox);

}
Пример #4
0
void Worker::AccumulateFluxPPMPA(uint iteration, u_int64_t photonTraced) {

  //photonTraced += engine->getPhotonTracedTotal();


#ifndef __DEBUG
  omp_set_num_threads(config->max_threads);
#pragma omp parallel for schedule(guided)
#endif
  for (uint i = 0; i < engine->hitPointTotal; i++) {

    HitPointStaticInfo *ehp = GetHitPointInfo(i);
    HitPoint *ihp = GetHitPoint(i);

    switch (ehp->type) {
    case CONSTANT_COLOR:
      ihp->radiance = ehp->throughput;

      break;
    case SURFACE:

      if ((ihp->accumPhotonCount > 0)) {

        ihp->reflectedFlux = ihp->accumReflectedFlux;

        //out of the loop
        const double k = 1.0 / (M_PI * currentPhotonRadius2 * photonTraced);

        ihp->radiance = ihp->reflectedFlux * k;

        ihp->accumPhotonCount = 0;
        ihp->accumReflectedFlux = Spectrum();
      }
      break;
    default:
      assert (false);
    }
  }
}
Пример #5
0
void Worker::UpdateSampleFrameBuffer(unsigned long long iterationPhotonCount) {
#else
void Worker::UpdateSampleFrameBuffer(unsigned long long /*iterationPhotonCount*/) {
#endif

  for (unsigned int i = 0; i < engine->hitPointTotal; ++i) {
    HitPointStaticInfo *hp = GetHitPointInfo(i);
    HitPoint *ihp = GetHitPoint(i);

#if defined USE_SPPM || defined USE_SPPMPA
    const float scrX = i % engine->width;
    const float scrY = i / engine->width;

    sampleBuffer->SplatSample(scrX, scrY, ihp->radiance);
#endif

#if defined USE_PPM || defined USE_PPMPA
    sampleBuffer->SplatSample(hp->scrX, hp->scrY, ihp->radiance);
#endif

  }

  sampleFrameBuffer->Clear();

  if (sampleBuffer->GetSampleCount() > 0) {

    engine->SplatSampleBuffer(sampleFrameBuffer, true, sampleBuffer);
    sampleBuffer->Reset();
  }
}

#ifdef USE_PPM
void Worker::AccumulateFluxPPM(uint /*iteration*/, u_int64_t photonTraced) {

  photonTraced += engine->getPhotonTracedTotal();

#ifndef __DEBUG
  omp_set_num_threads(config->max_threads);
#pragma omp parallel for schedule(guided)
#endif
  for (uint i = 0; i < engine->hitPointTotal; i++) {
    HitPointStaticInfo *ehp = GetHitPointInfo(i);
    HitPoint *ihp = GetHitPoint(i);

    switch (ehp->type) {
      case CONSTANT_COLOR:
      ihp->radiance = ehp->throughput;
      break;
      case SURFACE:

      if ((ihp->accumPhotonCount > 0)) {

        const unsigned long long pcount = ihp->photonCount + ihp->accumPhotonCount;
        const float alpha = engine->alpha;

        const float g = alpha * pcount / (ihp->photonCount * alpha + ihp->accumPhotonCount);

        ihp->accumPhotonRadius2 *= g;

        ihp->reflectedFlux = (ihp->reflectedFlux + ihp->accumReflectedFlux) * g;

        ihp->photonCount = pcount;

        const double k = 1.0 / (M_PI * ihp->accumPhotonRadius2 * photonTraced);

        ihp->radiance = ihp->reflectedFlux * k;

        ihp->accumPhotonCount = 0;
        ihp->accumReflectedFlux = Spectrum();
      }

      break;
      default:
      assert (false);
    }

  }

  //fprintf(stderr, "Iteration %d hit point 0 reducted radius: %f\n", iteration,
  //    GetHitPoint(0)->accumPhotonRadius2);
}
Пример #6
0
void Worker::BuildHitPoints(uint iteration) {

  const unsigned int width = engine->width;
  const unsigned int height = engine->height;
  const unsigned int superSampling = engine->superSampling;

  const unsigned int hitPointTotal = engine->hitPointTotal;

  EyePath* todoEyePaths = new EyePath[hitPointTotal];


#ifndef USE_SPPM
  memset(HPsIterationRadianceFlux, 0, sizeof(HitPointRadianceFlux) * engine->hitPointTotal);
#endif

  unsigned int hitPointsIndex = 0;
  const float invSuperSampling = 1.f / superSampling;

  for (unsigned int y = 0; y < height; ++y) {

    //for all hitpoints
    for (unsigned int x = 0; x < width; ++x) {
      for (unsigned int sy = 0; sy < superSampling; ++sy) {
        for (unsigned int sx = 0; sx < superSampling; ++sx) {

          EyePath *eyePath = &todoEyePaths[hitPointsIndex];

          eyePath->scrX = x + (sx + getFloatRNG(seedBuffer[hitPointsIndex]))
              * invSuperSampling - 0.5f;

          eyePath->scrY = y + (sy + getFloatRNG(seedBuffer[hitPointsIndex]))
              * invSuperSampling - 0.5f;

          float u0 = getFloatRNG(seedBuffer[hitPointsIndex]);
          float u1 = getFloatRNG(seedBuffer[hitPointsIndex]);
          float u2 = getFloatRNG(seedBuffer[hitPointsIndex]);

          ss->GenerateRay(eyePath->scrX, eyePath->scrY, width, height, &eyePath->ray, u0,
              u1, u2, &ss->camera);

          eyePath->depth = 0;
          eyePath->throughput = Spectrum(1.f, 1.f, 1.f);

          eyePath->done = false;
          eyePath->splat = false;
          eyePath->sampleIndex = hitPointsIndex;

          hitPointsIndex++;

        }
      }
    }
  }

  uint todoEyePathCount = hitPointTotal;
  uint chunk_counter = 0;

  uint* eyePathIndexes = new uint[getRaybufferSize()];

  resetRayBuffer();

  while (todoEyePathCount > 0) {

    //transversing in chunks
    uint start = (chunk_counter / getRaybufferSize()) * getRaybufferSize();

    uint end;
    if (hitPointTotal - start < getRaybufferSize())
      end = hitPointTotal;
    else
      end = start + getRaybufferSize();

    for (uint i = start; i < end; i++) {

      EyePath *eyePath = &todoEyePaths[i];

      // Check if we reached the max path depth
      if (!eyePath->done && eyePath->depth > MAX_EYE_PATH_DEPTH) {

        // Add an hit point
        HitPointPositionInfo* hp = GetHitPointInfo(eyePath->sampleIndex);

        hp->type = CONSTANT_COLOR;
        hp->scrX = eyePath->scrX;
        hp->scrY = eyePath->scrY;
        hp->throughput = Spectrum();

        eyePath->done = true;

      } else if (!eyePath->done) {
        eyePath->depth++;

        uint p = RaybufferAddRay(eyePath->ray);

        eyePathIndexes[p] = i;
      }

      if (eyePath->done && !eyePath->splat) {
        --todoEyePathCount;
        chunk_counter++;
        eyePath->splat = true;
      }
    }

    if (getRayBufferRayCount() > 0) {

      IntersectRayBuffer();

      AdvanceEyePaths(&todoEyePaths[0], eyePathIndexes);

      resetRayBuffer();
    }
  }

  delete[] todoEyePaths;
  delete[] eyePathIndexes;

}