Skip to content

Commit

Permalink
Refactor|Renderer: Restructured vector light generation
Browse files Browse the repository at this point in the history
Revised the high-level model for the generation of vector lights,
making use of C++11 lambdas to improve SoC and better locality.
RenderSystem now has ownership of the vector light lists.

Todo for later: There is no need to expose the vector light list
instances to users of RenderSystem.
  • Loading branch information
danij-deng committed May 2, 2015
1 parent 6a6a7a3 commit 1328c46
Show file tree
Hide file tree
Showing 19 changed files with 708 additions and 784 deletions.
3 changes: 1 addition & 2 deletions doomsday/client/client.pro
Expand Up @@ -309,9 +309,9 @@ DENG_HEADERS += \
include/render/skyfixedge.h \
include/render/surfacedecorator.h \
include/render/trianglestripbuilder.h \
include/render/vectorlightdata.h \
include/render/viewports.h \
include/render/vissprite.h \
include/render/vlight.h \
include/render/vr.h \
include/render/walledge.h \
include/render/wallspec.h \
Expand Down Expand Up @@ -640,7 +640,6 @@ SOURCES += \
src/render/trianglestripbuilder.cpp \
src/render/viewports.cpp \
src/render/vissprite.cpp \
src/render/vlight.cpp \
src/render/vr.cpp \
src/render/walledge.cpp \
src/render/wallspec.cpp \
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/include/de_render.h
Expand Up @@ -38,7 +38,6 @@
#include "render/billboard.h"
#include "render/cameralensfx.h"
#include "render/vissprite.h"
#include "render/vlight.h"
#endif

#include "r_util.h"
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/render/projectedtexturedata.h
Expand Up @@ -25,6 +25,7 @@

/**
* POD for a texture => surface projection.
* @ingroup render
*/
struct ProjectedTextureData
{
Expand Down
15 changes: 15 additions & 0 deletions doomsday/client/include/render/rend_main.h
Expand Up @@ -33,6 +33,7 @@

class Sector;
class SectorCluster;
struct VectorLightData;

namespace de {
class Map;
Expand Down Expand Up @@ -233,6 +234,20 @@ de::Vector3f Rend_LuminousColor(de::Vector3f const &color, float light);
*/
coord_t Rend_PlaneGlowHeight(float intensity);

/**
* @param point World space point to evaluate.
* @param ambientColor Ambient color of the object being lit.
* @param subspace Subspace in which @a origin resides.
* @param starkLight @c true= World light has a more pronounced affect.
*
* @todo Does not belong here.
*/
de::duint Rend_CollectAffectingLights(de::Vector3d const &point,
de::Vector3f const &ambientColor = de::Vector3f(1, 1, 1), ConvexSubspace *subspace = nullptr,
bool starkLight = false);

void Rend_DrawVectorLight(VectorLightData const &vlight, dfloat alpha);

/**
* Selects a Material for the given map @a surface considering the current map
* renderer configuration.
Expand Down
84 changes: 66 additions & 18 deletions doomsday/client/include/render/rendersystem.h
Expand Up @@ -27,6 +27,7 @@
#include "DrawLists"
#include "settingsregister.h"
#include "projectedtexturedata.h"
#include "vectorlightdata.h"

class AngleClipper;
class ModelRenderer;
Expand Down Expand Up @@ -64,6 +65,7 @@ struct Store
uint vertCount, vertMax;
};

/// @todo make private to RenderSystem
struct ProjectionList
{
struct Node
Expand All @@ -73,25 +75,45 @@ struct ProjectionList
};

Node *head = nullptr;
bool sortByLuma; ///< @c true= Sort from brightest to darkest.
bool sortByLuma; ///< @c true= Sort from brightest to darkest.

static void init();

static void reset();
static void rewind();

inline ProjectionList &operator << (ProjectedTextureData &texp) { return add(texp); }

ProjectionList &add(ProjectedTextureData &texp);

private:
// Projection list nodes.
static Node *firstNode;
static Node *cursorNode;

static Node *newNode();
};

/// Average color * alpha.
static dfloat luminosity(ProjectedTextureData const &texp);
/// @todo make private to RenderSystem
struct VectorLightList
{
struct Node
{
Node *next, *nextUsed;
VectorLightData vlight;
};

Node *head = nullptr;

static void init();
static void rewind();

inline VectorLightList &operator << (VectorLightData &texp) { return add(texp); }

VectorLightList &add(VectorLightData &texp);

private:
static Node *firstNode;
static Node *cursorNode;

static Node *newNode();
};

/**
Expand Down Expand Up @@ -125,25 +147,30 @@ class RenderSystem : public de::System
*/
Store &buffer();

void clearDrawLists();

void resetDrawLists();

/**
* Provides access to the DrawLists collection for conveniently writing geometry.
*/
DrawLists &drawLists();

public: // Texture => surface projection lists -----------------------------------
/**
* To be called manually, to clear all persistent data held by/for the draw lists
* (e.g., during re-initialization).
*
* @todo Use a de::Observers based mechanism.
*/
void clearDrawLists();

/**
* To be called to initialize the projector when the current map changes.
* @todo make private
* @todo Use a de::Observers based mechanism.
*/
void projectorInitForMap(de::Map &map);
void worldSystemMapChanged(de::Map &map);

/**
* To be called at the start of a render frame to clear the projection lists
* to prepare for subsequent drawing.
* @todo Use a de::Observers based mechanism.
*/
void projectorReset();
void beginFrame();

public: // Texture => surface projection lists -----------------------------------

/**
* Find/create a new projection list.
Expand All @@ -152,7 +179,7 @@ class RenderSystem : public de::System
* list index is non-zero return the associated list. Otherwise
* allocate a new list and write it's index back to this address.
*
* @param sortByLuma @c true= The list should maintain luma-sorted order.
* @param sortByLuma @c true= Maintain a luminosity sorted order (descending).
*
* @return ProjectionList associated with the (possibly newly attributed) index.
*/
Expand All @@ -166,6 +193,27 @@ class RenderSystem : public de::System
*/
de::LoopResult forAllSurfaceProjections(de::duint listIdx, std::function<de::LoopResult (ProjectedTextureData const &)> func) const;

public: // VectorLight affection lists -------------------------------------------

/**
* Find/create a new vector light list.
*
* @param listIdx Address holding the list index to retrieve. If the referenced
* list index is non-zero return the associated list. Otherwise
* allocate a new list and write it's index back to this address.
*
* @return VectorLightList associated with the (possibly newly attributed) index.
*/
VectorLightList &findVectorLightList(de::duint *listIdx);

/**
* Iterate through the referenced vector light list.
*
* @param listIdx Unique identifier of the list to process.
* @param func Callback to make for each VectorLight.
*/
de::LoopResult forAllVectorLights(de::duint listIdx, std::function<de::LoopResult (VectorLightData const &)> func);

public:
/**
* Register the console commands, variables, etc..., of this module.
Expand Down
40 changes: 40 additions & 0 deletions doomsday/client/include/render/vectorlightdata.h
@@ -0,0 +1,40 @@
/** @file vectorlightdata.h Vector light source data.
*
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_RENDER_VECTORLIGHTDATA_H
#define CLIENT_RENDER_VECTORLIGHTDATA_H

#include <de/Vector>

/**
* POD for a vector light source affection.
* @ingroup render
*/
struct VectorLightData
{
de::dfloat approxDist; ///< Only an approximation.
de::Vector3f direction; ///< Normalized vector from light origin to illumination point.
de::Vector3f color; ///< How intense the light is (0..1, RGB).
de::dfloat offset;
de::dfloat lightSide;
de::dfloat darkSide; ///< Factors for world light.
bool affectedByAmbient;
};

#endif // CLIENT_RENDER_VECTORLIGHTDATA_H
82 changes: 0 additions & 82 deletions doomsday/client/include/render/vlight.h

This file was deleted.

14 changes: 9 additions & 5 deletions doomsday/client/include/world/mapobject.h
@@ -1,7 +1,7 @@
/** @file mapobject.h Base class for all world map objects.
*
* @authors Copyright © 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2013-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -73,6 +73,10 @@ class MapObject
*/
de::Vector3d const &origin() const;

inline de::ddouble x() const { return origin().x; }
inline de::ddouble y() const { return origin().y; }
inline de::ddouble z() const { return origin().z; }

/**
* Change the origin of the object in map space.
*
Expand Down Expand Up @@ -119,7 +123,7 @@ class MapObject
*
* @see setIndexInMap()
*/
int indexInMap() const;
de::dint indexInMap() const;

/**
* Change the "in-map" index attributed to the map object.
Expand All @@ -129,12 +133,12 @@ class MapObject
*
* @see indexInMap()
*/
void setIndexInMap(int newIndex = NoIndex);
void setIndexInMap(de::dint newIndex = NoIndex);

private:
DENG2_PRIVATE(d)
};

} // namespace de
} // namespace de

#endif // DENG_WORLD_MAPOBJECT_H
#endif // DENG_WORLD_MAPOBJECT_H

0 comments on commit 1328c46

Please sign in to comment.