- Simplify ProjectedWallLight light step setup and positioning

This commit is contained in:
Magnus Norddahl 2018-12-27 22:52:33 +01:00
parent ed094d0b2f
commit c0a4ba5e82
7 changed files with 48 additions and 39 deletions

View File

@ -490,8 +490,8 @@ namespace swrenderer
draw_segment->iscalestep = 0;
}
}
draw_segment->light = mLight.lightleft + mLight.lightstep * (start - WallC.sx1);
draw_segment->lightstep = mLight.lightstep;
draw_segment->light = mLight.GetLightPos(start);
draw_segment->lightstep = mLight.GetLightStep();
// Masked mMiddlePart.Textures should get the light level from the sector they reference,
// not from the current subsector, which is what the current lightlevel value
@ -552,7 +552,7 @@ namespace swrenderer
// [ZZ] Only if not an active mirror
if (!markportal)
{
RenderDecal::RenderDecals(Thread, mLineSegment->sidedef, draw_segment, mLineSegment, WallC, mLight, walltop.ScreenY, wallbottom.ScreenY, false);
RenderDecal::RenderDecals(Thread, mLineSegment->sidedef, draw_segment, mLineSegment, mLight, walltop.ScreenY, wallbottom.ScreenY, false);
}
if (markportal)
@ -786,18 +786,7 @@ namespace swrenderer
walltexcoords.Project(Thread->Viewport.get(), sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2, WallT);
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0)
{
mLight.lightlevel = mLineSegment->sidedef->GetLightLevel(mLight.foggy, mFrontSector->lightlevel);
mLight.lightleft = float(Thread->Light->WallVis(WallC.sz1, mLight.foggy));
mLight.lightstep = float((Thread->Light->WallVis(WallC.sz2, mLight.foggy) - mLight.lightleft) / (WallC.sx2 - WallC.sx1));
}
else
{
mLight.lightleft = 1;
mLight.lightstep = 0;
}
mLight.SetLightLeft(Thread, mLineSegment, mFrontSector, WallC);
}
}
@ -1164,8 +1153,6 @@ namespace swrenderer
offset = -offset;
}
mLight.light = mLight.lightleft + mLight.lightstep * (x1 - WallC.sx1);
RenderWallPart renderWallpart(Thread);
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, offset, mLight, GetLightList());
}
@ -1197,8 +1184,6 @@ namespace swrenderer
offset = -offset;
}
mLight.light = mLight.lightleft + mLight.lightstep * (x1 - WallC.sx1);
RenderWallPart renderWallpart(Thread);
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, offset, mLight, GetLightList());
}
@ -1231,8 +1216,6 @@ namespace swrenderer
offset = -offset;
}
mLight.light = mLight.lightleft + mLight.lightstep * (x1 - WallC.sx1);
RenderWallPart renderWallpart(Thread);
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, offset, mLight, GetLightList());
}

View File

@ -83,8 +83,7 @@ namespace swrenderer
mLight.basecolormap = GetColorTable(sec->Colormap, sec->SpecialColors[sector_t::walltop]); // [RH] Set basecolormap
mLight.foggy = ds->foggy;
mLight.lightlevel = ds->lightlevel;
mLight.lightstep = ds->lightstep;
mLight.light = ds->light + (x1 - ds->x1) * mLight.lightstep;
mLight.SetLightLeft(ds->light, ds->lightstep, ds->x1);
Clip3DFloors *clip3d = Thread->Clip3D.get();
@ -122,7 +121,7 @@ namespace swrenderer
const short *mceilingclip = ds->sprtopclip - ds->x1;
RenderFogBoundary renderfog;
renderfog.Render(Thread, x1, x2, mceilingclip, mfloorclip, mLight.lightlevel, ds->foggy, mLight.light, mLight.lightstep, mLight.basecolormap);
renderfog.Render(Thread, x1, x2, mceilingclip, mfloorclip, mLight.lightlevel, ds->foggy, mLight.GetLightPos(x1), mLight.GetLightStep(), mLight.basecolormap);
if (ds->maskedtexturecol == nullptr)
renderwall = false;
@ -316,10 +315,11 @@ namespace swrenderer
if (visible)
{
Thread->PrepareTexture(tex, renderstyle);
float lightpos = mLight.GetLightPos(x1);
for (int x = x1; x < x2; ++x)
{
if (needslight)
columndrawerargs.SetLight(mLight.light, mLight.lightlevel, mLight.foggy, Thread->Viewport.get());
columndrawerargs.SetLight(lightpos, mLight.lightlevel, mLight.foggy, Thread->Viewport.get());
fixed_t iscale = xs_Fix<16>::ToFix(MaskedSWall[x] * MaskedScaleY);
double sprtopscreen;
@ -330,7 +330,7 @@ namespace swrenderer
columndrawerargs.DrawMaskedColumn(Thread, x, iscale, tex, maskedtexturecol[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, renderstyle);
mLight.light += mLight.lightstep;
lightpos += mLight.GetLightStep();
spryscale += rw_scalestep;
}
}
@ -415,8 +415,7 @@ namespace swrenderer
if (Alpha <= 0)
return;
mLight.lightstep = ds->lightstep;
mLight.light = ds->light + (x1 - ds->x1) * mLight.lightstep;
mLight.SetLightLeft(ds->light, ds->lightstep, ds->x1);
const short *mfloorclip = ds->sprbottomclip - ds->x1;
const short *mceilingclip = ds->sprtopclip - ds->x1;
@ -502,7 +501,7 @@ namespace swrenderer
RenderWallPart renderWallpart(Thread);
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, rw_offset, mLight, nullptr);
RenderDecal::RenderDecals(Thread, curline->sidedef, ds, curline, WallC, mLight, wallupper.ScreenY, walllower.ScreenY, true);
RenderDecal::RenderDecals(Thread, curline->sidedef, ds, curline, mLight, wallupper.ScreenY, walllower.ScreenY, true);
}
// kg3D - walls of fake floors

View File

@ -368,8 +368,8 @@ namespace swrenderer
double xmagnitude = 1.0;
float curlight = mLight.light;
for (int x = x1; x < x2; x++, curlight += mLight.lightstep)
float curlight = mLight.GetLightPos(x1);
for (int x = x1; x < x2; x++, curlight += mLight.GetLightStep())
{
int y1 = uwal[x];
int y2 = dwal[x];

View File

@ -241,4 +241,24 @@ namespace swrenderer
}
}
}
/////////////////////////////////////////////////////////////////////////
void ProjectedWallLight::SetLightLeft(RenderThread *thread, seg_t *lineseg, sector_t *frontsector, const FWallCoords &wallc)
{
x1 = wallc.sx1;
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0)
{
lightlevel = lineseg->sidedef->GetLightLevel(foggy, frontsector->lightlevel);
lightleft = float(thread->Light->WallVis(wallc.sz1, foggy));
lightstep = float((thread->Light->WallVis(wallc.sz2, foggy) - lightleft) / (wallc.sx2 - wallc.sx1));
}
else
{
lightleft = 1;
lightstep = 0;
}
}
}

View File

@ -64,8 +64,15 @@ namespace swrenderer
bool foggy;
FDynamicColormap *basecolormap;
float GetLightPos(int x) const { return lightleft + lightstep * (x - x1); }
float GetLightStep() const { return lightstep; }
void SetLightLeft(float left, float step, int startx) { lightleft = left; lightstep = step; x1 = startx; }
void SetLightLeft(RenderThread *thread, seg_t *lineseg, sector_t *frontsector, const FWallCoords &wallc);
private:
int x1;
float lightleft;
float lightstep;
float light;
};
}

View File

@ -57,15 +57,15 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor);
namespace swrenderer
{
void RenderDecal::RenderDecals(RenderThread *thread, side_t *sidedef, DrawSegment *draw_segment, seg_t *curline, const FWallCoords &wallC, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass)
void RenderDecal::RenderDecals(RenderThread *thread, side_t *sidedef, DrawSegment *draw_segment, seg_t *curline, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass)
{
for (DBaseDecal *decal = sidedef->AttachedDecals; decal != NULL; decal = decal->WallNext)
{
Render(thread, sidedef, decal, draw_segment, curline, wallC, light, walltop, wallbottom, drawsegPass);
Render(thread, sidedef, decal, draw_segment, curline, light, walltop, wallbottom, drawsegPass);
}
}
void RenderDecal::Render(RenderThread *thread, side_t *wall, DBaseDecal *decal, DrawSegment *clipper, seg_t *curline, const FWallCoords &savecoord, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass)
void RenderDecal::Render(RenderThread *thread, side_t *wall, DBaseDecal *decal, DrawSegment *clipper, seg_t *curline, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass)
{
DVector2 decal_left, decal_right, decal_pos;
int x1, x2;
@ -264,7 +264,7 @@ namespace swrenderer
usecolormap = GetSpecialLights(usecolormap->Color, 0, usecolormap->Desaturate);
}
float lightpos = light.lightleft + (x1 - savecoord.sx1) * light.lightstep;
float lightpos = light.GetLightPos(x1);
cameraLight = CameraLight::Instance();
@ -303,7 +303,7 @@ namespace swrenderer
drawerargs.SetLight(lightpos, light.lightlevel, light.foggy, thread->Viewport.get());
}
DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, decal->RenderStyle);
lightpos += light.lightstep;
lightpos += light.GetLightStep();
x++;
}
}

View File

@ -12,10 +12,10 @@ namespace swrenderer
class RenderDecal
{
public:
static void RenderDecals(RenderThread *thread, side_t *wall, DrawSegment *draw_segment, seg_t *curline, const FWallCoords &wallC, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass);
static void RenderDecals(RenderThread *thread, side_t *wall, DrawSegment *draw_segment, seg_t *curline, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass);
private:
static void Render(RenderThread *thread, side_t *wall, DBaseDecal *first, DrawSegment *clipper, seg_t *curline, const FWallCoords &wallC, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass);
static void Render(RenderThread *thread, side_t *wall, DBaseDecal *first, DrawSegment *clipper, seg_t *curline, const ProjectedWallLight &light, const short *walltop, const short *wallbottom, bool drawsegPass);
static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FSoftwareTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style);
};
}