Remove yslope loopup table and StepColumn

This commit is contained in:
Magnus Norddahl 2017-02-06 15:15:09 +01:00
parent 942f90a759
commit 7e6c91d73c
6 changed files with 32 additions and 86 deletions

View file

@ -64,22 +64,20 @@ namespace swrenderer
double xstep, ystep, leftxfrac, leftyfrac, rightxfrac, rightyfrac; double xstep, ystep, leftxfrac, leftyfrac, rightxfrac, rightyfrac;
double x; double x;
xscale = xs_ToFixed(32 - drawerargs.TextureWidthBits(), _xscale);
yscale = xs_ToFixed(32 - drawerargs.TextureHeightBits(), _yscale);
if (planeang != 0) if (planeang != 0)
{ {
double cosine = cos(planeang), sine = sin(planeang); double cosine = cos(planeang), sine = sin(planeang);
pviewx = FLOAT2FIXED(pl->xform.xOffs + ViewPos.X * cosine - ViewPos.Y * sine); pviewx = pl->xform.xOffs + ViewPos.X * cosine - ViewPos.Y * sine;
pviewy = FLOAT2FIXED(pl->xform.yOffs - ViewPos.X * sine - ViewPos.Y * cosine); pviewy = pl->xform.yOffs - ViewPos.X * sine - ViewPos.Y * cosine;
} }
else else
{ {
pviewx = FLOAT2FIXED(pl->xform.xOffs + ViewPos.X); pviewx = pl->xform.xOffs + ViewPos.X;
pviewy = FLOAT2FIXED(pl->xform.yOffs - ViewPos.Y); pviewy = pl->xform.yOffs - ViewPos.Y;
} }
pviewx = FixedMul(xscale, pviewx); pviewx = _xscale * pviewx;
pviewy = FixedMul(yscale, pviewy); pviewy = _yscale * pviewy;
// left to right mapping // left to right mapping
planeang += (ViewAngle - 90).Radians(); planeang += (ViewAngle - 90).Radians();
@ -100,17 +98,19 @@ namespace swrenderer
planeang += M_PI / 2; planeang += M_PI / 2;
double cosine = cos(planeang), sine = -sin(planeang); double cosine = cos(planeang), sine = -sin(planeang);
x = pl->right - centerx - 0.5; x = pl->right - viewport->CenterX - 0.5;
rightxfrac = _xscale * (cosine + x * xstep); rightxfrac = _xscale * (cosine + x * xstep);
rightyfrac = _yscale * (sine + x * ystep); rightyfrac = _yscale * (sine + x * ystep);
x = pl->left - centerx - 0.5; x = pl->left - viewport->CenterX + 0.5;
leftxfrac = _xscale * (cosine + x * xstep); leftxfrac = _xscale * (cosine + x * xstep);
leftyfrac = _yscale * (sine + x * ystep); leftyfrac = _yscale * (sine + x * ystep);
basexfrac = rightxfrac; basexfrac = leftxfrac;
baseyfrac = rightyfrac; baseyfrac = leftyfrac;
xstepscale = (rightxfrac - leftxfrac) / (pl->right - pl->left); xstepscale = (rightxfrac - leftxfrac) / (pl->right - pl->left + 1);
ystepscale = (rightyfrac - leftyfrac) / (pl->right - pl->left); ystepscale = (rightyfrac - leftyfrac) / (pl->right - pl->left + 1);
minx = pl->left;
planeheight = fabs(pl->height.Zat0() - ViewPos.Z); planeheight = fabs(pl->height.Zat0() - ViewPos.Z);
@ -143,8 +143,6 @@ namespace swrenderer
void RenderFlatPlane::RenderLine(int y, int x1, int x2) void RenderFlatPlane::RenderLine(int y, int x1, int x2)
{ {
double distance;
#ifdef RANGECHECK #ifdef RANGECHECK
if (x2 < x1 || x1<0 || x2 >= viewwidth || (unsigned)y >= (unsigned)viewheight) if (x2 < x1 || x1<0 || x2 >= viewwidth || (unsigned)y >= (unsigned)viewheight)
{ {
@ -152,15 +150,17 @@ namespace swrenderer
} }
#endif #endif
// [RH] Notice that I dumped the caching scheme used by Doom. auto viewport = RenderViewport::Instance();
// It did not offer any appreciable speedup.
distance = planeheight * yslope[y]; double curxfrac = basexfrac + xstepscale * (x1 + 0.5 - minx);
double curyfrac = baseyfrac + ystepscale * (x1 + 0.5 - minx);
double distance = viewport->PlaneDepth(y, planeheight);
if (drawerargs.TextureWidthBits() != 0) if (drawerargs.TextureWidthBits() != 0)
{ {
drawerargs.SetTextureUStep(xs_ToFixed(32 - drawerargs.TextureWidthBits(), distance * xstepscale)); drawerargs.SetTextureUStep(xs_ToFixed(32 - drawerargs.TextureWidthBits(), distance * xstepscale));
drawerargs.SetTextureUPos(xs_ToFixed(32 - drawerargs.TextureWidthBits(), distance * basexfrac) + pviewx); drawerargs.SetTextureUPos(xs_ToFixed(32 - drawerargs.TextureWidthBits(), distance * curxfrac + pviewx));
} }
else else
{ {
@ -171,7 +171,7 @@ namespace swrenderer
if (drawerargs.TextureHeightBits() != 0) if (drawerargs.TextureHeightBits() != 0)
{ {
drawerargs.SetTextureVStep(xs_ToFixed(32 - drawerargs.TextureHeightBits(), distance * ystepscale)); drawerargs.SetTextureVStep(xs_ToFixed(32 - drawerargs.TextureHeightBits(), distance * ystepscale));
drawerargs.SetTextureVPos(xs_ToFixed(32 - drawerargs.TextureHeightBits(), distance * baseyfrac) + pviewy); drawerargs.SetTextureVPos(xs_ToFixed(32 - drawerargs.TextureHeightBits(), distance * curyfrac + pviewy));
} }
else else
{ {
@ -179,11 +179,9 @@ namespace swrenderer
drawerargs.SetTextureVPos(0); drawerargs.SetTextureVPos(0);
} }
auto viewport = RenderViewport::Instance();
if (viewport->RenderTarget->IsBgra()) if (viewport->RenderTarget->IsBgra())
{ {
double distance2 = planeheight * yslope[(y + 1 < viewheight) ? y + 1 : y - 1]; double distance2 = viewport->PlaneDepth(y + 1, planeheight);
double xmagnitude = fabs(ystepscale * (distance2 - distance) * viewport->FocalLengthX); double xmagnitude = fabs(ystepscale * (distance2 - distance) * viewport->FocalLengthX);
double ymagnitude = fabs(xstepscale * (distance2 - distance) * viewport->FocalLengthX); double ymagnitude = fabs(xstepscale * (distance2 - distance) * viewport->FocalLengthX);
double magnitude = MAX(ymagnitude, xmagnitude); double magnitude = MAX(ymagnitude, xmagnitude);
@ -268,56 +266,6 @@ namespace swrenderer
drawerargs.DrawSpan(Thread); drawerargs.DrawSpan(Thread);
} }
void RenderFlatPlane::StepColumn()
{
basexfrac -= xstepscale;
baseyfrac -= ystepscale;
}
void RenderFlatPlane::SetupSlope()
{
auto viewport = RenderViewport::Instance();
int i = 0;
int e = viewheight;
float focus = float(viewport->FocalLengthY);
float den;
float cy = float(viewport->CenterY);
if (i < centery)
{
den = cy - i - 0.5f;
if (e <= centery)
{
do {
yslope[i] = focus / den;
den -= 1;
} while (++i < e);
}
else
{
do {
yslope[i] = focus / den;
den -= 1;
} while (++i < centery);
den = i - cy + 0.5f;
do {
yslope[i] = focus / den;
den += 1;
} while (++i < e);
}
}
else
{
den = i - cy + 0.5f;
do {
yslope[i] = focus / den;
den += 1;
} while (++i < e);
}
}
float RenderFlatPlane::yslope[MAXHEIGHT];
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
RenderColoredPlane::RenderColoredPlane(RenderThread *thread) RenderColoredPlane::RenderColoredPlane(RenderThread *thread)

View file

@ -27,28 +27,23 @@ namespace swrenderer
RenderFlatPlane(RenderThread *thread); RenderFlatPlane(RenderThread *thread);
void Render(VisiblePlane *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked, FDynamicColormap *basecolormap, FTexture *texture); void Render(VisiblePlane *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked, FDynamicColormap *basecolormap, FTexture *texture);
static void SetupSlope();
RenderThread *Thread = nullptr; RenderThread *Thread = nullptr;
private: private:
void RenderLine(int y, int x1, int x2) override; void RenderLine(int y, int x1, int x2) override;
void StepColumn() override;
int minx;
double planeheight; double planeheight;
bool plane_shade; bool plane_shade;
int planeshade; int planeshade;
double GlobVis; double GlobVis;
FDynamicColormap *basecolormap; FDynamicColormap *basecolormap;
fixed_t pviewx, pviewy; double pviewx, pviewy;
fixed_t xscale, yscale;
double xstepscale, ystepscale; double xstepscale, ystepscale;
double basexfrac, baseyfrac; double basexfrac, baseyfrac;
VisiblePlaneLight *light_list; VisiblePlaneLight *light_list;
SpanDrawerArgs drawerargs; SpanDrawerArgs drawerargs;
static float yslope[MAXHEIGHT];
}; };
class RenderColoredPlane : PlaneRenderer class RenderColoredPlane : PlaneRenderer

View file

@ -85,8 +85,6 @@ namespace swrenderer
t2 = pl->top[x]; t2 = pl->top[x];
b2 = pl->bottom[x]; b2 = pl->bottom[x];
StepColumn();
} }
// Draw any spans that are still open // Draw any spans that are still open
while (t2 < b2) while (t2 < b2)

View file

@ -26,7 +26,6 @@ namespace swrenderer
void RenderLines(VisiblePlane *pl); void RenderLines(VisiblePlane *pl);
virtual void RenderLine(int y, int x1, int x2) = 0; virtual void RenderLine(int y, int x1, int x2) = 0;
virtual void StepColumn() { }
private: private:
short spanend[MAXHEIGHT]; short spanend[MAXHEIGHT];

View file

@ -130,8 +130,6 @@ namespace swrenderer
centery = xs_ToInt(CenterY); centery = xs_ToInt(CenterY);
globaluclip = -CenterY / InvZtoScale; globaluclip = -CenterY / InvZtoScale;
globaldclip = (viewheight - CenterY) / InvZtoScale; globaldclip = (viewheight - CenterY) / InvZtoScale;
RenderFlatPlane::SetupSlope();
} }
void RenderViewport::SetupBuffer() void RenderViewport::SetupBuffer()

View file

@ -59,6 +59,14 @@ namespace swrenderer
DVector2 PointWorldToView(const DVector2 &worldPos) const; DVector2 PointWorldToView(const DVector2 &worldPos) const;
DVector2 ScaleViewToScreen(const DVector2 &scale, double viewZ, bool pixelstretch = true) const; DVector2 ScaleViewToScreen(const DVector2 &scale, double viewZ, bool pixelstretch = true) const;
double PlaneDepth(int screenY, double planeHeight) const
{
if (screenY + 0.5 < CenterY)
return FocalLengthY / (CenterY - screenY - 0.5) * planeHeight;
else
return FocalLengthY / (screenY + 0.5 - CenterY) * planeHeight;
}
private: private:
void InitTextureMapping(); void InitTextureMapping();
void SetupBuffer(); void SetupBuffer();