Ejemplo n.º 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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 3
0
void Worker::UpdateSampleFrameBuffer(unsigned long long iterationPhotonCount) {

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

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

    //if (i %1000 == 0) std::cout << scrX << " " << scrY << " " << ihp->radiance << '\n';

    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();
  }
}
Ejemplo n.º 4
0
void Worker::InitRadius(uint iteration) {
#else
void Worker::InitRadius(uint /*iteration*/) {
#endif

  BBox* hitPointsbbox = GetHostBBox();

  Vector ssize = hitPointsbbox->pMax - hitPointsbbox->pMin;
  float photonRadius = ((ssize.x + ssize.y + ssize.z) / 3.f) / ((engine->width
      * engine->superSampling + engine->height * engine->superSampling) / 2.f) * 2.f;

  float photonRadius2 = photonRadius * photonRadius;

#if defined USE_SPPMPA || defined USE_PPMPA


  float g = 1;
  for (uint k = 1; k < iteration; k++)
    g *= (k + engine->alpha) / k;

  g /= iteration;

  photonRadius2 = photonRadius2 * g;
#endif

  // Expand the bounding box by used radius
  hitPointsbbox->Expand(sqrt(photonRadius2));

  // Initialize hit points field
  //const float photonRadius2 = photonRadius * photonRadius;

#if defined USE_SPPMPA || defined USE_PPMPA
  currentPhotonRadius2 = photonRadius2;
#else
  for (unsigned int i = 0; i < engine->hitPointTotal; ++i) {

    //HitPointInfo *hpinfo = engine->GetHitPointInfo(i);
    HitPoint *hp = GetHitPoint(i);

    hp->accumPhotonRadius2 = photonRadius2;

  }
#endif

}
Ejemplo n.º 5
0
void vMover::SetPointParam( int nDstParameter, int nValue, bool bTrans )
{
	int nMax = nValue;
	if( nValue < 0 )	
		nValue	= 0;

	bool bTransfer = bTrans;

	switch( nDstParameter )
	{
	case DST_HP:
		if( nValue > GetMaxHitPoint() || nMax == 999999999 )	
			nValue = GetMaxHitPoint();

		if( GetHitPoint() != nValue )
		{
			bTransfer = true;
			SetHitPoint( nValue );
		}
		break;
	case DST_MP:
		if( nValue > GetMaxManaPoint() || nMax == 999999999 )	
			nValue = GetMaxManaPoint();

		if( GetManaPoint() != nValue )
		{
			bTransfer	= true;
			m_nManaPoint = nValue;
		}
		break;
	case DST_FP:
		if( nValue > GetMaxFatiguePoint() || nMax == 999999999 )	
			nValue	= GetMaxFatiguePoint();

		if( GetFatiguePoint() != nValue )
		{
			bTransfer	= true;
			m_nFatiguePoint = nValue;
		}
		break;
	}
	if( bTransfer )
		g_pUserMng.AddSetPointParam( this, nDstParameter, nValue );
}
Ejemplo n.º 6
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);
    }
  }
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
void vMover::SetDestParam( int nDstParameter, int nAdjParameterValue, int nChgParameterValue, bool bSend )
{
	bool fSuccess	= FALSE;

	if( (nDstParameter < 0 ) && ( nDstParameter != DST_ADJDEF_RATE && nDstParameter != DST_ADJDEF ) )
		return;

	switch( nDstParameter )
	{
	case DST_HP:
		{
			if( nAdjParameterValue == -1 )
				SetPointParam( nDstParameter, GetMaxHitPoint() );
			else
				SetPointParam( nDstParameter, GetHitPoint() + nAdjParameterValue );
		}
		return;
	case DST_MP:
		{
			if( nAdjParameterValue == -1 )
				SetPointParam( nDstParameter, GetMaxManaPoint() );
			else
				SetPointParam( nDstParameter, GetManaPoint() + nAdjParameterValue );
		}
		return;
	case DST_FP:
		{
			if( nAdjParameterValue == -1 )
				SetPointParam( nDstParameter, GetMaxFatiguePoint() );
			else
				SetPointParam( nDstParameter, GetFatiguePoint() + nAdjParameterValue );
		}
		return;

	case DST_GOLD:	
		Log( LOG_ERROR, "SetDestParam( DST_GOLD ) - [User:%s(%07d)], [Value:%d]", ((vUser*)(this))->GetName(), ((vUser*)(this))->m_idPlayer, nAdjParameterValue );
		return;

		if( AddGold( nAdjParameterValue ) == FALSE )	
			SetGold( 0 );
		return;

	case DST_RESIST_ALL:
		SetDestParam( DST_RESIST_ELECTRICITY,	nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_RESIST_FIRE,			nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_RESIST_WIND,			nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_RESIST_WATER,			nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_RESIST_EARTH,			nAdjParameterValue, nChgParameterValue, bSend );
		return;
	case DST_STAT_ALLUP:
		SetDestParam( DST_STR,	nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_DEX,	nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_INT,	nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_STA,	nAdjParameterValue, nChgParameterValue, bSend );
		return;
	case DST_HPDMG_UP:
		SetDestParam( DST_HP_MAX, nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_CHR_DMG, nAdjParameterValue, nChgParameterValue, bSend );
		return;
	case DST_DEFHITRATE_DOWN:
		SetDestParam( DST_ADJDEF, nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_ADJ_HITRATE, nAdjParameterValue, nChgParameterValue, bSend );
		return;
	case DST_LOCOMOTION:
		SetDestParam( DST_SPEED,	nAdjParameterValue, nChgParameterValue, bSend );
		SetDestParam( DST_JUMPING,	( nAdjParameterValue * 3 ), nChgParameterValue, bSend );
		return;
	case DST_HP_RECOVERY_RATE:
		{
			int nMax	= GetMaxOriginHitPoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_HP_RECOVERY, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_MP_RECOVERY_RATE:
		{
			int nMax	= GetMaxOriginManaPoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_MP_RECOVERY, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_FP_RECOVERY_RATE:
		{
			int nMax	= GetMaxOriginFatiguePoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_FP_RECOVERY, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_ALL_RECOVERY:
		{
			SetDestParam( DST_HP_RECOVERY, nAdjParameterValue, NULL_CHGPARAM, bSend );
			SetDestParam( DST_MP_RECOVERY, nAdjParameterValue, NULL_CHGPARAM, bSend );
			SetDestParam( DST_FP_RECOVERY, nAdjParameterValue, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_ALL_RECOVERY_RATE:
		{
			int nMax	= GetMaxOriginHitPoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_HP_RECOVERY, nRecv, NULL_CHGPARAM, bSend );

			nMax	= GetMaxOriginManaPoint();
			nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_MP_RECOVERY, nRecv, NULL_CHGPARAM, bSend );

			nMax	= GetMaxOriginFatiguePoint();
			nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_FP_RECOVERY, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_KILL_ALL:	
		{
			SetDestParam( DST_KILL_HP, nAdjParameterValue, NULL_CHGPARAM, bSend );
			SetDestParam( DST_KILL_MP, nAdjParameterValue, NULL_CHGPARAM, bSend );
			SetDestParam( DST_KILL_FP, nAdjParameterValue, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_KILL_HP_RATE:
		{
			int nMax	= GetMaxOriginHitPoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_KILL_HP, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_KILL_MP_RATE:
		{
			int nMax	= GetMaxOriginManaPoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_KILL_MP, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_KILL_FP_RATE:
		{
			int nMax	= GetMaxOriginFatiguePoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_KILL_FP, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_KILL_ALL_RATE:
		{
			int nMax	= GetMaxOriginHitPoint();
			int nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_KILL_HP, nRecv, NULL_CHGPARAM, bSend );

			nMax	= GetMaxOriginManaPoint();
			nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_KILL_MP, nRecv, NULL_CHGPARAM, bSend );

			nMax	= GetMaxOriginFatiguePoint();
			nRecv	= (int)( (nMax * (nAdjParameterValue / 100.0f)) );
			SetDestParam( DST_KILL_FP, nRecv, NULL_CHGPARAM, bSend );
		}
		return;
	case DST_ALL_DEC_RATE:
		{
			SetDestParam( DST_MP_DEC_RATE, nAdjParameterValue, NULL_CHGPARAM, bSend );
			SetDestParam( DST_FP_DEC_RATE, nAdjParameterValue, NULL_CHGPARAM, bSend );
		}
		return;
	}

	if( nDstParameter >= MAX_ADJPARAMARY)
		return;

	if( nAdjParameterValue != 0 )
	{
		fSuccess = true;

		switch( nDstParameter )
		{
		case DST_CHRSTATE:
		case DST_IMMUNITY:
			if( nAdjParameterValue != NULL_ID )
			{
				if( nAdjParameterValue == 0xffffffff )
				{
					Log( LOG_ERROR, "SetDestParam : Adj == -1, %s", GetName() );
					return;
				}
				m_adjParamAry[nDstParameter] |= nAdjParameterValue;
			} else
				fSuccess = false;
			break;
		case DST_CURECHR:
			ResetDestParam( DST_CHRSTATE, nAdjParameterValue, bSend );
			return;
		case DST_REFLECT_DAMAGE:
			m_adjParamAry[nDstParameter] += nAdjParameterValue;
			m_chgParamAry[nDstParameter] = nChgParameterValue;
			break;
		case DST_CHR_CHANCEBLEEDING:
		case DST_CHR_CHANCESTEALHP:
		case DST_CHR_CHANCEPOISON:
		case DST_CHR_CHANCEDARK:
		case DST_CHR_CHANCESTUN:
		case DST_AUTOHP:
			m_adjParamAry[nDstParameter] += nAdjParameterValue;
			m_chgParamAry[nDstParameter] = nChgParameterValue;
			break;
		case DST_HEAL:
			m_nHealCnt	= (short)( PROCESS_COUNT * 6.0f );
			m_adjParamAry[nDstParameter]	+= nAdjParameterValue;	
			break;

		default:
			m_adjParamAry[nDstParameter] += nAdjParameterValue;
			break;
		}
	}

	else if( nChgParameterValue != 0x7FFFFFFF ) 
	{
		fSuccess = true;

		if( nDstParameter == DST_SPEED )
		{
			if( m_chgParamAry[nDstParameter] == 0x7FFFFFFF )
				m_chgParamAry[nDstParameter]	= 0;
			m_chgParamAry[nDstParameter]++;
		}
		else
			m_chgParamAry[nDstParameter] = nChgParameterValue;
	}

	if( ( fSuccess & bSend ) == TRUE ) 
		g_pUserMng.AddSetDestParam( this, nDstParameter, nAdjParameterValue, nChgParameterValue );
	


// 	if ( nAdjParameterValue == -1 )
// 	{
// 		v6 = GetMaxHitPoint();
// 		SetPointParam( nDstParameter, v6, 0);
// 	}
// 	else
// 	{
// 		v7 = sub_646450(pThis);
// 		CMover::SetPointParam(pThis, nDstParameter, nAdjParameterValue + v7, 0);
// 	}
// 	v5 = CMover::GetAdjParam(pThis, 94);
// 	if ( v5 > 0 )
// 	{
// 		CMover::ResetDestParam(pThis, 94, 0, 1);
// 		v5 = sub_6396C0(pThis, 94);
// 	}
}