Skip to content

Commit

Permalink
Refactor|Map Renderer|Client: Cleaned up dynamic light projection
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Sep 5, 2013
1 parent 2d93713 commit 7fa23c2
Show file tree
Hide file tree
Showing 8 changed files with 828 additions and 144 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -284,6 +284,7 @@ DENG_HEADERS += \
include/render/lightgrid.h \
include/render/lumobj.h \
include/render/materialcontext.h \
include/render/projector.h \
include/render/r_draw.h \
include/render/r_main.h \
include/render/r_shadow.h \
Expand Down Expand Up @@ -622,6 +623,7 @@ SOURCES += \
src/render/huecirclevisual.cpp \
src/render/lightgrid.cpp \
src/render/lumobj.cpp \
src/render/projector.cpp \
src/render/r_draw.cpp \
src/render/r_fakeradio.cpp \
src/render/r_main.cpp \
Expand Down
7 changes: 4 additions & 3 deletions doomsday/client/include/de_render.h
Expand Up @@ -25,16 +25,17 @@
#include "render/r_main.h"

#ifdef __CLIENT__
#include "render/rend_main.h"
#include "render/r_draw.h"
#include "render/r_things.h"
#include "render/lightgrid.h"
#include "render/lumobj.h"
#include "render/projector.h"
#include "render/r_draw.h"
#include "render/r_shadow.h"
#include "render/r_things.h"
#include "render/rend_clip.h"
#include "render/rend_halo.h"
#include "render/rend_list.h"
#include "render/rend_particle.h"
#include "render/rend_main.h"
#include "render/rend_model.h"
#include "render/rend_shadow.h"
#include "render/rend_fakeradio.h"
Expand Down
131 changes: 131 additions & 0 deletions doomsday/client/include/render/projector.h
@@ -0,0 +1,131 @@
/** @file projector.h Texture coordinate projector and projection lists.
*
* @todo: This module should be replaced with a system which decentralizes the
* projection lists such that these can be managed piecewise and possibly used
* for drawing multiple frames.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 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 DENG_CLIENT_RENDER_PROJECTOR_H
#define DENG_CLIENT_RENDER_PROJECTOR_H

#include <de/Matrix>
#include <de/Vector>

#include "api_gl.h" // DGLuint

#include "world/map.h"

class BspLeaf;

/**
* Dynlight stores a luminous object => surface projection.
*/
struct dynlight_t
{
DGLuint texture;
de::Vector2f topLeft, bottomRight;
de::Vector4f color;
};

/**
* To be called to initialize the projector when the current map changes.
*/
void Rend_ProjectorInitForMap(de::Map &map);

/**
* To be called at the start of a render frame to clear the projection lists
* to prepare for subsequent drawing.
*/
void Rend_ProjectorReset();

/**
* @defgroup projectLightFlags Flags for Rend_ProjectLumobjs
* @ingroup flags
*/
///@{
#define PLF_SORT_LUMINOSITY_DESC 0x1 ///< Sort by descending luminosity, brightest to dullest.
#define PLF_TEX_FLOOR 0x4 ///< Prefer the "floor" slot when picking textures.
#define PLF_TEX_CEILING 0x8 ///< Prefer the "ceiling" slot when picking textures.
///@}

/**
* Project all lumobjs affecting the given quad (world space), calculate
* coordinates (in texture space) then store into a new list of projections.
*
* @pre The coordinates of the given quad must be contained wholly within
* the BSP leaf specified. This is due to an optimization within the lumobj
* management which separates them according to their position in the BSP.
*
* @param flags @ref projectLightFlags
* @param bspLeaf BspLeaf within which the quad wholly resides.
* @param blendFactor Multiplied with projection alpha.
* @param topLeft Top left coordinates of the surface being projected to.
* @param bottomRight Bottom right coordinates of the surface being projected to.
* @param tangentMatrix Normalized tangent space matrix of the surface being projected to.
* @param lmap Semantic identifier of the lightmap to use.
*
* Return values:
* @param listIdx If projected to, the identifier of the resultant list
* (1-based) is written here. If a projection list already
* exists it will be reused.
*/
void Rend_ProjectLumobjs(int flags, BspLeaf *bspLeaf, float blendFactor,
de::Vector3d const &topLeft, de::Vector3d const &bottomRight,
de::Matrix3f const &tangentMatrix, /*Lumobj::LightmapSemantic lightmap,*/
uint &listIdx);

/**
* Project all plane glows affecting the given quad (world space), calculate
* coordinates (in texture space) then store into a new list of projections.
*
* @pre The coordinates of the given quad must be contained wholly within
* the BSP leaf specified. This is due to an optimization within the lumobj
* management which separates them according to their position in the BSP.
*
* @param flags @ref projectLightFlags
* @param bspLeaf BspLeaf within which the quad wholly resides.
* @param blendFactor Multiplied with projection alpha.
* @param topLeft Top left coordinates of the surface being projected to.
* @param bottomRight Bottom right coordinates of the surface being projected to.
* @param tangentMatrix Normalized tangent space matrix of the surface being projected to.
*
* Return values:
* @param listIdx If projected to, the identifier of the resultant list
* (1-based) is written here. If a projection list already
* exists it will be reused.
*/
void Rend_ProjectPlaneGlows(int flags, BspLeaf *bspLeaf, float blendFactor,
de::Vector3d const &topLeft, de::Vector3d const &bottomRight,
de::Matrix3f const &tangentMatrix, uint &listIdx);

/**
* Iterate over projections in the identified surface-projection list, making
* a callback for each visited. Iteration ends when all selected projections
* have been visited or a callback returns non-zero.
*
* @param listIdx Unique identifier of the list to process.
* @param callback Callback to make for each visited projection.
* @param context Passed to the callback.
*
* @return @c 0 iff iteration completed wholly.
*/
int Rend_IterateProjectionList(uint listIdx, int (*callback) (dynlight_t const *, void *),
void *context = 0);

#endif // DENG_CLIENT_RENDER_PROJECTOR_H
9 changes: 6 additions & 3 deletions doomsday/client/include/render/r_shadow.h
Expand Up @@ -63,11 +63,14 @@ float R_ShadowAttenuationFactor(coord_t distance);
* @param bottomRight Bottom right coordinates of the surface being projected to.
* @param tangentMatrix Normalized tangent space matrix of the surface being projected to.
*
* @return Projection list identifier if surface is lit else @c 0.
* Return values:
* @param listIdx If projected to, the identifier of the resultant list
* (1-based) is written here. If a projection list already
* exists it will be reused.
*/
uint R_ProjectShadowsToSurface(BspLeaf *bspLeaf, float blendFactor,
void Rend_ProjectMobjShadows(BspLeaf *bspLeaf, float blendFactor,
de::Vector3d const &topLeft, de::Vector3d const &bottomRight,
de::Matrix3f const &tangentMatrix);
de::Matrix3f const &tangentMatrix, uint &listIdx);

/**
* Iterate over projections in the identified shadow-projection list, making
Expand Down
25 changes: 24 additions & 1 deletion doomsday/client/include/render/rend_main.h
Expand Up @@ -67,8 +67,9 @@ DENG_EXTERN_C int useBias;

DENG_EXTERN_C int useDynLights;
DENG_EXTERN_C float dynlightFactor, dynlightFogBright;
DENG_EXTERN_C int rendMaxLumobjs;

DENG_EXTERN_C int useWallGlow;
DENG_EXTERN_C int useGlowOnWalls;
DENG_EXTERN_C float glowFactor, glowHeightFactor;
DENG_EXTERN_C int glowHeightMax;

Expand All @@ -82,6 +83,9 @@ DENG_EXTERN_C int useShinySurfaces;
DENG_EXTERN_C float detailFactor, detailScale;

DENG_EXTERN_C byte devRendSkyAlways;
DENG_EXTERN_C byte rendInfoLums;
DENG_EXTERN_C byte devDrawLums;

DENG_EXTERN_C byte freezeRLs;

void Rend_Register();
Expand Down Expand Up @@ -155,6 +159,25 @@ void Rend_DrawLightModMatrix();
*/
de::Vector3f const &Rend_SectorLightColor(Sector const &sector);

/**
* Blend the given light value with the luminous object's color, applying any
* applicable global modifiers and returns the result.
*
* @param color Source light color.
* @param light Strength of the light on the illumination point.
*
* @return Calculated result.
*/
de::Vector3f Rend_LuminousColor(de::Vector3f const &color, float light);

/**
* Given an @a intensity determine the height of the plane glow, applying any
* applicable global modifiers.
*
* @return Calculated result.
*/
coord_t Rend_PlaneGlowHeight(float intensity);

/**
* Selects a Material for the given map @a surface considering the current map
* renderer configuration.
Expand Down

0 comments on commit 7fa23c2

Please sign in to comment.