2017-04-17 10:27:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-01-03 06:17:54 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// Copyright 1993-1996 id Software
|
|
|
|
// Copyright 1999-2016 Randy Heit
|
|
|
|
// Copyright 2016 Magnus Norddahl
|
2017-01-03 06:17:54 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// 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 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2017-01-03 06:17:54 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
2017-01-03 06:17:54 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-04-17 10:27:19 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2017-01-03 06:17:54 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-12-30 07:11:06 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "w_wad.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/things/r_wallsprite.h"
|
2016-12-30 07:11:06 +00:00
|
|
|
#include "c_console.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "sc_man.h"
|
|
|
|
#include "s_sound.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "colormatcher.h"
|
|
|
|
#include "d_netinf.h"
|
|
|
|
#include "p_effect.h"
|
2017-01-11 19:42:39 +00:00
|
|
|
#include "swrenderer/scene/r_opaque_pass.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/scene/r_3dfloors.h"
|
2017-01-11 19:42:39 +00:00
|
|
|
#include "swrenderer/scene/r_translucent_pass.h"
|
2016-12-30 07:11:06 +00:00
|
|
|
#include "swrenderer/drawers/r_draw_rgba.h"
|
|
|
|
#include "swrenderer/drawers/r_draw_pal.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "r_data/r_translate.h"
|
|
|
|
#include "r_data/colormaps.h"
|
|
|
|
#include "r_data/voxels.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "p_maputl.h"
|
|
|
|
#include "r_voxel.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/segments/r_drawsegment.h"
|
|
|
|
#include "swrenderer/scene/r_portal.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
#include "swrenderer/scene/r_scene.h"
|
|
|
|
#include "swrenderer/scene/r_light.h"
|
2017-01-01 09:28:35 +00:00
|
|
|
#include "swrenderer/line/r_wallsetup.h"
|
|
|
|
#include "swrenderer/line/r_walldraw.h"
|
2017-02-02 14:10:06 +00:00
|
|
|
#include "swrenderer/viewport/r_viewport.h"
|
2016-12-30 07:11:06 +00:00
|
|
|
#include "swrenderer/r_memory.h"
|
2017-02-03 23:25:37 +00:00
|
|
|
#include "swrenderer/r_renderthread.h"
|
2017-01-28 22:37:57 +00:00
|
|
|
|
|
|
|
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor);
|
2017-01-11 14:41:42 +00:00
|
|
|
|
2016-12-30 07:11:06 +00:00
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-05-23 07:37:38 +00:00
|
|
|
void RenderWallSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *pic, const DVector2 &scale, int renderflags, int spriteshade, bool foggy, FDynamicColormap *basecolormap)
|
2016-12-30 07:11:06 +00:00
|
|
|
{
|
|
|
|
FWallCoords wallc;
|
|
|
|
double x1, x2;
|
|
|
|
DVector2 left, right;
|
|
|
|
double gzb, gzt, tz;
|
|
|
|
DAngle ang = thing->Angles.Yaw + 90;
|
|
|
|
double angcos = ang.Cos();
|
|
|
|
double angsin = ang.Sin();
|
|
|
|
|
|
|
|
// Determine left and right edges of sprite. The sprite's angle is its normal,
|
|
|
|
// so the edges are 90 degrees each side of it.
|
|
|
|
x2 = pic->GetScaledWidth();
|
|
|
|
x1 = pic->GetScaledLeftOffset();
|
|
|
|
|
|
|
|
x1 *= scale.X;
|
|
|
|
x2 *= scale.X;
|
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
left.X = pos.X - x1 * angcos - thread->Viewport->viewpoint.Pos.X;
|
|
|
|
left.Y = pos.Y - x1 * angsin - thread->Viewport->viewpoint.Pos.Y;
|
2016-12-30 07:11:06 +00:00
|
|
|
right.X = left.X + x2 * angcos;
|
2017-05-23 07:37:38 +00:00
|
|
|
right.Y = left.Y + x2 * angsin;
|
2016-12-30 07:11:06 +00:00
|
|
|
|
|
|
|
// Is it off-screen?
|
2017-02-03 23:25:37 +00:00
|
|
|
if (wallc.Init(thread, left, right, TOO_CLOSE_Z))
|
2016-12-30 07:11:06 +00:00
|
|
|
return;
|
2017-01-05 03:55:26 +00:00
|
|
|
|
2017-02-03 23:25:37 +00:00
|
|
|
RenderPortal *renderportal = thread->Portal.get();
|
2016-12-30 07:11:06 +00:00
|
|
|
|
2017-01-05 03:55:26 +00:00
|
|
|
if (wallc.sx1 >= renderportal->WindowRight || wallc.sx2 <= renderportal->WindowLeft)
|
2016-12-30 07:11:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Sprite sorting should probably treat these as walls, not sprites,
|
|
|
|
// but right now, I just want to get them drawing.
|
2017-03-12 17:54:39 +00:00
|
|
|
tz = (pos.X - thread->Viewport->viewpoint.Pos.X) * thread->Viewport->viewpoint.TanCos + (pos.Y - thread->Viewport->viewpoint.Pos.Y) * thread->Viewport->viewpoint.TanSin;
|
2016-12-30 07:11:06 +00:00
|
|
|
|
|
|
|
int scaled_to = pic->GetScaledTopOffset();
|
|
|
|
int scaled_bo = scaled_to - pic->GetScaledHeight();
|
|
|
|
gzt = pos.Z + scale.Y * scaled_to;
|
|
|
|
gzb = pos.Z + scale.Y * scaled_bo;
|
|
|
|
|
2017-02-04 01:50:52 +00:00
|
|
|
RenderWallSprite *vis = thread->FrameMemory->NewObject<RenderWallSprite>();
|
2017-01-05 03:55:26 +00:00
|
|
|
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
|
|
|
|
vis->x1 = wallc.sx1 < renderportal->WindowLeft ? renderportal->WindowLeft : wallc.sx1;
|
|
|
|
vis->x2 = wallc.sx2 >= renderportal->WindowRight ? renderportal->WindowRight : wallc.sx2;
|
2016-12-30 07:11:06 +00:00
|
|
|
vis->yscale = (float)scale.Y;
|
|
|
|
vis->idepth = float(1 / tz);
|
|
|
|
vis->depth = (float)tz;
|
|
|
|
vis->sector = thing->Sector;
|
|
|
|
vis->heightsec = NULL;
|
|
|
|
vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z };
|
|
|
|
vis->gzb = (float)gzb;
|
|
|
|
vis->gzt = (float)gzt;
|
2017-03-12 17:54:39 +00:00
|
|
|
vis->deltax = float(pos.X - thread->Viewport->viewpoint.Pos.X);
|
|
|
|
vis->deltay = float(pos.Y - thread->Viewport->viewpoint.Pos.Y);
|
2016-12-30 07:11:06 +00:00
|
|
|
vis->renderflags = renderflags;
|
|
|
|
if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D
|
2017-01-16 15:23:02 +00:00
|
|
|
vis->RenderStyle = thing->RenderStyle;
|
2016-12-30 07:11:06 +00:00
|
|
|
vis->FillColor = thing->fillcolor;
|
|
|
|
vis->Translation = thing->Translation;
|
2017-01-04 18:03:33 +00:00
|
|
|
vis->FakeFlatStat = WaterFakeSide::Center;
|
2017-01-16 15:23:02 +00:00
|
|
|
vis->Alpha = float(thing->Alpha);
|
2016-12-30 07:11:06 +00:00
|
|
|
vis->fakefloor = NULL;
|
|
|
|
vis->fakeceiling = NULL;
|
2017-01-16 04:26:22 +00:00
|
|
|
//vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP;
|
2016-12-30 07:11:06 +00:00
|
|
|
vis->pic = pic;
|
|
|
|
vis->wallc = wallc;
|
2017-01-12 19:13:21 +00:00
|
|
|
vis->foggy = foggy;
|
2017-01-16 02:46:05 +00:00
|
|
|
|
2017-03-12 19:40:00 +00:00
|
|
|
vis->Light.SetColormap(thread->Light->SpriteGlobVis(foggy) / MAX(tz, MINZ), spriteshade, basecolormap, false, false, false);
|
2017-01-17 00:30:12 +00:00
|
|
|
|
2017-02-03 23:25:37 +00:00
|
|
|
thread->SpriteList->Push(vis);
|
2016-12-30 07:11:06 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 23:25:37 +00:00
|
|
|
void RenderWallSprite::Render(RenderThread *thread, short *mfloorclip, short *mceilingclip, int, int)
|
2016-12-30 07:11:06 +00:00
|
|
|
{
|
2017-01-16 04:26:22 +00:00
|
|
|
auto spr = this;
|
|
|
|
|
2016-12-30 07:11:06 +00:00
|
|
|
int x1, x2;
|
|
|
|
double iyscale;
|
2017-01-09 12:53:02 +00:00
|
|
|
bool sprflipvert;
|
2016-12-30 07:11:06 +00:00
|
|
|
|
|
|
|
x1 = MAX<int>(spr->x1, spr->wallc.sx1);
|
|
|
|
x2 = MIN<int>(spr->x2, spr->wallc.sx2);
|
|
|
|
if (x1 >= x2)
|
|
|
|
return;
|
2017-01-24 06:06:47 +00:00
|
|
|
|
2017-01-03 17:57:48 +00:00
|
|
|
FWallTmapVals WallT;
|
2017-02-03 23:25:37 +00:00
|
|
|
WallT.InitFromWallCoords(thread, &spr->wallc);
|
2017-01-24 06:06:47 +00:00
|
|
|
|
|
|
|
ProjectedWallTexcoords walltexcoords;
|
2017-03-12 17:54:39 +00:00
|
|
|
walltexcoords.Project(thread->Viewport.get(), spr->pic->GetWidth() << FRACBITS, x1, x2, WallT);
|
2017-01-24 06:06:47 +00:00
|
|
|
|
2016-12-30 07:11:06 +00:00
|
|
|
iyscale = 1 / spr->yscale;
|
2017-03-12 17:54:39 +00:00
|
|
|
double texturemid = (spr->gzt - thread->Viewport->viewpoint.Pos.Z) * iyscale;
|
2016-12-30 07:11:06 +00:00
|
|
|
if (spr->renderflags & RF_XFLIP)
|
|
|
|
{
|
|
|
|
int right = (spr->pic->GetWidth() << FRACBITS) - 1;
|
|
|
|
|
|
|
|
for (int i = x1; i < x2; i++)
|
|
|
|
{
|
2017-01-24 05:50:17 +00:00
|
|
|
walltexcoords.UPos[i] = right - walltexcoords.UPos[i];
|
2016-12-30 07:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Prepare lighting
|
|
|
|
bool calclighting = false;
|
2017-01-24 03:15:54 +00:00
|
|
|
FSWColormap *usecolormap = spr->Light.BaseColormap;
|
2016-12-30 07:11:06 +00:00
|
|
|
bool rereadcolormap = true;
|
|
|
|
|
|
|
|
// Decals that are added to the scene must fade to black.
|
2017-01-16 15:23:02 +00:00
|
|
|
if (spr->RenderStyle == LegacyRenderStyles[STYLE_Add] && usecolormap->Fade != 0)
|
2016-12-30 07:11:06 +00:00
|
|
|
{
|
|
|
|
usecolormap = GetSpecialLights(usecolormap->Color, 0, usecolormap->Desaturate);
|
|
|
|
rereadcolormap = false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:27:58 +00:00
|
|
|
SpriteDrawerArgs drawerargs;
|
2017-01-28 15:36:39 +00:00
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
int shade = LightVisibility::LightLevelToShade(spr->sector->lightlevel + LightVisibility::ActualExtraLight(spr->foggy, thread->Viewport.get()), spr->foggy);
|
2017-03-12 19:40:00 +00:00
|
|
|
double GlobVis = thread->Light->WallGlobVis(foggy);
|
2017-01-03 17:57:48 +00:00
|
|
|
float lightleft = float(GlobVis / spr->wallc.sz1);
|
|
|
|
float lightstep = float((GlobVis / spr->wallc.sz2 - lightleft) / (spr->wallc.sx2 - spr->wallc.sx1));
|
|
|
|
float light = lightleft + (x1 - spr->wallc.sx1) * lightstep;
|
2017-01-26 09:22:54 +00:00
|
|
|
CameraLight *cameraLight = CameraLight::Instance();
|
2017-02-03 08:00:46 +00:00
|
|
|
if (cameraLight->FixedLightLevel() >= 0)
|
2017-03-06 22:27:02 +00:00
|
|
|
drawerargs.SetLight(usecolormap, 0, cameraLight->FixedLightLevelShade());
|
2017-02-03 08:00:46 +00:00
|
|
|
else if (cameraLight->FixedColormap() != NULL)
|
|
|
|
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
|
2017-01-12 19:13:21 +00:00
|
|
|
else if (!spr->foggy && (spr->renderflags & RF_FULLBRIGHT))
|
2017-02-02 10:16:18 +00:00
|
|
|
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
|
2016-12-30 07:11:06 +00:00
|
|
|
else
|
|
|
|
calclighting = true;
|
|
|
|
|
|
|
|
// Draw it
|
2017-01-09 13:51:34 +00:00
|
|
|
FTexture *WallSpriteTile = spr->pic;
|
2016-12-30 07:11:06 +00:00
|
|
|
if (spr->renderflags & RF_YFLIP)
|
|
|
|
{
|
|
|
|
sprflipvert = true;
|
|
|
|
iyscale = -iyscale;
|
2017-01-12 21:52:17 +00:00
|
|
|
texturemid -= spr->pic->GetHeight();
|
2016-12-30 07:11:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprflipvert = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
float maskedScaleY = (float)iyscale;
|
|
|
|
|
|
|
|
int x = x1;
|
|
|
|
|
2017-01-24 03:15:54 +00:00
|
|
|
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(spr->Light.BaseColormap);
|
2017-01-12 20:29:19 +00:00
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
bool visible = drawerargs.SetStyle(thread->Viewport.get(), spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap);
|
2016-12-30 07:11:06 +00:00
|
|
|
|
|
|
|
// R_SetPatchStyle can modify basecolormap.
|
|
|
|
if (rereadcolormap)
|
|
|
|
{
|
2017-01-24 03:15:54 +00:00
|
|
|
usecolormap = spr->Light.BaseColormap;
|
2016-12-30 07:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!visible)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-03 23:25:37 +00:00
|
|
|
RenderTranslucentPass *translucentPass = thread->TranslucentPass.get();
|
2017-01-26 07:36:28 +00:00
|
|
|
|
2017-03-15 01:59:33 +00:00
|
|
|
thread->PrepareTexture(WallSpriteTile);
|
2016-12-30 07:11:06 +00:00
|
|
|
while (x < x2)
|
|
|
|
{
|
|
|
|
if (calclighting)
|
|
|
|
{ // calculate lighting
|
2017-02-02 10:16:18 +00:00
|
|
|
drawerargs.SetLight(usecolormap, light, shade);
|
2016-12-30 07:11:06 +00:00
|
|
|
}
|
2017-01-26 07:36:28 +00:00
|
|
|
if (!translucentPass->ClipSpriteColumnWithPortals(x, spr))
|
2017-02-04 11:38:05 +00:00
|
|
|
DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);
|
2017-01-03 17:57:48 +00:00
|
|
|
light += lightstep;
|
2016-12-30 07:11:06 +00:00
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-04 11:38:05 +00:00
|
|
|
void RenderWallSprite::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip)
|
2016-12-30 07:11:06 +00:00
|
|
|
{
|
2017-03-12 17:54:39 +00:00
|
|
|
auto viewport = thread->Viewport.get();
|
2017-02-01 15:02:21 +00:00
|
|
|
|
2017-01-24 05:50:17 +00:00
|
|
|
float iscale = walltexcoords.VStep[x] * maskedScaleY;
|
2017-01-09 12:53:02 +00:00
|
|
|
double spryscale = 1 / iscale;
|
|
|
|
double sprtopscreen;
|
2016-12-30 07:11:06 +00:00
|
|
|
if (sprflipvert)
|
2017-02-01 15:02:21 +00:00
|
|
|
sprtopscreen = viewport->CenterY + texturemid * spryscale;
|
2016-12-30 07:11:06 +00:00
|
|
|
else
|
2017-02-01 15:02:21 +00:00
|
|
|
sprtopscreen = viewport->CenterY - texturemid * spryscale;
|
2016-12-30 07:11:06 +00:00
|
|
|
|
2017-02-04 11:38:05 +00:00
|
|
|
drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
|
2016-12-30 07:11:06 +00:00
|
|
|
}
|
|
|
|
}
|