2017-01-03 06:17:54 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
//
|
|
|
|
// This source is available for distribution and/or modification
|
|
|
|
// only under the terms of the DOOM Source Code License as
|
|
|
|
// published by id Software. All rights reserved.
|
|
|
|
//
|
|
|
|
// The source is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
|
|
|
// for more details.
|
|
|
|
//
|
2016-12-30 07:31:02 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "templates.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "doomdata.h"
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "swrenderer/r_main.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "stats.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "g_level.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/scene/r_bsp.h"
|
2016-12-30 07:31:02 +00:00
|
|
|
#include "r_decal.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/scene/r_3dfloors.h"
|
2016-12-30 07:31:02 +00:00
|
|
|
#include "swrenderer/drawers/r_draw.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "r_data/colormaps.h"
|
2017-01-01 09:28:35 +00:00
|
|
|
#include "swrenderer/line/r_wallsetup.h"
|
|
|
|
#include "swrenderer/line/r_walldraw.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/segments/r_drawsegment.h"
|
|
|
|
#include "swrenderer/scene/r_portal.h"
|
2017-01-09 12:53:02 +00:00
|
|
|
#include "swrenderer/things/r_wallsprite.h"
|
2016-12-30 07:31:02 +00:00
|
|
|
#include "swrenderer/r_memory.h"
|
|
|
|
|
2017-01-11 14:41:42 +00:00
|
|
|
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor);
|
|
|
|
|
2016-12-30 07:31:02 +00:00
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-01-11 17:10:51 +00:00
|
|
|
void RenderDecal::RenderDecals(side_t *sidedef, drawseg_t *draw_segment, int wallshade, float lightleft, float lightstep, seg_t *curline, const FWallCoords &wallC)
|
2016-12-30 07:31:02 +00:00
|
|
|
{
|
|
|
|
for (DBaseDecal *decal = sidedef->AttachedDecals; decal != NULL; decal = decal->WallNext)
|
|
|
|
{
|
2017-01-11 17:10:51 +00:00
|
|
|
Render(sidedef, decal, draw_segment, wallshade, lightleft, lightstep, curline, wallC, 0);
|
2016-12-30 07:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass = 0: when seg is first drawn
|
|
|
|
// = 1: drawing masked textures (including sprites)
|
|
|
|
// Currently, only pass = 0 is done or used
|
|
|
|
|
2017-01-11 17:10:51 +00:00
|
|
|
void RenderDecal::Render(side_t *wall, DBaseDecal *decal, drawseg_t *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, FWallCoords WallC, int pass)
|
2016-12-30 07:31:02 +00:00
|
|
|
{
|
|
|
|
DVector2 decal_left, decal_right, decal_pos;
|
|
|
|
int x1, x2;
|
|
|
|
double yscale;
|
|
|
|
BYTE flipx;
|
|
|
|
double zpos;
|
|
|
|
int needrepeat = 0;
|
|
|
|
sector_t *front, *back;
|
|
|
|
bool calclighting;
|
|
|
|
bool rereadcolormap;
|
|
|
|
FDynamicColormap *usecolormap;
|
2017-01-03 19:53:40 +00:00
|
|
|
float light = 0;
|
2017-01-09 12:53:02 +00:00
|
|
|
short *mfloorclip;
|
|
|
|
short *mceilingclip;
|
2016-12-30 07:31:02 +00:00
|
|
|
|
|
|
|
if (decal->RenderFlags & RF_INVISIBLE || !viewactive || !decal->PicNum.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Determine actor z
|
|
|
|
zpos = decal->Z;
|
|
|
|
front = curline->frontsector;
|
|
|
|
back = (curline->backsector != NULL) ? curline->backsector : curline->frontsector;
|
|
|
|
switch (decal->RenderFlags & RF_RELMASK)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
zpos = decal->Z;
|
|
|
|
break;
|
|
|
|
case RF_RELUPPER:
|
|
|
|
if (curline->linedef->flags & ML_DONTPEGTOP)
|
|
|
|
{
|
|
|
|
zpos = decal->Z + front->GetPlaneTexZ(sector_t::ceiling);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zpos = decal->Z + back->GetPlaneTexZ(sector_t::ceiling);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RF_RELLOWER:
|
|
|
|
if (curline->linedef->flags & ML_DONTPEGBOTTOM)
|
|
|
|
{
|
|
|
|
zpos = decal->Z + front->GetPlaneTexZ(sector_t::ceiling);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zpos = decal->Z + back->GetPlaneTexZ(sector_t::floor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RF_RELMID:
|
|
|
|
if (curline->linedef->flags & ML_DONTPEGBOTTOM)
|
|
|
|
{
|
|
|
|
zpos = decal->Z + front->GetPlaneTexZ(sector_t::floor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zpos = decal->Z + front->GetPlaneTexZ(sector_t::ceiling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:51:34 +00:00
|
|
|
FTexture *WallSpriteTile = TexMan(decal->PicNum, true);
|
2016-12-30 07:31:02 +00:00
|
|
|
flipx = (BYTE)(decal->RenderFlags & RF_XFLIP);
|
|
|
|
|
|
|
|
if (WallSpriteTile == NULL || WallSpriteTile->UseType == FTexture::TEX_Null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine left and right edges of sprite. Since this sprite is bound
|
|
|
|
// to a wall, we use the wall's angle instead of the decal's. This is
|
|
|
|
// pretty much the same as what R_AddLine() does.
|
|
|
|
|
|
|
|
FWallCoords savecoord = WallC;
|
|
|
|
|
|
|
|
double edge_right = WallSpriteTile->GetWidth();
|
|
|
|
double edge_left = WallSpriteTile->LeftOffset;
|
|
|
|
edge_right = (edge_right - edge_left) * decal->ScaleX;
|
|
|
|
edge_left *= decal->ScaleX;
|
|
|
|
|
|
|
|
double dcx, dcy;
|
|
|
|
decal->GetXY(wall, dcx, dcy);
|
|
|
|
decal_pos = { dcx, dcy };
|
|
|
|
|
|
|
|
DVector2 angvec = (curline->v2->fPos() - curline->v1->fPos()).Unit();
|
2016-12-30 14:05:57 +00:00
|
|
|
float maskedScaleY;
|
2016-12-30 07:31:02 +00:00
|
|
|
|
|
|
|
decal_left = decal_pos - edge_left * angvec - ViewPos;
|
|
|
|
decal_right = decal_pos + edge_right * angvec - ViewPos;
|
|
|
|
|
|
|
|
if (WallC.Init(decal_left, decal_right, TOO_CLOSE_Z))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
x1 = WallC.sx1;
|
|
|
|
x2 = WallC.sx2;
|
|
|
|
|
|
|
|
if (x1 >= clipper->x2 || x2 <= clipper->x1)
|
|
|
|
goto done;
|
|
|
|
|
2017-01-03 17:57:48 +00:00
|
|
|
FWallTmapVals WallT;
|
2016-12-30 07:31:02 +00:00
|
|
|
WallT.InitFromWallCoords(&WallC);
|
|
|
|
|
|
|
|
// Get the top and bottom clipping arrays
|
|
|
|
switch (decal->RenderFlags & RF_CLIPMASK)
|
|
|
|
{
|
|
|
|
case RF_CLIPFULL:
|
|
|
|
if (curline->backsector == NULL)
|
|
|
|
{
|
|
|
|
if (pass != 0)
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
mceilingclip = walltop;
|
|
|
|
mfloorclip = wallbottom;
|
|
|
|
}
|
|
|
|
else if (pass == 0)
|
|
|
|
{
|
|
|
|
mceilingclip = walltop;
|
2017-01-04 14:39:47 +00:00
|
|
|
mfloorclip = RenderBSP::Instance()->ceilingclip;
|
2016-12-30 07:31:02 +00:00
|
|
|
needrepeat = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mceilingclip = openings + clipper->sprtopclip - clipper->x1;
|
|
|
|
mfloorclip = openings + clipper->sprbottomclip - clipper->x1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RF_CLIPUPPER:
|
|
|
|
if (pass != 0)
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
mceilingclip = walltop;
|
2017-01-04 14:39:47 +00:00
|
|
|
mfloorclip = RenderBSP::Instance()->ceilingclip;
|
2016-12-30 07:31:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RF_CLIPMID:
|
|
|
|
if (curline->backsector != NULL && pass != 2)
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
mceilingclip = openings + clipper->sprtopclip - clipper->x1;
|
|
|
|
mfloorclip = openings + clipper->sprbottomclip - clipper->x1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RF_CLIPLOWER:
|
|
|
|
if (pass != 0)
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
2017-01-04 14:39:47 +00:00
|
|
|
mceilingclip = RenderBSP::Instance()->floorclip;
|
2016-12-30 07:31:02 +00:00
|
|
|
mfloorclip = wallbottom;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
yscale = decal->ScaleY;
|
|
|
|
dc_texturemid = WallSpriteTile->TopOffset + (zpos - ViewPos.Z) / yscale;
|
|
|
|
|
|
|
|
// Clip sprite to drawseg
|
|
|
|
x1 = MAX<int>(clipper->x1, x1);
|
|
|
|
x2 = MIN<int>(clipper->x2, x2);
|
|
|
|
if (x1 >= x2)
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2017-01-03 17:57:48 +00:00
|
|
|
PrepWall(swall, lwall, WallSpriteTile->GetWidth(), x1, x2, WallT);
|
2016-12-30 07:31:02 +00:00
|
|
|
|
|
|
|
if (flipx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int right = (WallSpriteTile->GetWidth() << FRACBITS) - 1;
|
|
|
|
|
|
|
|
for (i = x1; i < x2; i++)
|
|
|
|
{
|
|
|
|
lwall[i] = right - lwall[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare lighting
|
|
|
|
calclighting = false;
|
|
|
|
usecolormap = basecolormap;
|
|
|
|
rereadcolormap = true;
|
|
|
|
|
|
|
|
// Decals that are added to the scene must fade to black.
|
|
|
|
if (decal->RenderStyle == LegacyRenderStyles[STYLE_Add] && usecolormap->Fade != 0)
|
|
|
|
{
|
|
|
|
usecolormap = GetSpecialLights(usecolormap->Color, 0, usecolormap->Desaturate);
|
|
|
|
rereadcolormap = false;
|
|
|
|
}
|
|
|
|
|
2017-01-03 19:53:40 +00:00
|
|
|
light = lightleft + (x1 - savecoord.sx1) * lightstep;
|
2016-12-30 07:31:02 +00:00
|
|
|
if (fixedlightlev >= 0)
|
|
|
|
R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev));
|
|
|
|
else if (fixedcolormap != NULL)
|
|
|
|
R_SetColorMapLight(fixedcolormap, 0, 0);
|
|
|
|
else if (!foggy && (decal->RenderFlags & RF_FULLBRIGHT))
|
|
|
|
R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
|
|
|
|
else
|
|
|
|
calclighting = true;
|
|
|
|
|
|
|
|
// Draw it
|
2017-01-09 12:53:02 +00:00
|
|
|
bool sprflipvert;
|
2016-12-30 07:31:02 +00:00
|
|
|
if (decal->RenderFlags & RF_YFLIP)
|
|
|
|
{
|
|
|
|
sprflipvert = true;
|
|
|
|
yscale = -yscale;
|
|
|
|
dc_texturemid -= WallSpriteTile->GetHeight();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprflipvert = false;
|
|
|
|
}
|
|
|
|
|
2016-12-30 14:05:57 +00:00
|
|
|
maskedScaleY = float(1 / yscale);
|
2016-12-30 07:31:02 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
int x = x1;
|
|
|
|
|
|
|
|
bool visible = R_SetPatchStyle(decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor);
|
|
|
|
|
|
|
|
// R_SetPatchStyle can modify basecolormap.
|
|
|
|
if (rereadcolormap)
|
|
|
|
{
|
|
|
|
usecolormap = basecolormap;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
while (x < x2)
|
|
|
|
{
|
|
|
|
if (calclighting)
|
|
|
|
{ // calculate lighting
|
2017-01-03 17:57:48 +00:00
|
|
|
R_SetColorMapLight(usecolormap, light, wallshade);
|
2016-12-30 07:31:02 +00:00
|
|
|
}
|
2017-01-11 17:10:51 +00:00
|
|
|
DrawColumn(x, WallSpriteTile, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);
|
2017-01-03 17:57:48 +00:00
|
|
|
light += lightstep;
|
2016-12-30 07:31:02 +00:00
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this sprite is RF_CLIPFULL on a two-sided line, needrepeat will
|
|
|
|
// be set 1 if we need to draw on the lower wall. In all other cases,
|
|
|
|
// needrepeat will be 0, and the while will fail.
|
2017-01-04 14:39:47 +00:00
|
|
|
mceilingclip = RenderBSP::Instance()->floorclip;
|
2016-12-30 07:31:02 +00:00
|
|
|
mfloorclip = wallbottom;
|
|
|
|
R_FinishSetPatchStyle();
|
|
|
|
} while (needrepeat--);
|
|
|
|
|
|
|
|
colfunc = basecolfunc;
|
|
|
|
|
|
|
|
R_FinishSetPatchStyle();
|
|
|
|
done:
|
|
|
|
WallC = savecoord;
|
|
|
|
}
|
2017-01-03 17:57:48 +00:00
|
|
|
|
2017-01-11 17:10:51 +00:00
|
|
|
void RenderDecal::DrawColumn(int x, FTexture *WallSpriteTile, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip)
|
2017-01-03 17:57:48 +00:00
|
|
|
{
|
2017-01-09 12:53:02 +00:00
|
|
|
float iscale = swall[x] * maskedScaleY;
|
|
|
|
double spryscale = 1 / iscale;
|
|
|
|
double sprtopscreen;
|
2017-01-03 17:57:48 +00:00
|
|
|
if (sprflipvert)
|
|
|
|
sprtopscreen = CenterY + dc_texturemid * spryscale;
|
|
|
|
else
|
|
|
|
sprtopscreen = CenterY - dc_texturemid * spryscale;
|
|
|
|
|
2017-01-09 12:53:02 +00:00
|
|
|
R_DrawMaskedColumn(x, FLOAT2FIXED(iscale), WallSpriteTile, lwall[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
|
2017-01-03 17:57:48 +00:00
|
|
|
}
|
2016-12-30 07:31:02 +00:00
|
|
|
}
|