Skip to content

Commit

Permalink
Refactor: Merged render/r_fakeradio.h into render/rend_fakeradio.h
Browse files Browse the repository at this point in the history
Also relocated shadowlink_t here and renamed various functions
according to existing conventions in this module.
  • Loading branch information
danij-deng committed Nov 26, 2012
1 parent 81baee6 commit b3bd7b5
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 162 deletions.
1 change: 0 additions & 1 deletion doomsday/engine/engine.pro
Expand Up @@ -268,7 +268,6 @@ DENG_HEADERS += \
include/network/ui_mpi.h \
include/r_util.h \
include/render/r_draw.h \
include/render/r_fakeradio.h \
include/render/r_main.h \
include/render/r_lgrid.h \
include/render/r_lumobjs.h \
Expand Down
1 change: 0 additions & 1 deletion doomsday/engine/include/de_render.h
Expand Up @@ -24,7 +24,6 @@

#include "render/r_main.h"
#include "render/r_draw.h"
#include "render/r_fakeradio.h"
#include "render/r_lgrid.h"
#include "render/r_lumobjs.h"
#include "render/r_shadow.h"
Expand Down
64 changes: 0 additions & 64 deletions doomsday/engine/include/render/r_fakeradio.h

This file was deleted.

101 changes: 69 additions & 32 deletions doomsday/engine/include/render/rend_fakeradio.h
@@ -1,75 +1,112 @@
/**\file rend_fakeradio.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
/**
* @file rend_fakeradio.h Faked Radiosity Lighting
*
* Perhaps the most distinctive characteristic of radiosity lighting
* is that the corners of a room are slightly dimmer than the rest of
* the surfaces. (It's not the only characteristic, however.) We
* will fake these shadowed areas by generating shadow polygons for
* wall segments and determining, which BSP leaf vertices will be
* shadowed.
*
*\author Copyright © 2004-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2007-2012 Daniel Swanson <danij@dengine.net>
* In other words, walls use shadow polygons (over entire hedges), while
* planes use vertex lighting. Since planes are usually tesselated
* into a great deal of BSP leafs (and triangles), they are better
* suited for vertex lighting. In some cases we will be forced to
* split a BSP leaf into smaller pieces than strictly necessary in
* order to achieve better accuracy in the shadow effect.
*
* 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.
* @author Copyright &copy; 2004-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2012 Daniel Swanson <danij@dengine.net>
*
* 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.
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
* <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, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_RENDER_FAKERADIO_H
#define LIBDENG_RENDER_FAKERADIO_H

#ifdef __cplusplus
extern "C" {
#endif
#include "map/linedef.h"
#include "render/rendpoly.h"

typedef struct shadowlink_s {
struct shadowlink_s *next;
LineDef *lineDef;
byte side;
} shadowlink_t;

typedef struct {
float shadowRGB[3], shadowDark;
float shadowSize;
const shadowcorner_t* botCn, *topCn, *sideCn;
const edgespan_t* spans;
const coord_t* segOffset;
const coord_t* segLength;
const coord_t* linedefLength;
const Sector* frontSec, *backSec;
shadowcorner_t const *botCn, *topCn, *sideCn;
edgespan_t const *spans;
coord_t const *segOffset;
coord_t const *segLength;
coord_t const *linedefLength;
Sector const *frontSec, *backSec;
struct {
struct {
walldivnode_t* firstDiv;
walldivnode_t *firstDiv;
uint divCount;
} left;
struct {
walldivnode_t* firstDiv;
walldivnode_t *firstDiv;
uint divCount;
} right;
} wall;
} rendsegradio_params_t;

#ifdef __cplusplus
extern "C" {
#endif

/// Register the console commands, variables, etc..., of this module.
void Rend_RadioRegister(void);

/**
* To be called after map load to perform necessary initialization within this module.
*/
void Rend_RadioInitForMap(void);

/// @return @c true if @a lineDef qualifies as a (edge) shadow caster.
boolean Rend_RadioIsShadowingLineDef(LineDef *lineDef);

/**
* Updates all the shadow offsets for the given vertex.
*
* @pre Lineowner rings must be set up.
*
* @param vtx Vertex to be updated.
*/
void Rend_RadioUpdateVertexShadowOffsets(Vertex *vtx);

float Rend_RadioCalcShadowDarkness(float lightLevel);

/**
* Called to update the shadow properties used when doing FakeRadio for the
* given linedef.
*/
void Rend_RadioUpdateLinedef(LineDef* line, boolean backSide);
void Rend_RadioUpdateLinedef(LineDef *line, boolean backSide);

/**
* Render FakeRadio for the given hedge section.
*/
void Rend_RadioSegSection(const rvertex_t* rvertices, const rendsegradio_params_t* params);
void Rend_RadioSegSection(rvertex_t const *rvertices, rendsegradio_params_t const *params);

/**
* Render FakeRadio for the given BSP leaf.
*/
void Rend_RadioBspLeafEdges(BspLeaf* bspLeaf);
void Rend_RadioBspLeafEdges(BspLeaf *bspLeaf);

/**
* Render the shadow poly vertices, for debug.
Expand Down
6 changes: 0 additions & 6 deletions doomsday/engine/include/resource/r_data.h
Expand Up @@ -63,12 +63,6 @@ typedef struct glcommand_vertex_s {
int index;
} glcommand_vertex_t;

typedef struct shadowlink_s {
struct shadowlink_s* next;
LineDef* lineDef;
byte side;
} shadowlink_t;

typedef struct {
lumpnum_t lumpNum;
short offX; /// block origin (always UL), which has allready
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/map/dam_main.cpp
Expand Up @@ -354,7 +354,7 @@ boolean DAM_AttemptMapLoad(Uri const* _uri)
// theMap to be set first.
P_SetCurrentMap(map);

R_InitFakeRadioForMap();
Rend_RadioInitForMap();

{ uint startTime = Timer_RealMilliseconds();
GameMap_InitSkyFix(map);
Expand Down
77 changes: 22 additions & 55 deletions doomsday/engine/src/render/r_fakeradio.c
@@ -1,58 +1,32 @@
/**\file r_fakeradio.c
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2012 Daniel Swanson <danij@dengine.net>
/**
* @file r_fakeradio.c Faked Radiosity Lighting
*
* 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.
* @author Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2012 Daniel Swanson <danij@dengine.net>
*
* 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.
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

/**
* Runtime Map Shadowing (FakeRadio)
* <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, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

// HEADER FILES ------------------------------------------------------------

#include "de_base.h"
#include "de_console.h"
#include "de_misc.h"
#include "de_play.h"

// MACROS ------------------------------------------------------------------

// TYPES -------------------------------------------------------------------

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

// PUBLIC DATA DEFINITIONS -------------------------------------------------

// PRIVATE DATA DEFINITIONS ------------------------------------------------
#include "de_render.h"

static zblockset_t *shadowLinksBlockSet;

// CODE --------------------------------------------------------------------

/**
* Line1 and line2 are the (dx,dy)s for two lines, connected at the
* origin (0,0). Dist1 and dist2 are the distances from these lines.
Expand Down Expand Up @@ -122,14 +96,7 @@ double R_ShadowEdgeWidth(const pvec2d_t edge)
return normalWidth;
}

/**
* Updates all the shadow offsets for the given vertex.
*
* \pre Lineowner rings MUST be set up.
*
* @param vtx Ptr to the vertex being updated.
*/
void R_UpdateVertexShadowOffsets(Vertex* vtx)
void Rend_RadioUpdateVertexShadowOffsets(Vertex* vtx)
{
vec2d_t left, right;

Expand Down Expand Up @@ -221,7 +188,7 @@ int RIT_ShadowBspLeafLinker(BspLeaf* bspLeaf, void* parm)
return false; // Continue iteration.
}

boolean R_IsShadowingLinedef(LineDef* line)
boolean Rend_RadioIsShadowingLineDef(LineDef* line)
{
if(line)
{
Expand All @@ -236,7 +203,7 @@ boolean R_IsShadowingLinedef(LineDef* line)
return false;
}

void R_InitFakeRadioForMap(void)
void Rend_RadioInitForMap(void)
{
uint startTime = Timer_RealMilliseconds();

Expand All @@ -249,7 +216,7 @@ void R_InitFakeRadioForMap(void)

for(i = 0; i < NUM_VERTEXES; ++i)
{
R_UpdateVertexShadowOffsets(VERTEX_PTR(i));
Rend_RadioUpdateVertexShadowOffsets(VERTEX_PTR(i));
}

/**
Expand All @@ -269,7 +236,7 @@ void R_InitFakeRadioForMap(void)
for(i = 0; i < NUM_LINEDEFS; ++i)
{
LineDef* line = LINE_PTR(i);
if(!R_IsShadowingLinedef(line)) continue;
if(!Rend_RadioIsShadowingLineDef(line)) continue;

for(j = 0; j < 2; ++j)
{
Expand Down
6 changes: 4 additions & 2 deletions doomsday/engine/src/render/rend_fakeradio.c
Expand Up @@ -32,6 +32,7 @@
#include "gl/sys_opengl.h"
#include "m_vector.h"
#include "resource/materialvariant.h"
#include "render/rendpoly.h"

#define MIN_OPEN (.1f)
#define EDGE_OPEN_THRESHOLD (8) // world units (Z axis)
Expand Down Expand Up @@ -967,8 +968,9 @@ static void quadTexCoords(rtexcoord_t* tc, const rvertex_t* rverts,
tc[0].st[1] = tc[3].st[1] + (rverts[3].pos[VZ] - rverts[2].pos[VZ]) / texHeight;
}

static void renderShadowSeg(const rvertex_t* origVertices, const rendershadowseg_params_t* segp,
const rendsegradio_params_t* p)
static void renderShadowSeg(const rvertex_t* origVertices,
const rendershadowseg_params_t* segp,
const rendsegradio_params_t* p)
{
float texOrigin[2][3];
ColorRawf* rcolors;
Expand Down

0 comments on commit b3bd7b5

Please sign in to comment.