Skip to content

Commit

Permalink
PhotonGI can now render black rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Dade916 committed Mar 2, 2019
1 parent dfc1d96 commit 193b87d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 65 deletions.
8 changes: 5 additions & 3 deletions src/slg/engines/caches/photongi/photongicache.cpp
Expand Up @@ -387,9 +387,11 @@ void PhotonGICache::Preprocess() {
SLG_LOG("PhotonGI building radiance photon data");
CreateRadiancePhotons();

SLG_LOG("PhotonGI building radiance photons BVH");
radiancePhotonsBVH = new PGICRadiancePhotonBvh(radiancePhotons,
params.indirect.lookUpRadius, params.indirect.lookUpNormalAngle);
if (radiancePhotons.size() > 0) {
SLG_LOG("PhotonGI building radiance photons BVH");
radiancePhotonsBVH = new PGICRadiancePhotonBvh(radiancePhotons,
params.indirect.lookUpRadius, params.indirect.lookUpNormalAngle);
}
}

//--------------------------------------------------------------------------
Expand Down
124 changes: 62 additions & 62 deletions src/slg/engines/caches/photongi/tracephotonsthread.cpp
Expand Up @@ -373,79 +373,79 @@ void TracePhotonsThread::RenderFunc() {

if (!foundUseful) {
// I was unable to find a useful path. Something wrong. this
// may be an empty scene.
throw runtime_error("Unable to find a useful path in TracePhotonsThread::RenderFunc()");
}

// Trace light paths

u_int currentPhotonsScale = 1;
float mutationSize = 1.f;
u_int acceptedCount = 1;
u_int mutatedCount = 1;
u_int uniformCount = 1;
u_int workToDoIndex = workToDo;
while (workToDoIndex-- && !boost::this_thread::interruption_requested()) {
UniformMutate(rndGen, uniformPathSamples);

if (TracePhotonPath(rndGen, uniformPathSamples, uniformIndirectPhotons,
uniformCausticPhotons)) {
// Add the old current photons (scaled by currentPhotonsScale)
AddPhotons(currentPhotonsScale, currentIndirectPhotons, currentCausticPhotons);

// The candidate path becomes the current one
copy(uniformPathSamples.begin(), uniformPathSamples.end(), currentPathSamples.begin());

currentPhotonsScale = 1;
currentIndirectPhotons = uniformIndirectPhotons;
currentCausticPhotons = uniformCausticPhotons;

++uniformCount;
} else {
// Try a mutation of the current path
Mutate(rndGen, currentPathSamples, candidatePathSamples, mutationSize);
++mutatedCount;

if (TracePhotonPath(rndGen, candidatePathSamples, candidateIndirectPhotons,
candidateCausticPhotons)) {
// may be an empty scene, a dark room, etc.
SLG_LOG("PhotonGI metropolis sampler is unable to find a useful light path");
} else {
// Trace light paths

u_int currentPhotonsScale = 1;
float mutationSize = 1.f;
u_int acceptedCount = 1;
u_int mutatedCount = 1;
u_int uniformCount = 1;
u_int workToDoIndex = workToDo;
while (workToDoIndex-- && !boost::this_thread::interruption_requested()) {
UniformMutate(rndGen, uniformPathSamples);

if (TracePhotonPath(rndGen, uniformPathSamples, uniformIndirectPhotons,
uniformCausticPhotons)) {
// Add the old current photons (scaled by currentPhotonsScale)
AddPhotons(currentPhotonsScale, currentIndirectPhotons, currentCausticPhotons);

// The candidate path becomes the current one
copy(candidatePathSamples.begin(), candidatePathSamples.end(), currentPathSamples.begin());
copy(uniformPathSamples.begin(), uniformPathSamples.end(), currentPathSamples.begin());

currentPhotonsScale = 1;
currentIndirectPhotons = candidateIndirectPhotons;
currentCausticPhotons = candidateCausticPhotons;

++acceptedCount;
} else
++currentPhotonsScale;
currentIndirectPhotons = uniformIndirectPhotons;
currentCausticPhotons = uniformCausticPhotons;

++uniformCount;
} else {
// Try a mutation of the current path
Mutate(rndGen, currentPathSamples, candidatePathSamples, mutationSize);
++mutatedCount;

if (TracePhotonPath(rndGen, candidatePathSamples, candidateIndirectPhotons,
candidateCausticPhotons)) {
// Add the old current photons (scaled by currentPhotonsScale)
AddPhotons(currentPhotonsScale, currentIndirectPhotons, currentCausticPhotons);

// The candidate path becomes the current one
copy(candidatePathSamples.begin(), candidatePathSamples.end(), currentPathSamples.begin());

currentPhotonsScale = 1;
currentIndirectPhotons = candidateIndirectPhotons;
currentCausticPhotons = candidateCausticPhotons;

++acceptedCount;
} else
++currentPhotonsScale;

const float R = acceptedCount / (float)mutatedCount;
// 0.234 => the optimal asymptotic acceptance ratio has been
// derived 23.4% [Roberts et al. 1997]
mutationSize += (R - .234f) / mutatedCount;
}

const float R = acceptedCount / (float)mutatedCount;
// 0.234 => the optimal asymptotic acceptance ratio has been
// derived 23.4% [Roberts et al. 1997]
mutationSize += (R - .234f) / mutatedCount;
}

#ifdef WIN32
// Work around Windows bad scheduling
renderThread->yield();
// Work around Windows bad scheduling
renderThread->yield();
#endif
}
}

// Add the last current photons (scaled by currentPhotonsScale)
if (currentPhotonsScale > 1) {
AddPhotons(currentPhotonsScale, currentIndirectPhotons, currentCausticPhotons);
}
// Add the last current photons (scaled by currentPhotonsScale)
if (currentPhotonsScale > 1) {
AddPhotons(currentPhotonsScale, currentIndirectPhotons, currentCausticPhotons);
}

// Scale all photon values
const float scaleFactor = uniformCount / (float)workToDo;
// Scale all photon values
const float scaleFactor = uniformCount / (float)workToDo;

for (u_int i = indirectPhotonsStart; i < indirectPhotons.size(); ++i)
indirectPhotons[i].alpha *= scaleFactor;
for (u_int i = causticPhotonsStart; i < causticPhotons.size(); ++i)
causticPhotons[i].alpha *= scaleFactor;
for (u_int i = indirectPhotonsStart; i < indirectPhotons.size(); ++i)
indirectPhotons[i].alpha *= scaleFactor;
for (u_int i = causticPhotonsStart; i < causticPhotons.size(); ++i)
causticPhotons[i].alpha *= scaleFactor;
}
} else

//----------------------------------------------------------------------
Expand All @@ -471,7 +471,7 @@ void TracePhotonsThread::RenderFunc() {
}
} else
throw runtime_error("Unknown sampler type in TracePhotonsThread::RenderFunc(): " + ToString(pgic.params.samplerType));

//----------------------------------------------------------------------

// Update size counters
Expand Down

0 comments on commit 193b87d

Please sign in to comment.