Skip to content

Commit

Permalink
Client|Shadow Bias|BiasIllum: Copying bias illuminations and assignin…
Browse files Browse the repository at this point in the history
…g a tracker
  • Loading branch information
danij-deng committed Aug 2, 2013
1 parent 4ab6eb6 commit 51afc7c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
39 changes: 38 additions & 1 deletion doomsday/client/include/render/biasillum.h
Expand Up @@ -20,6 +20,7 @@
#ifndef DENG_RENDER_SHADOWBIAS_ILLUMINATION_H
#define DENG_RENDER_SHADOWBIAS_ILLUMINATION_H

#include <de/Error>
#include <de/Vector>

#include "render/rendpoly.h" /// @todo remove me
Expand All @@ -35,20 +36,56 @@ class BiasTracker;
class BiasIllum
{
public:
/// Required tracker is missing. @ingroup errors
DENG2_ERROR(MissingTrackerError);

/// Maximum number of light contributions.
static int const MAX_CONTRIBUTORS = 6;

/// Minimum intensity for a light contributor.
static float const MIN_INTENSITY; // .005f

public:
BiasIllum(BiasTracker *surface);
/**
* Construct a new bias illumination point.
*
* @param tracker Tracker to assigned to the new point (if any). Note that
* @ref assignTracker() can be used later.
*/
explicit BiasIllum(BiasTracker *tracker = 0);

BiasIllum(BiasIllum const &other);
BiasIllum &operator = (BiasIllum const &other);

/**
* To be called to register the commands and variables of this module.
*/
static void consoleRegister();

/**
* Returns @c true iff a BiasTracker has been assigned for the illumination.
*
* @see setTracker()
*/
bool hasTracker() const;

/**
* Provides access to the currently assigned tracker.
*
* @see hasTracker(), setTracker()
*/
BiasTracker &tracker() const;

/**
* Assign the illumination point to the specified tracker.
*
* @param newTracker New illumination tracker to be assigned. Use @c 0 to
* unassign any current tracker.
*
* @see hasTracker()
*/
void setTracker(BiasTracker *newTracker);

/**
* (Re-)Evaluate lighting for this map point.
*
Expand Down
41 changes: 41 additions & 0 deletions doomsday/client/src/render/biasillum.cpp
Expand Up @@ -53,6 +53,14 @@ DENG2_PIMPL_NOREF(BiasIllum)
interpolating(false)
{}

Instance(Instance const &other)
: tracker(other.tracker),
color(other.color),
dest(other.dest),
updateTime(other.updateTime),
interpolating(other.interpolating)
{}

/**
* Returns a previous light contribution by unique contributor @a index.
*/
Expand All @@ -72,6 +80,8 @@ DENG2_PIMPL_NOREF(BiasIllum)
{
#define COLOR_CHANGE_THRESHOLD 0.1f // Ignore small variations for perf

DENG_ASSERT(tracker != 0);

// Determine the new color (initially, black).
Vector3f newColor;

Expand Down Expand Up @@ -132,6 +142,8 @@ DENG2_PIMPL_NOREF(BiasIllum)
void updateContribution(int index, Vector3d const &point,
Vector3f const &normalAtPoint, MapElement &bspRoot)
{
DENG_ASSERT(tracker != 0);

BiasSource const &source = tracker->contributor(index);

Vector3f &casted = contribution(index);
Expand Down Expand Up @@ -211,6 +223,35 @@ float const BiasIllum::MIN_INTENSITY = .005f;
BiasIllum::BiasIllum(BiasTracker *tracker) : d(new Instance(tracker))
{}

BiasIllum::BiasIllum(BiasIllum const &other) : d(new Instance(*other.d))
{}

BiasIllum &BiasIllum::operator = (BiasIllum const &other)
{
d.reset(new Instance(*other.d));
return *this;
}

bool BiasIllum::hasTracker() const
{
return d->tracker != 0;
}

BiasTracker &BiasIllum::tracker() const
{
if(d->tracker != 0)
{
return *d->tracker;
}
/// @throw MissingTrackerError Attempted with no tracker assigned.
throw MissingTrackerError("BiasIllum::tracker", "No tracker is assigned");
}

void BiasIllum::setTracker(BiasTracker *newTracker)
{
d->tracker = newTracker;
}

void BiasIllum::evaluate(Vector3f &color, Vector3d const &point,
Vector3f const &normalAtPoint, uint biasTime,
/// @todo Refactor away:
Expand Down

0 comments on commit 51afc7c

Please sign in to comment.