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-31 10:42:49 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include "templates.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "stats.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "g_level.h"
|
2017-03-06 21:14:54 +00:00
|
|
|
#include "g_levellocals.h"
|
2017-01-11 19:42:39 +00:00
|
|
|
#include "swrenderer/scene/r_opaque_pass.h"
|
2016-12-31 10:42:49 +00:00
|
|
|
#include "r_slopeplane.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/scene/r_3dfloors.h"
|
2016-12-31 10:42:49 +00:00
|
|
|
#include "v_palette.h"
|
|
|
|
#include "r_data/colormaps.h"
|
|
|
|
#include "swrenderer/drawers/r_draw_rgba.h"
|
|
|
|
#include "gl/dynlights/gl_dynlight.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/segments/r_clipsegment.h"
|
|
|
|
#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-02-02 14:10:06 +00:00
|
|
|
#include "swrenderer/viewport/r_viewport.h"
|
2017-01-11 22:27:35 +00:00
|
|
|
#include "swrenderer/plane/r_visibleplane.h"
|
2017-02-03 23:25:37 +00:00
|
|
|
#include "swrenderer/r_memory.h"
|
|
|
|
#include "swrenderer/r_renderthread.h"
|
2016-12-31 10:42:49 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4244)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-02-03 23:25:37 +00:00
|
|
|
RenderSlopePlane::RenderSlopePlane(RenderThread *thread)
|
|
|
|
{
|
|
|
|
Thread = thread;
|
|
|
|
}
|
|
|
|
|
2017-01-28 15:36:39 +00:00
|
|
|
void RenderSlopePlane::Render(VisiblePlane *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked, FDynamicColormap *colormap, FTexture *texture)
|
2016-12-31 10:42:49 +00:00
|
|
|
{
|
|
|
|
static const float ifloatpow2[16] =
|
|
|
|
{
|
|
|
|
// ifloatpow2[i] = 1 / (1 << i)
|
|
|
|
64.f, 32.f, 16.f, 8.f, 4.f, 2.f, 1.f, 0.5f,
|
|
|
|
0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f,
|
|
|
|
0.00390625f, 0.001953125f
|
|
|
|
/*, 0.0009765625f, 0.00048828125f, 0.000244140625f,
|
|
|
|
1.220703125e-4f, 6.103515625e-5, 3.0517578125e-5*/
|
|
|
|
};
|
|
|
|
double lxscale, lyscale;
|
|
|
|
double xscale, yscale;
|
|
|
|
FVector3 p, m, n;
|
|
|
|
double ang, planeang, cosine, sine;
|
|
|
|
double zeroheight;
|
|
|
|
|
|
|
|
if (alpha <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-02-01 15:02:21 +00:00
|
|
|
|
|
|
|
auto viewport = RenderViewport::Instance();
|
2016-12-31 10:42:49 +00:00
|
|
|
|
2017-01-30 11:46:17 +00:00
|
|
|
drawerargs.SetSolidColor(3);
|
|
|
|
drawerargs.SetTexture(texture);
|
2017-01-28 15:36:39 +00:00
|
|
|
|
2017-01-30 11:46:17 +00:00
|
|
|
lxscale = _xscale * ifloatpow2[drawerargs.TextureWidthBits()];
|
|
|
|
lyscale = _yscale * ifloatpow2[drawerargs.TextureHeightBits()];
|
2016-12-31 10:42:49 +00:00
|
|
|
xscale = 64.f / lxscale;
|
|
|
|
yscale = 64.f / lyscale;
|
2017-03-11 22:28:07 +00:00
|
|
|
zeroheight = pl->height.ZatPoint(r_viewpoint.Pos);
|
2016-12-31 10:42:49 +00:00
|
|
|
|
2017-01-30 11:46:17 +00:00
|
|
|
pviewx = xs_ToFixed(32 - drawerargs.TextureWidthBits(), pl->xform.xOffs * pl->xform.xScale);
|
|
|
|
pviewy = xs_ToFixed(32 - drawerargs.TextureHeightBits(), pl->xform.yOffs * pl->xform.yScale);
|
2016-12-31 10:42:49 +00:00
|
|
|
planeang = (pl->xform.Angle + pl->xform.baseAngle).Radians();
|
|
|
|
|
|
|
|
// p is the texture origin in view space
|
|
|
|
// Don't add in the offsets at this stage, because doing so can result in
|
|
|
|
// errors if the flat is rotated.
|
2017-03-11 22:28:07 +00:00
|
|
|
ang = M_PI * 3 / 2 - r_viewpoint.Angles.Yaw.Radians();
|
2016-12-31 10:42:49 +00:00
|
|
|
cosine = cos(ang), sine = sin(ang);
|
2017-03-11 22:28:07 +00:00
|
|
|
p[0] = r_viewpoint.Pos.X * cosine - r_viewpoint.Pos.Y * sine;
|
|
|
|
p[2] = r_viewpoint.Pos.X * sine + r_viewpoint.Pos.Y * cosine;
|
|
|
|
p[1] = pl->height.ZatPoint(0.0, 0.0) - r_viewpoint.Pos.Z;
|
2016-12-31 10:42:49 +00:00
|
|
|
|
|
|
|
// m is the v direction vector in view space
|
|
|
|
ang = ang - M_PI / 2 - planeang;
|
|
|
|
cosine = cos(ang), sine = sin(ang);
|
|
|
|
m[0] = yscale * cosine;
|
|
|
|
m[2] = yscale * sine;
|
|
|
|
// m[1] = pl->height.ZatPointF (0, iyscale) - pl->height.ZatPointF (0,0));
|
|
|
|
// VectorScale2 (m, 64.f/VectorLength(m));
|
|
|
|
|
|
|
|
// n is the u direction vector in view space
|
|
|
|
#if 0
|
|
|
|
//let's use the sin/cosine we already know instead of computing new ones
|
|
|
|
ang += M_PI / 2
|
|
|
|
n[0] = -xscale * cos(ang);
|
|
|
|
n[2] = -xscale * sin(ang);
|
|
|
|
#else
|
|
|
|
n[0] = xscale * sine;
|
|
|
|
n[2] = -xscale * cosine;
|
|
|
|
#endif
|
|
|
|
// n[1] = pl->height.ZatPointF (ixscale, 0) - pl->height.ZatPointF (0,0));
|
|
|
|
// VectorScale2 (n, 64.f/VectorLength(n));
|
|
|
|
|
|
|
|
// This code keeps the texture coordinates constant across the x,y plane no matter
|
|
|
|
// how much you slope the surface. Use the commented-out code above instead to keep
|
|
|
|
// the textures a constant size across the surface's plane instead.
|
|
|
|
cosine = cos(planeang), sine = sin(planeang);
|
2017-03-11 22:28:07 +00:00
|
|
|
m[1] = pl->height.ZatPoint(r_viewpoint.Pos.X + yscale * sine, r_viewpoint.Pos.Y + yscale * cosine) - zeroheight;
|
|
|
|
n[1] = -(pl->height.ZatPoint(r_viewpoint.Pos.X - xscale * cosine, r_viewpoint.Pos.Y + xscale * sine) - zeroheight);
|
2016-12-31 10:42:49 +00:00
|
|
|
|
|
|
|
plane_su = p ^ m;
|
|
|
|
plane_sv = p ^ n;
|
|
|
|
plane_sz = m ^ n;
|
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
plane_su.Z *= viewport->FocalLengthX;
|
|
|
|
plane_sv.Z *= viewport->FocalLengthX;
|
|
|
|
plane_sz.Z *= viewport->FocalLengthX;
|
2016-12-31 10:42:49 +00:00
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
plane_su.Y *= viewport->IYaspectMul;
|
|
|
|
plane_sv.Y *= viewport->IYaspectMul;
|
|
|
|
plane_sz.Y *= viewport->IYaspectMul;
|
2016-12-31 10:42:49 +00:00
|
|
|
|
|
|
|
// Premultiply the texture vectors with the scale factors
|
|
|
|
plane_su *= 4294967296.f;
|
|
|
|
plane_sv *= 4294967296.f;
|
|
|
|
|
2017-02-03 23:25:37 +00:00
|
|
|
RenderPortal *renderportal = Thread->Portal.get();
|
2017-01-05 03:55:26 +00:00
|
|
|
if (renderportal->MirrorFlags & RF_XFLIP)
|
2016-12-31 10:42:49 +00:00
|
|
|
{
|
|
|
|
plane_su[0] = -plane_su[0];
|
|
|
|
plane_sv[0] = -plane_sv[0];
|
|
|
|
plane_sz[0] = -plane_sz[0];
|
|
|
|
}
|
|
|
|
|
2017-03-06 21:14:54 +00:00
|
|
|
// [RH] set foggy flag
|
|
|
|
basecolormap = colormap;
|
|
|
|
bool foggy = level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE);;
|
|
|
|
|
2017-03-11 22:28:07 +00:00
|
|
|
planelightfloat = (LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * lxscale * lyscale) / (fabs(pl->height.ZatPoint(r_viewpoint.Pos) - r_viewpoint.Pos.Z)) / 65536.f;
|
2016-12-31 10:42:49 +00:00
|
|
|
|
|
|
|
if (pl->height.fC() > 0)
|
|
|
|
planelightfloat = -planelightfloat;
|
|
|
|
|
2017-01-12 20:29:19 +00:00
|
|
|
|
2017-01-26 09:22:54 +00:00
|
|
|
CameraLight *cameraLight = CameraLight::Instance();
|
2017-02-03 08:00:46 +00:00
|
|
|
if (cameraLight->FixedLightLevel() >= 0)
|
2016-12-31 10:42:49 +00:00
|
|
|
{
|
2017-03-06 22:27:02 +00:00
|
|
|
drawerargs.SetLight(basecolormap, 0, cameraLight->FixedLightLevelShade());
|
2016-12-31 10:42:49 +00:00
|
|
|
plane_shade = false;
|
|
|
|
}
|
2017-02-03 08:00:46 +00:00
|
|
|
else if (cameraLight->FixedColormap())
|
2016-12-31 10:42:49 +00:00
|
|
|
{
|
2017-02-03 08:00:46 +00:00
|
|
|
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
|
2016-12-31 10:42:49 +00:00
|
|
|
plane_shade = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-02 10:16:18 +00:00
|
|
|
drawerargs.SetLight(basecolormap, 0, 0);
|
2016-12-31 10:42:49 +00:00
|
|
|
plane_shade = true;
|
2017-03-06 22:27:02 +00:00
|
|
|
planeshade = LightVisibility::LightLevelToShade(pl->lightlevel, foggy);
|
2016-12-31 10:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hack in support for 1 x Z and Z x 1 texture sizes
|
2017-01-30 11:46:17 +00:00
|
|
|
if (drawerargs.TextureHeightBits() == 0)
|
2016-12-31 10:42:49 +00:00
|
|
|
{
|
|
|
|
plane_sv[2] = plane_sv[1] = plane_sv[0] = 0;
|
|
|
|
}
|
2017-01-30 11:46:17 +00:00
|
|
|
if (drawerargs.TextureWidthBits() == 0)
|
2016-12-31 10:42:49 +00:00
|
|
|
{
|
|
|
|
plane_su[2] = plane_su[1] = plane_su[0] = 0;
|
|
|
|
}
|
|
|
|
|
2017-01-11 20:59:26 +00:00
|
|
|
RenderLines(pl);
|
2016-12-31 10:42:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 20:59:26 +00:00
|
|
|
void RenderSlopePlane::RenderLine(int y, int x1, int x2)
|
2016-12-31 10:42:49 +00:00
|
|
|
{
|
2017-02-04 11:38:05 +00:00
|
|
|
drawerargs.DrawTiltedSpan(Thread, y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap);
|
2016-12-31 10:42:49 +00:00
|
|
|
}
|
|
|
|
}
|