- move more of the light calculation code to the drawerargs

This commit is contained in:
Magnus Norddahl 2018-12-18 00:37:50 +01:00
parent a73c065811
commit efb8e39aa9
26 changed files with 203 additions and 280 deletions

View file

@ -74,7 +74,8 @@ namespace swrenderer
fillshort(spanend + t2, b2 - t2, x);
}
drawerargs.SetLight(basecolormap, (float)light, lightlevel, foggy, thread->Viewport.get());
drawerargs.SetBaseColormap(basecolormap);
drawerargs.SetLight(light, lightlevel, foggy, thread->Viewport.get());
uint8_t *fake_dc_colormap = basecolormap->Maps + (GETPALOOKUP(light, wallshade) << COLORMAPSHIFT);
@ -101,7 +102,7 @@ namespace swrenderer
fillshort(spanend + t2, b2 - t2, x);
}
rcolormap = lcolormap;
drawerargs.SetLight(basecolormap, (float)light, wallshade);
drawerargs.SetLight(light, wallshade);
fake_dc_colormap = basecolormap->Maps + (GETPALOOKUP(light, wallshade) << COLORMAPSHIFT);
}
else

View file

@ -1164,24 +1164,10 @@ namespace swrenderer
offset = -offset;
}
WallDrawerArgs drawerargs;
drawerargs.SetStyle(false, false, OPAQUE);
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, cameraLight->FixedLightLevelShade());
else if (cameraLight->FixedColormap() != nullptr)
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
float rw_light = rw_lightleft + rw_lightstep * (x1 - WallC.sx1);
FLightNode *light_list = (mLineSegment && mLineSegment->sidedef) ? mLineSegment->sidedef->lighthead : nullptr;
if ((cameraLight->FixedLightLevel() >= 0) || (cameraLight->FixedColormap() != nullptr))
light_list = nullptr; // [SP] Don't draw dynlights if invul/lightamp active
RenderWallPart renderWallpart(Thread);
renderWallpart.Render(drawerargs, mFrontSector, mLineSegment, WallC, rw_pic, x1, x2, walltop.ScreenY, wallupper.ScreenY, mTopPart.TextureMid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mBackCeilingZ1, mBackCeilingZ2), false, lightlevel, offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
renderWallpart.Render(mFrontSector, mLineSegment, WallC, rw_pic, x1, x2, walltop.ScreenY, wallupper.ScreenY, mTopPart.TextureMid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mBackCeilingZ1, mBackCeilingZ2), false, false, OPAQUE, lightlevel, offset, rw_light, rw_lightstep, GetLightList(), foggy, basecolormap);
}
void SWRenderLine::RenderMiddleTexture(int x1, int x2)
@ -1211,24 +1197,10 @@ namespace swrenderer
offset = -offset;
}
WallDrawerArgs drawerargs;
drawerargs.SetStyle(false, false, OPAQUE);
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, cameraLight->FixedLightLevelShade());
else if (cameraLight->FixedColormap() != nullptr)
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
float rw_light = rw_lightleft + rw_lightstep * (x1 - WallC.sx1);
FLightNode *light_list = (mLineSegment && mLineSegment->sidedef) ? mLineSegment->sidedef->lighthead : nullptr;
if ((cameraLight->FixedLightLevel() >= 0) || (cameraLight->FixedColormap() != nullptr))
light_list = nullptr; // [SP] Don't draw dynlights if invul/lightamp active
RenderWallPart renderWallpart(Thread);
renderWallpart.Render(drawerargs, mFrontSector, mLineSegment, WallC, rw_pic, x1, x2, walltop.ScreenY, wallbottom.ScreenY, mMiddlePart.TextureMid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, lightlevel, offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
renderWallpart.Render(mFrontSector, mLineSegment, WallC, rw_pic, x1, x2, walltop.ScreenY, wallbottom.ScreenY, mMiddlePart.TextureMid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, false, OPAQUE, lightlevel, offset, rw_light, rw_lightstep, GetLightList(), foggy, basecolormap);
}
void SWRenderLine::RenderBottomTexture(int x1, int x2)
@ -1259,24 +1231,21 @@ namespace swrenderer
offset = -offset;
}
WallDrawerArgs drawerargs;
drawerargs.SetStyle(false, false, OPAQUE);
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, cameraLight->FixedLightLevelShade());
else if (cameraLight->FixedColormap() != nullptr)
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
float rw_light = rw_lightleft + rw_lightstep * (x1 - WallC.sx1);
FLightNode *light_list = (mLineSegment && mLineSegment->sidedef) ? mLineSegment->sidedef->lighthead : nullptr;
if ((cameraLight->FixedLightLevel() >= 0) || (cameraLight->FixedColormap() != nullptr))
light_list = nullptr; // [SP] Don't draw dynlights if invul/lightamp active
RenderWallPart renderWallpart(Thread);
renderWallpart.Render(drawerargs, mFrontSector, mLineSegment, WallC, rw_pic, x1, x2, walllower.ScreenY, wallbottom.ScreenY, mBottomPart.TextureMid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(mBackFloorZ1, mBackFloorZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, lightlevel, offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
renderWallpart.Render(mFrontSector, mLineSegment, WallC, rw_pic, x1, x2, walllower.ScreenY, wallbottom.ScreenY, mBottomPart.TextureMid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(mBackFloorZ1, mBackFloorZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, false, OPAQUE, lightlevel, offset, rw_light, rw_lightstep, GetLightList(), foggy, basecolormap);
}
FLightNode *SWRenderLine::GetLightList()
{
CameraLight *cameraLight = CameraLight::Instance();
if ((cameraLight->FixedLightLevel() >= 0) || cameraLight->FixedColormap())
return nullptr; // [SP] Don't draw dynlights if invul/lightamp active
else if (mLineSegment && mLineSegment->sidedef)
return mLineSegment->sidedef->lighthead;
else
return nullptr;
}
////////////////////////////////////////////////////////////////////////////

View file

@ -91,6 +91,8 @@ namespace swrenderer
void RenderMiddleTexture(int x1, int x2);
void RenderBottomTexture(int x1, int x2);
FLightNode *GetLightList();
bool IsFogBoundary(sector_t *front, sector_t *back) const;
bool SkyboxCompare(sector_t *frontsector, sector_t *backsector) const;

View file

@ -70,21 +70,6 @@ namespace swrenderer
curline = ds->curline;
m3DFloor = clip3DFloor;
float alpha = (float)MIN(curline->linedef->alpha, 1.);
bool additive = (curline->linedef->flags & ML_ADDTRANS) != 0;
WallDrawerArgs walldrawerargs;
walldrawerargs.SetStyle(true, additive, FLOAT2FIXED(alpha));
SpriteDrawerArgs columndrawerargs;
FDynamicColormap *patchstylecolormap = nullptr;
bool visible = columndrawerargs.SetStyle(viewport, LegacyRenderStyles[additive ? STYLE_Add : STYLE_Translucent], alpha, 0, 0, patchstylecolormap);
if (!visible && !ds->bFogBoundary && !ds->Has3DFloorWalls())
{
return;
}
if (Thread->MainThread)
NetUpdate();
@ -97,29 +82,38 @@ namespace swrenderer
FDynamicColormap *basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::walltop]); // [RH] Set basecolormap
bool foggy = ds->foggy;
int lightlevel = ds->lightlevel;
rw_lightstep = ds->lightstep;
rw_light = ds->light + (x1 - ds->x1) * rw_lightstep;
Clip3DFloors *clip3d = Thread->Clip3D.get();
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() < 0)
double clipTop = m3DFloor.clipTop ? m3DFloor.sclipTop : sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos);
for (int i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--)
{
double clipTop = m3DFloor.clipTop ? m3DFloor.sclipTop : sec->ceilingplane.ZatPoint(Thread->Viewport->viewpoint.Pos);
for (int i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--)
if (clipTop <= frontsector->e->XFloor.lightlist[i].plane.Zat0())
{
if (clipTop <= frontsector->e->XFloor.lightlist[i].plane.Zat0())
{
lightlist_t *lit = &frontsector->e->XFloor.lightlist[i];
basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]);
//bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag
lightlevel = curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr);
break;
}
lightlist_t *lit = &frontsector->e->XFloor.lightlist[i];
basecolormap = GetColorTable(lit->extra_colormap, frontsector->SpecialColors[sector_t::walltop]);
foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag
lightlevel = curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr);
break;
}
}
float alpha = (float)MIN(curline->linedef->alpha, 1.);
bool additive = (curline->linedef->flags & ML_ADDTRANS) != 0;
SpriteDrawerArgs columndrawerargs;
ColormapLight cmlight;
cmlight.SetColormap(Thread, MINZ, lightlevel, foggy, basecolormap, false, false, false, false, false);
bool visible = columndrawerargs.SetStyle(viewport, LegacyRenderStyles[additive ? STYLE_Add : STYLE_Translucent], alpha, 0, 0, cmlight);
if (!visible && !ds->bFogBoundary && !ds->Has3DFloorWalls())
{
return;
}
// [RH] Draw fog partition
bool renderwall = true;
bool notrelevant = false;
@ -140,7 +134,7 @@ namespace swrenderer
}
if (renderwall)
notrelevant = RenderWall(ds, x1, x2, walldrawerargs, columndrawerargs, visible, basecolormap, lightlevel);
notrelevant = RenderWall(ds, x1, x2, basecolormap, columndrawerargs, visible, lightlevel, foggy);
if (ds->Has3DFloorFrontSectorWalls() || ds->Has3DFloorBackSectorWalls())
{
@ -153,7 +147,7 @@ namespace swrenderer
}
}
bool RenderDrawSegment::RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int lightlevel)
bool RenderDrawSegment::RenderWall(DrawSegment *ds, int x1, int x2, FDynamicColormap *basecolormap, SpriteDrawerArgs &columndrawerargs, bool visible, int lightlevel, bool foggy)
{
auto renderstyle = DefaultRenderStyle();
auto viewport = Thread->Viewport.get();
@ -178,18 +172,6 @@ namespace swrenderer
double spryscale = ds->iscale + ds->iscalestep * (x1 - ds->x1);
float rw_scalestep = ds->iscalestep;
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
{
walldrawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, cameraLight->FixedLightLevelShade());
columndrawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, cameraLight->FixedLightLevelShade());
}
else if (cameraLight->FixedColormap() != nullptr)
{
walldrawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
columndrawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
}
// find positioning
double texheight = tex->GetScaledHeightDouble();
double texheightscale = fabs(curline->sidedef->GetTextureYScale(side_t::mid));
@ -328,16 +310,17 @@ namespace swrenderer
mfloorclip = walllower.ScreenY;
mceilingclip = wallupper.ScreenY;
auto cameraLight = CameraLight::Instance();
bool needslight = (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0);
// draw the columns one at a time
if (visible)
{
Thread->PrepareTexture(tex, renderstyle);
for (int x = x1; x < x2; ++x)
{
if (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0)
{
columndrawerargs.SetLight(basecolormap, rw_light, lightlevel, ds->foggy, Thread->Viewport.get());
}
if (needslight)
columndrawerargs.SetLight(rw_light, lightlevel, foggy, Thread->Viewport.get());
fixed_t iscale = xs_Fix<16>::ToFix(MaskedSWall[x] * MaskedScaleY);
double sprtopscreen;
@ -412,8 +395,11 @@ namespace swrenderer
double top, bot;
GetMaskedWallTopBottom(ds, top, bot);
float alpha = FLOAT2FIXED((float)MIN(curline->linedef->alpha, 1.));
bool additive = (curline->linedef->flags & ML_ADDTRANS) != 0;
RenderWallPart renderWallpart(Thread);
renderWallpart.Render(walldrawerargs, frontsector, curline, WallC, rw_pic, x1, x2, mceilingclip, mfloorclip, texturemid, MaskedSWall, maskedtexturecol, ds->yscale, top, bot, true, lightlevel, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
renderWallpart.Render(frontsector, curline, WallC, rw_pic, x1, x2, mceilingclip, mfloorclip, texturemid, MaskedSWall, maskedtexturecol, ds->yscale, top, bot, true, additive, alpha, lightlevel, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
}
return false;
@ -430,9 +416,6 @@ namespace swrenderer
if (Alpha <= 0)
return;
WallDrawerArgs drawerargs;
drawerargs.SetStyle(true, (rover->flags & FF_ADDITIVETRANS) != 0, Alpha);
rw_lightstep = ds->lightstep;
rw_light = ds->light + (x1 - ds->x1) * rw_lightstep;
@ -486,12 +469,6 @@ namespace swrenderer
texturemid += rowoffset;
}
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, cameraLight->FixedLightLevelShade());
else if (cameraLight->FixedColormap() != nullptr)
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
WallC.sz1 = ds->sz1;
WallC.sz2 = ds->sz2;
WallC.sx1 = ds->sx1;
@ -524,7 +501,7 @@ namespace swrenderer
GetMaskedWallTopBottom(ds, top, bot);
RenderWallPart renderWallpart(Thread);
renderWallpart.Render(drawerargs, frontsector, curline, WallC, rw_pic, x1, x2, wallupper.ScreenY, walllower.ScreenY, texturemid, MaskedSWall, walltexcoords.UPos, yscale, top, bot, true, lightlevel, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
renderWallpart.Render(frontsector, curline, WallC, rw_pic, x1, x2, wallupper.ScreenY, walllower.ScreenY, texturemid, MaskedSWall, walltexcoords.UPos, yscale, top, bot, true, (rover->flags & FF_ADDITIVETRANS) != 0, Alpha, lightlevel, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
RenderDecal::RenderDecals(Thread, curline->sidedef, ds, lightlevel, rw_light, rw_lightstep, curline, WallC, ds->foggy, basecolormap, wallupper.ScreenY, walllower.ScreenY, true);
}

View file

@ -37,7 +37,7 @@ namespace swrenderer
RenderThread *Thread = nullptr;
private:
bool RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int lightlevel);
bool RenderWall(DrawSegment *ds, int x1, int x2, FDynamicColormap *basecolormap, SpriteDrawerArgs &columndrawerargs, bool visible, int lightlevel, bool foggy);
void ClipMidtex(int x1, int x2);
void RenderFakeWall(DrawSegment *ds, int x1, int x2, F3DFloor *rover, int lightlevel, FDynamicColormap *basecolormap, double clipTop, double clipBottom);
void RenderFakeWallRange(DrawSegment *ds, int x1, int x2);

View file

@ -346,16 +346,19 @@ namespace swrenderer
drawerargs.SetTextureFracBits(Thread->Viewport->RenderTarget->IsBgra() ? FRACBITS : fracbits);
// Textures that aren't masked can use the faster opaque drawer
if (!rw_pic->GetTexture()->isMasked() && mask && alpha >= OPAQUE && !additive)
{
drawerargs.SetStyle(true, false, OPAQUE, basecolormap);
}
else
{
drawerargs.SetStyle(mask, additive, alpha, basecolormap);
}
CameraLight *cameraLight = CameraLight::Instance();
bool fixed = (cameraLight->FixedColormap() != NULL || cameraLight->FixedLightLevel() >= 0);
if (cameraLight->FixedLightLevel() >= 0)
drawerargs.SetLight(cameraLight->FixedColormap(), 0, cameraLight->FixedLightLevelShade());
else if (cameraLight->FixedColormap())
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
else
drawerargs.SetLight(basecolormap, 0, 0);
float dx = WallC.tright.X - WallC.tleft.X;
float dy = WallC.tright.Y - WallC.tleft.Y;
float length = sqrt(dx * dx + dy * dy);
@ -374,7 +377,7 @@ namespace swrenderer
continue;
if (!fixed)
drawerargs.SetLight(basecolormap, curlight, lightlevel, foggy, Thread->Viewport.get());
drawerargs.SetLight(curlight, lightlevel, foggy, Thread->Viewport.get());
if (x + 1 < x2) xmagnitude = fabs(FIXED2DBL(lwal[x + 1]) - FIXED2DBL(lwal[x]));
@ -430,12 +433,6 @@ namespace swrenderer
void RenderWallPart::ProcessWall(const short *uwal, const short *dwal, double texturemid, float *swal, fixed_t *lwal)
{
// Textures that aren't masked can use the faster ProcessNormalWall.
if (!rw_pic->GetTexture()->isMasked() && drawerargs.IsMaskedDrawer())
{
drawerargs.SetStyle(true, false, OPAQUE);
}
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedColormap() != NULL || cameraLight->FixedLightLevel() >= 0 || !(frontsector->e && frontsector->e->XFloor.lightlist.Size()))
{
@ -519,9 +516,8 @@ namespace swrenderer
}
}
void RenderWallPart::Render(const WallDrawerArgs &drawerargs, sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FSoftwareTexture *pic, int x1, int x2, const short *walltop, const short *wallbottom, double texturemid, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, int lightlevel, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy, FDynamicColormap *basecolormap)
void RenderWallPart::Render(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FSoftwareTexture *pic, int x1, int x2, const short *walltop, const short *wallbottom, double texturemid, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, bool additive, fixed_t alpha, int lightlevel, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy, FDynamicColormap *basecolormap)
{
this->drawerargs = drawerargs;
this->x1 = x1;
this->x2 = x2;
this->frontsector = frontsector;
@ -537,6 +533,8 @@ namespace swrenderer
this->light_list = light_list;
this->rw_pic = pic;
this->mask = mask;
this->additive = additive;
this->alpha = alpha;
Thread->PrepareTexture(pic, DefaultRenderStyle()); // Get correct render style? Shaded won't get here.

View file

@ -46,7 +46,6 @@ namespace swrenderer
RenderWallPart(RenderThread *thread);
void Render(
const WallDrawerArgs &drawerargs,
sector_t *frontsector,
seg_t *curline,
const FWallCoords &WallC,
@ -62,6 +61,8 @@ namespace swrenderer
double top,
double bottom,
bool mask,
bool additive,
fixed_t alpha,
int lightlevel,
fixed_t xoffset,
float light,
@ -96,6 +97,8 @@ namespace swrenderer
FDynamicColormap *basecolormap = nullptr;
FLightNode *light_list = nullptr;
bool mask = false;
bool additive = false;
fixed_t alpha = 0;
WallDrawerArgs drawerargs;
};

View file

@ -134,29 +134,14 @@ namespace swrenderer
planeheight = fabs(pl->height.Zat0() - Thread->Viewport->viewpoint.Pos.Z);
basecolormap = colormap;
// [RH] set foggy flag
foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE));
foggy = (level.fadeto || colormap->Fade || (level.flags & LEVEL_HASFADETABLE));
lightlevel = pl->lightlevel;
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
{
drawerargs.SetLight(basecolormap, 0, cameraLight->FixedLightLevelShade());
plane_shade = false;
}
else if (cameraLight->FixedColormap())
{
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
plane_shade = false;
}
else
{
plane_shade = true;
lightlevel = pl->lightlevel;
}
plane_shade = cameraLight->FixedLightLevel() < 0 && !cameraLight->FixedColormap();
drawerargs.SetStyle(masked, additive, alpha);
drawerargs.SetStyle(masked, additive, alpha, colormap);
light_list = pl->lights;
@ -200,7 +185,7 @@ namespace swrenderer
if (plane_shade)
{
// Determine lighting based on the span's distance from the viewer.
drawerargs.SetLight(basecolormap, (float)Thread->Light->FlatPlaneVis(y, planeheight, foggy, viewport), lightlevel, foggy, viewport);
drawerargs.SetLight((float)Thread->Light->FlatPlaneVis(y, planeheight, foggy, viewport), lightlevel, foggy, viewport);
}
if (r_dynlights)

View file

@ -46,7 +46,6 @@ namespace swrenderer
bool plane_shade;
int lightlevel;
bool foggy;
FDynamicColormap *basecolormap;
double pviewx, pviewy;
double xstepscale, ystepscale;
double basexfrac, baseyfrac;

View file

@ -227,15 +227,7 @@ namespace swrenderer
backpos = int(fmod(backdpos, sky2cyl * 65536.0));
}
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedColormap())
{
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
}
else
{
drawerargs.SetLight(&NormalLight, 0, 0);
}
drawerargs.SetStyle();
Thread->PrepareTexture(frontskytex, DefaultRenderStyle());
Thread->PrepareTexture(backskytex, DefaultRenderStyle());

View file

@ -174,31 +174,19 @@ namespace swrenderer
// [RH] set foggy flag
basecolormap = colormap;
foggy = level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE);;
foggy = level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE);
planelightfloat = (Thread->Light->SlopePlaneGlobVis(foggy) * lxscale * lyscale) / (fabs(pl->height.ZatPoint(Thread->Viewport->viewpoint.Pos) - Thread->Viewport->viewpoint.Pos.Z)) / 65536.f;
if (pl->height.fC() > 0)
planelightfloat = -planelightfloat;
drawerargs.SetStyle(false, false, OPAQUE, basecolormap);
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
{
drawerargs.SetLight(basecolormap, 0, cameraLight->FixedLightLevelShade());
plane_shade = false;
}
else if (cameraLight->FixedColormap())
{
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
plane_shade = false;
}
else
{
drawerargs.SetLight(basecolormap, 0, 0);
plane_shade = true;
lightlevel = pl->lightlevel;
}
plane_shade = cameraLight->FixedLightLevel() < 0 && !cameraLight->FixedColormap();
lightlevel = pl->lightlevel;
// Hack in support for 1 x Z and Z x 1 texture sizes
if (drawerargs.TextureHeightBits() == 0)

View file

@ -74,8 +74,6 @@ namespace swrenderer
double zpos;
int needrepeat = 0;
sector_t *back;
bool calclighting;
bool rereadcolormap;
FDynamicColormap *usecolormap;
float light = 0;
const short *mfloorclip;
@ -259,15 +257,12 @@ namespace swrenderer
}
// 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;
}
light = lightleft + (x1 - savecoord.sx1) * lightstep;
@ -292,24 +287,12 @@ namespace swrenderer
{
int x = x1;
ColormapLight cmlight;
cmlight.SetColormap(thread, MINZ, lightlevel, foggy, usecolormap, decal->RenderFlags & RF_FULLBRIGHT, false, false, false, false);
SpriteDrawerArgs drawerargs;
if (cameraLight->FixedLightLevel() >= 0)
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, cameraLight->FixedLightLevelShade());
else if (cameraLight->FixedColormap() != NULL)
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
else if (!foggy && (decal->RenderFlags & RF_FULLBRIGHT))
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
else
calclighting = true;
bool visible = drawerargs.SetStyle(thread->Viewport.get(), decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, basecolormap);
// R_SetPatchStyle can modify basecolormap.
if (rereadcolormap)
{
usecolormap = basecolormap;
}
bool visible = drawerargs.SetStyle(thread->Viewport.get(), decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, cmlight);
bool calclighting = cameraLight->FixedLightLevel() < 0 && !cameraLight->FixedColormap();
if (visible)
{
@ -318,7 +301,7 @@ namespace swrenderer
{
if (calclighting)
{ // calculate lighting
drawerargs.SetLight(usecolormap, light, lightlevel, foggy, thread->Viewport.get());
drawerargs.SetLight(light, lightlevel, foggy, thread->Viewport.get());
}
DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, decal->RenderStyle);
light += lightstep;

View file

@ -492,11 +492,7 @@ namespace swrenderer
}
SpriteDrawerArgs drawerargs;
drawerargs.SetLight(Light.BaseColormap, 0, Light.ColormapNum << FRACBITS);
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(Light.BaseColormap);
bool visible = drawerargs.SetStyle(thread->Viewport.get(), RenderStyle, Alpha, Translation, FillColor, basecolormap, Light.ColormapNum << FRACBITS);
bool visible = drawerargs.SetStyle(thread->Viewport.get(), RenderStyle, Alpha, Translation, FillColor, Light);
if (!visible)
return;

View file

@ -323,12 +323,8 @@ namespace swrenderer
}
SpriteDrawerArgs drawerargs;
drawerargs.SetLight(vis->Light.BaseColormap, 0, vis->Light.ColormapNum << FRACBITS);
drawerargs.SetDynamicLight(dynlightcolor);
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(vis->Light.BaseColormap);
bool visible = drawerargs.SetStyle(thread->Viewport.get(), vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, basecolormap, vis->Light.ColormapNum << FRACBITS);
bool visible = drawerargs.SetStyle(thread->Viewport.get(), vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, vis->Light);
if (visible)
{

View file

@ -162,7 +162,6 @@ namespace swrenderer
vis->Alpha = float(thing->Alpha);
vis->fakefloor = fakefloor;
vis->fakeceiling = fakeceiling;
vis->Light.ColormapNum = 0;
vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP;
//vis->bSplitSprite = false;
@ -192,9 +191,7 @@ namespace swrenderer
// Fake a voxel drawing to find its extents..
SpriteDrawerArgs drawerargs;
drawerargs.SetLight(vis->Light.BaseColormap, 0, vis->Light.ColormapNum << FRACBITS);
basecolormap = (FDynamicColormap*)vis->Light.BaseColormap;
bool visible = drawerargs.SetStyle(thread->Viewport.get(), vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, basecolormap);
bool visible = drawerargs.SetStyle(thread->Viewport.get(), vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, vis->Light);
if (!visible)
return;
int flags = vis->bInMirror ? (DVF_MIRRORED | DVF_FIND_X1X2) : DVF_FIND_X1X2;
@ -211,10 +208,7 @@ namespace swrenderer
auto viewport = thread->Viewport.get();
SpriteDrawerArgs drawerargs;
drawerargs.SetLight(spr->Light.BaseColormap, 0, spr->Light.ColormapNum << FRACBITS);
FDynamicColormap *basecolormap = (FDynamicColormap*)spr->Light.BaseColormap;
bool visible = drawerargs.SetStyle(viewport, spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap);
bool visible = drawerargs.SetStyle(viewport, spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, spr->Light);
if (!visible)
return;
@ -908,12 +902,8 @@ namespace swrenderer
auto sprite = this;
auto viewport = RenderViewport::Instance();
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(sprite->Light.BaseColormap);
SpriteDrawerArgs drawerargs;
drawerargs.SetLight(sprite->Light.BaseColormap, 0, sprite->Light.ColormapNum << FRACBITS);
bool visible = drawerargs.SetStyle(sprite->RenderStyle, sprite->Alpha, sprite->Translation, sprite->FillColor, basecolormap);
bool visible = drawerargs.SetStyle(sprite->RenderStyle, sprite->Alpha, sprite->Translation, sprite->FillColor, sprite->Light);
if (!visible)
return;

View file

@ -176,32 +176,27 @@ namespace swrenderer
walltexcoords.UPos[i] = right - walltexcoords.UPos[i];
}
}
// Prepare lighting
bool calclighting = false;
FSWColormap *usecolormap = spr->Light.BaseColormap;
bool rereadcolormap = true;
// Decals that are added to the scene must fade to black.
if (spr->RenderStyle == LegacyRenderStyles[STYLE_Add] && usecolormap->Fade != 0)
ColormapLight cmlight;
if (spr->RenderStyle == LegacyRenderStyles[STYLE_Add] && cmlight.BaseColormap->Fade != 0)
{
usecolormap = GetSpecialLights(usecolormap->Color, 0, usecolormap->Desaturate);
rereadcolormap = false;
cmlight.BaseColormap = GetSpecialLights(cmlight.BaseColormap->Color, 0, cmlight.BaseColormap->Desaturate);
}
SpriteDrawerArgs drawerargs;
bool visible = drawerargs.SetStyle(thread->Viewport.get(), spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, cmlight);
if (!visible)
return;
float lightleft = float(thread->Light->WallVis(spr->wallc.sz1, foggy));
float lightstep = float((thread->Light->WallVis(spr->wallc.sz2, foggy) - lightleft) / (spr->wallc.sx2 - spr->wallc.sx1));
float light = lightleft + (x1 - spr->wallc.sx1) * lightstep;
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
drawerargs.SetLight(usecolormap, 0, cameraLight->FixedLightLevelShade());
else if (cameraLight->FixedColormap() != NULL)
drawerargs.SetLight(cameraLight->FixedColormap(), 0, 0);
else if (!spr->foggy && (spr->renderflags & RF_FULLBRIGHT))
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
else
calclighting = true;
bool calclighting = cameraLight->FixedLightLevel() < 0 && !cameraLight->FixedColormap();
// Draw it
auto WallSpriteTile = spr->pic;
@ -220,36 +215,19 @@ namespace swrenderer
int x = x1;
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(spr->Light.BaseColormap);
RenderTranslucentPass *translucentPass = thread->TranslucentPass.get();
bool visible = drawerargs.SetStyle(thread->Viewport.get(), spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap);
// R_SetPatchStyle can modify basecolormap.
if (rereadcolormap)
thread->PrepareTexture(WallSpriteTile, spr->RenderStyle);
while (x < x2)
{
usecolormap = spr->Light.BaseColormap;
}
if (!visible)
{
return;
}
else
{
RenderTranslucentPass *translucentPass = thread->TranslucentPass.get();
thread->PrepareTexture(WallSpriteTile, spr->RenderStyle);
while (x < x2)
if (calclighting)
{
if (calclighting)
{ // calculate lighting
drawerargs.SetLight(usecolormap, light, spr->sector->lightlevel, spr->foggy, thread->Viewport.get());
}
if (!translucentPass->ClipSpriteColumnWithPortals(x, spr))
DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, spr->RenderStyle);
light += lightstep;
x++;
drawerargs.SetLight(light, spr->sector->lightlevel, spr->foggy, thread->Viewport.get());
}
if (!translucentPass->ClipSpriteColumnWithPortals(x, spr))
DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, spr->RenderStyle);
light += lightstep;
x++;
}
}

View file

@ -24,15 +24,26 @@
namespace swrenderer
{
void DrawerArgs::SetLight(FSWColormap *base_colormap, float light, int lightlevel, bool foggy, RenderViewport *viewport)
{
SetLight(base_colormap, light, LightVisibility::LightLevelToShade(lightlevel, foggy, viewport));
}
void DrawerArgs::SetLight(FSWColormap *base_colormap, float light, int shade)
void DrawerArgs::SetBaseColormap(FSWColormap *base_colormap)
{
mBaseColormap = base_colormap;
assert(mBaseColormap->Maps != nullptr);
}
void DrawerArgs::SetLight(float light, int lightlevel, bool foggy, RenderViewport *viewport)
{
mLight = light;
mShade = LightVisibility::LightLevelToShade(lightlevel, foggy, viewport);
}
void DrawerArgs::SetLight(const ColormapLight &light)
{
SetBaseColormap(light.BaseColormap);
SetLight(0.0f, light.ColormapNum << FRACBITS);
}
void DrawerArgs::SetLight(float light, int shade)
{
mLight = light;
mShade = shade;
}

View file

@ -16,6 +16,7 @@ struct FLightNode;
namespace swrenderer
{
class ColormapLight;
class SWPixelFormatDrawers;
class DrawerArgs;
struct ShadeConstants;
@ -30,8 +31,9 @@ namespace swrenderer
class DrawerArgs
{
public:
void SetLight(FSWColormap *base_colormap, float light, int shade);
void SetLight(FSWColormap *base_colormap, float light, int lightlevel, bool foggy, RenderViewport *viewport);
void SetBaseColormap(FSWColormap *base_colormap);
void SetLight(float light, int shade);
void SetLight(float light, int lightlevel, bool foggy, RenderViewport *viewport);
void SetTranslationMap(lighttable_t *translation);
uint8_t *Colormap(RenderViewport *viewport) const;
@ -40,6 +42,9 @@ namespace swrenderer
ShadeConstants ColormapConstants() const;
fixed_t Light() const { return LIGHTSCALE(mLight, mShade); }
protected:
void SetLight(const ColormapLight &light);
private:
FSWColormap *mBaseColormap = nullptr;
float mLight = 0.0f;

View file

@ -40,6 +40,21 @@ namespace swrenderer
thread->Drawers(dc_viewport)->DrawDoubleSkyColumn(*this);
}
void SkyDrawerArgs::SetStyle()
{
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedColormap())
{
SetBaseColormap(cameraLight->FixedColormap());
SetLight(0, 0);
}
else
{
SetBaseColormap(&NormalLight);
SetLight(0, 0);
}
}
void SkyDrawerArgs::SetDest(RenderViewport *viewport, int x, int y)
{
dc_dest = viewport->GetDest(x, y);

View file

@ -13,6 +13,7 @@ namespace swrenderer
class SkyDrawerArgs : public DrawerArgs
{
public:
void SetStyle();
void SetDest(RenderViewport *viewport, int x, int y);
void SetCount(int count) { dc_count = count; }
void SetFrontTexture(RenderThread *thread, FSoftwareTexture *texture, fixed_t column);

View file

@ -51,7 +51,7 @@ namespace swrenderer
ds_source_mipmapped = tex->Mipmapped() && tex->GetPhysicalWidth() > 1 && tex->GetPhysicalHeight() > 1;
}
void SpanDrawerArgs::SetStyle(bool masked, bool additive, fixed_t alpha)
void SpanDrawerArgs::SetStyle(bool masked, bool additive, fixed_t alpha, FDynamicColormap *basecolormap)
{
if (masked)
{
@ -105,6 +105,22 @@ namespace swrenderer
spanfunc = &SWPixelFormatDrawers::DrawSpan;
}
}
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
{
SetBaseColormap((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap);
SetLight(0, cameraLight->FixedLightLevelShade());
}
else if (cameraLight->FixedColormap())
{
SetBaseColormap(cameraLight->FixedColormap());
SetLight(0, 0);
}
else
{
SetBaseColormap(basecolormap);
}
}
void SpanDrawerArgs::DrawDepthSpan(RenderThread *thread, float idepth1, float idepth2)

View file

@ -15,7 +15,7 @@ namespace swrenderer
public:
SpanDrawerArgs();
void SetStyle(bool masked, bool additive, fixed_t alpha);
void SetStyle(bool masked, bool additive, fixed_t alpha, FDynamicColormap *basecolormap);
void SetDestY(RenderViewport *viewport, int y) { ds_viewport = viewport; ds_y = y; }
void SetDestX1(int x) { ds_x1 = x; }
void SetDestX2(int x) { ds_x2 = x; }

View file

@ -382,8 +382,14 @@ namespace swrenderer
}
}
bool SpriteDrawerArgs::SetStyle(RenderViewport *viewport, FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade)
bool SpriteDrawerArgs::SetStyle(RenderViewport *viewport, FRenderStyle style, fixed_t alpha, int translation, uint32_t color, const ColormapLight &light)
{
if (light.BaseColormap)
SetLight(light);
FDynamicColormap *basecolormap = light.BaseColormap ? static_cast<FDynamicColormap*>(light.BaseColormap) : nullptr;
fixed_t shadedlightshade = light.ColormapNum << FRACBITS;
fixed_t fglevel, bglevel;
drawer_needs_pal_input = false;
@ -450,11 +456,13 @@ namespace swrenderer
{
fixed_t shade = shadedlightshade;
if (shade == 0) shade = cameraLight->FixedLightLevelShade();
SetLight(basecolormap, 0, shade);
SetBaseColormap(basecolormap);
SetLight(0, shade);
}
else
{
SetLight(basecolormap, 0, shadedlightshade);
SetBaseColormap(basecolormap);
SetLight(0, shadedlightshade);
}
return true;
}
@ -482,15 +490,16 @@ namespace swrenderer
// dc_srccolor is used by the R_Fill* routines. It is premultiplied
// with the alpha.
dc_srccolor = ((((r*x) >> 4) << 20) | ((g*x) >> 4) | ((((b)*x) >> 4) << 10)) & 0x3feffbff;
SetLight(&identitycolormap, 0, 0);
SetBaseColormap(&identitycolormap);
SetLight(0, 0);
}
return SpriteDrawerArgs::SetBlendFunc(style.BlendOp, fglevel, bglevel, style.Flags);
}
bool SpriteDrawerArgs::SetStyle(RenderViewport *viewport, FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade)
bool SpriteDrawerArgs::SetStyle(RenderViewport *viewport, FRenderStyle style, float alpha, int translation, uint32_t color, const ColormapLight &light)
{
return SetStyle(viewport, style, FLOAT2FIXED(alpha), translation, color, basecolormap, shadedlightshade);
return SetStyle(viewport, style, FLOAT2FIXED(alpha), translation, color, light);
}
void SpriteDrawerArgs::FillColumn(RenderThread *thread)

View file

@ -26,8 +26,8 @@ namespace swrenderer
public:
SpriteDrawerArgs();
bool SetStyle(RenderViewport *viewport, FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0);
bool SetStyle(RenderViewport *viewport, FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0);
bool SetStyle(RenderViewport *viewport, FRenderStyle style, fixed_t alpha, int translation, uint32_t color, const ColormapLight &light);
bool SetStyle(RenderViewport *viewport, FRenderStyle style, float alpha, int translation, uint32_t color, const ColormapLight &light);
void SetDest(RenderViewport *viewport, int x, int y);
void SetCount(int count) { dc_count = count; }
void SetSolidColor(int color) { dc_color = color; dc_color_bgra = GPalette.BaseColors[color]; }

View file

@ -42,7 +42,7 @@ namespace swrenderer
(thread->Drawers(dc_viewport)->*wallfunc)(*this);
}
void WallDrawerArgs::SetStyle(bool masked, bool additive, fixed_t alpha)
void WallDrawerArgs::SetStyle(bool masked, bool additive, fixed_t alpha, FDynamicColormap *basecolormap)
{
if (alpha < OPAQUE || additive)
{
@ -71,10 +71,21 @@ namespace swrenderer
{
wallfunc = &SWPixelFormatDrawers::DrawWallColumn;
}
}
bool WallDrawerArgs::IsMaskedDrawer() const
{
return wallfunc == &SWPixelFormatDrawers::DrawWallMaskedColumn;
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedLightLevel() >= 0)
{
SetBaseColormap((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap);
SetLight(0.0f, cameraLight->FixedLightLevelShade());
}
else if (cameraLight->FixedColormap() != nullptr)
{
SetBaseColormap(cameraLight->FixedColormap());
SetLight(0.0f, 0);
}
else
{
SetBaseColormap(basecolormap);
}
}
}

View file

@ -14,7 +14,7 @@ namespace swrenderer
class WallDrawerArgs : public DrawerArgs
{
public:
void SetStyle(bool masked, bool additive, fixed_t alpha);
void SetStyle(bool masked, bool additive, fixed_t alpha, FDynamicColormap *basecolormap);
void SetDest(RenderViewport *viewport, int x, int y);
void SetCount(int count) { dc_count = count; }
void SetTexture(const uint8_t *pixels, const uint8_t *pixels2, int height)
@ -28,8 +28,6 @@ namespace swrenderer
void SetTextureVPos(fixed_t pos) { dc_texturefrac = pos; }
void SetTextureVStep(fixed_t step) { dc_iscale = step; }
bool IsMaskedDrawer() const;
void DrawDepthColumn(RenderThread *thread, float idepth);
void DrawColumn(RenderThread *thread);