Skip to content

Commit

Permalink
Renderer|SectorCluster|BspLeaf: SectorCluster routes BiasDigests to s…
Browse files Browse the repository at this point in the history
…urfaces

Leaf-level granularity for routing change notifications is wrong as
this assumes there is at least one surface geometry at each leaf.
A binary space partition does not inherently mean a convex subspace
will exist at the leaf. The subspace geometry is only fully defined
(or inferred) at a higher level.

Previously leafs were given responsibility of routing bias lighting
change digests because no other component had direct access to all
of the internal surface geometries.

However, since the introduction of the half-edge data structure it
is now easily possible to navigate to any element in the map geometry
mesh from anywhere else (provided they are connected by at least one
edge, of course).

This means this routing logic can now be placed in SectorCluster so
that we can take advantage of the extra spatial knowledge.

Todo: SectorCluster should also be responsible for surface BiasIllum
generation and management. Presently an illumination point is needed
for every face => vertex interception in the half-edge data structure
despite that many will never be used. SectorCluster has the necessary
knowledge to avoid allocating illumination points for internal edges
with no possible surface (inherently zero-area and will remain so,
regardless of plane movement or map hack mappings).
  • Loading branch information
danij-deng committed Apr 28, 2014
1 parent 08ba4df commit 0105827
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/include/render/lightgrid.h
Expand Up @@ -90,8 +90,8 @@ class LightGrid
* @param point 3D point.
*
* @return Evaluated color at the specified point.
* - [x, y, z] = RGB color with premultiplied luminance factor
* - [w] = luminance factor (i.e., light level)
* - [x, y, z] = RGB color with premultiplied light intensity factor
* - [w] = light intensity factor (i.e., light level)
*/
Vector4f evaluate(Vector3d const &point);

Expand Down
10 changes: 10 additions & 0 deletions doomsday/client/include/world/sectorcluster.h
Expand Up @@ -39,6 +39,9 @@
#include <QList>

class BspLeaf;
#ifdef __CLIENT__
class BiasDigest;
#endif

/**
* Adjacent BSP leafs in the sector (i.e., those which share one or more
Expand Down Expand Up @@ -230,6 +233,13 @@ class SectorCluster
*/
AudioEnvironmentFactors const &reverb() const;

/**
* Apply bias lighting changes to @em all surfaces within the cluster.
*
* @param changes Digest of lighting changes to be applied.
*/
void applyBiasDigest(BiasDigest &changes);

/**
* Returns the unique identifier of the light source.
*/
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/lightgrid.cpp
Expand Up @@ -121,7 +121,7 @@ DENG2_PIMPL(LightGrid)
* Construct a new light block using the source specified as the @em primary
* illumination source for the block.
*
* @param primarySource Primary illumation. Use @c 0 to create a "null-block".
* @param primarySource Primary illumination. Use @c 0 to create a "null-block".
*/
LightBlock(IBlockLightSource *primarySource = 0)
: bias(0), source(primarySource)
Expand Down
26 changes: 0 additions & 26 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -474,13 +474,6 @@ void BspLeaf::updateBiasAfterGeometryMove(int group)
}
}

static void applyBiasDigestToWallSections(HEdge *hedge, BiasDigest &changes)
{
if(!hedge || !hedge->hasMapElement())
return;
hedge->mapElementAs<LineSideSegment>().applyBiasDigest(changes);
}

void BspLeaf::applyBiasDigest(BiasDigest &changes)
{
if(!hasPoly()) return;
Expand All @@ -490,25 +483,6 @@ void BspLeaf::applyBiasDigest(BiasDigest &changes)
{
it.value().biasTracker.applyChanges(changes);
}

HEdge *base = poly().hedge();
HEdge *hedge = base;
do
{
applyBiasDigestToWallSections(hedge, changes);
} while((hedge = &hedge->next()) != base);

foreach(Mesh *mesh, extraMeshes())
foreach(HEdge *hedge, mesh->hedges())
{
applyBiasDigestToWallSections(hedge, changes);
}

foreach(Polyobj *polyobj, d->polyobjs)
foreach(HEdge *hedge, polyobj->mesh().hedges())
{
applyBiasDigestToWallSections(hedge, changes);
}
}

void BspLeaf::lightBiasPoly(int group, Vector3f const *posCoords, Vector4f *colorCoords)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -1277,9 +1277,9 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
* Apply changes to all surfaces:
*/
bias.lastChangeOnFrame = R_FrameCount();
foreach(BspLeaf *bspLeaf, bspLeafs)
foreach(SectorCluster *cluster, clusters)
{
bspLeaf->applyBiasDigest(allChanges);
cluster->applyBiasDigest(allChanges);
}
}

Expand Down
34 changes: 34 additions & 0 deletions doomsday/client/src/world/sectorcluster.cpp
Expand Up @@ -982,6 +982,40 @@ bool SectorCluster::hasSkyMaskedPlane() const
return false;
}

static void applyBiasDigestToWallSections(HEdge *hedge, BiasDigest &changes)
{
if(!hedge || !hedge->hasMapElement())
return;
hedge->mapElementAs<LineSideSegment>().applyBiasDigest(changes);
}

void SectorCluster::applyBiasDigest(BiasDigest &changes)
{
foreach(BspLeaf *bspLeaf, d->bspLeafs)
{
bspLeaf->applyBiasDigest(changes);

HEdge *base = bspLeaf->poly().hedge();
HEdge *hedge = base;
do
{
applyBiasDigestToWallSections(hedge, changes);
} while((hedge = &hedge->next()) != base);

foreach(Mesh *mesh, bspLeaf->extraMeshes())
foreach(HEdge *hedge, mesh->hedges())
{
applyBiasDigestToWallSections(hedge, changes);
}

foreach(Polyobj *polyobj, bspLeaf->polyobjs())
foreach(HEdge *hedge, polyobj->mesh().hedges())
{
applyBiasDigestToWallSections(hedge, changes);
}
}
}

SectorCluster::LightId SectorCluster::lightSourceId() const
{
/// @todo Need unique cluster ids.
Expand Down

0 comments on commit 0105827

Please sign in to comment.