Skip to content

Commit

Permalink
Fixed|Shadow Bias|BiasSurface: Latent bias lighting contributions whe…
Browse files Browse the repository at this point in the history
…n surface loses all sources

When recalculating per-vertex bias lighting the special case of a
surface suddenly loosing all light contributions was not handled
correctly. This resulted in latent contributions from sources which
no longer affect the surface continuing to do so.

Todo: BiasSurface::Instance::evalLighting() should be revised as it
is now obvious that a previous refactoring effort to minimize the
effect of source lighting changes was not completed.
  • Loading branch information
danij-deng committed Jul 30, 2013
1 parent fe16a5b commit d212c57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
21 changes: 17 additions & 4 deletions doomsday/client/src/render/biassurface.cpp
Expand Up @@ -208,6 +208,17 @@ DENG2_PIMPL_NOREF(BiasSurface)
if(vi.flags & VertexIllum::Unseen)
{
illumChanged = true;
for(int i = 0; i < MAX_AFFECTED; ++i)
{
BiasSource *source = vi.casted[i].source;
if(!source) continue;

// Remember the earliest time an affecting source changed.
if(latestSourceUpdate < source->lastUpdateTime())
{
latestSourceUpdate = source->lastUpdateTime();
}
}
vi.flags &= ~VertexIllum::Unseen;
}

Expand Down Expand Up @@ -325,11 +336,13 @@ DENG2_PIMPL_NOREF(BiasSurface)
newColor = newColor.min(saturated);

// Is there a new destination?
if(!de::fequal(vi.dest.x, newColor.x, COLOR_CHANGE_THRESHOLD) ||
!de::fequal(vi.dest.y, newColor.y, COLOR_CHANGE_THRESHOLD) ||
!de::fequal(vi.dest.z, newColor.z, COLOR_CHANGE_THRESHOLD))
if(!affecting[0].source ||
(!de::fequal(vi.dest.x, newColor.x, COLOR_CHANGE_THRESHOLD) ||
!de::fequal(vi.dest.y, newColor.y, COLOR_CHANGE_THRESHOLD) ||
!de::fequal(vi.dest.z, newColor.z, COLOR_CHANGE_THRESHOLD)))
{
if(vi.flags & VertexIllum::Interpolating)
if((vi.flags & VertexIllum::Interpolating) &&
affecting[0].source)
{
// Must not lose the half-way interpolation.
Vector3f mid; vi.lerp(mid, biasTime);
Expand Down
9 changes: 7 additions & 2 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -1183,21 +1183,26 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
// Check which sources have changed and update the tracker bits for
// any affected surfaces.
BiasTracker allChanges;
bool needUpdateSurfaces = false;

for(int i = 0; i < bias.sources.count(); ++i)
{
BiasSource *bsrc = bias.sources.at(i);

if(bsrc->trackChanges(allChanges, i, bias.currentTime))
{
// Recalculate which sources affect which surfaces.
bias.lastChangeOnFrame = frameCount;
// We'll need to determine which source => surface affection.
needUpdateSurfaces = true;
}
}

if(!needUpdateSurfaces) return;

/*
* Apply changes to all surfaces:
*/
bias.lastChangeOnFrame = frameCount;

foreach(Segment *seg, segments)
{
seg->updateBiasAffection(allChanges);
Expand Down

0 comments on commit d212c57

Please sign in to comment.