From 82855ab1fde8088f56feb79fef57b951ed430562 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 15 Nov 2019 05:21:10 +0100 Subject: [PATCH] Calculate light closer to where it is used --- src/rendering/swrenderer/line/r_line.cpp | 41 +++-- src/rendering/swrenderer/line/r_line.h | 2 - .../swrenderer/line/r_renderdrawsegment.cpp | 146 +++++++----------- .../swrenderer/line/r_renderdrawsegment.h | 2 - src/rendering/swrenderer/line/r_wallsetup.h | 2 - .../swrenderer/segments/r_drawsegment.h | 3 +- 6 files changed, 79 insertions(+), 117 deletions(-) diff --git a/src/rendering/swrenderer/line/r_line.cpp b/src/rendering/swrenderer/line/r_line.cpp index e6b3c03c1..04206ac9a 100644 --- a/src/rendering/swrenderer/line/r_line.cpp +++ b/src/rendering/swrenderer/line/r_line.cpp @@ -405,8 +405,6 @@ namespace swrenderer if (draw_segment->HasFogBoundary() || draw_segment->HasTranslucentMidTexture() || draw_segment->Has3DFloorWalls()) { draw_segment->drawsegclip.SetBackupClip(Thread, start, stop, Thread->OpaquePass->ceilingclip); - draw_segment->light = mLight.GetLightPos(start); - draw_segment->lightstep = mLight.GetLightStep(); Thread->DrawSegments->PushTranslucent(draw_segment); } } @@ -446,7 +444,10 @@ namespace swrenderer // [ZZ] Only if not an active mirror if (!markportal) { - RenderDecal::RenderDecals(Thread, mLineSegment->sidedef, draw_segment, mLineSegment, mLight, walltop.ScreenY, wallbottom.ScreenY, false); + ProjectedWallLight walllight; + walllight.SetColormap(mFrontSector, mLineSegment); + walllight.SetLightLeft(Thread, WallC); + RenderDecal::RenderDecals(Thread, mLineSegment->sidedef, draw_segment, mLineSegment, walllight, walltop.ScreenY, wallbottom.ScreenY, false); } if (markportal) @@ -661,22 +662,6 @@ namespace swrenderer } } } - - FTexture *ftex = TexMan.GetPalettedTexture(sidedef->GetTexture(side_t::mid), true); - FSoftwareTexture *midtex = ftex && ftex->isValid() ? ftex->GetSoftwareTexture() : nullptr; - - bool segtextured = ftex != NULL || mTopTexture != NULL || mBottomTexture != NULL; - - if (m3DFloor.type == Fake3DOpaque::Normal) - { - mLight.SetColormap(mFrontSector, mLineSegment); - } - - // calculate light table - if (segtextured || (mBackSector && IsFogBoundary(mFrontSector, mBackSector))) - { - mLight.SetLightLeft(Thread, WallC); - } } void SWRenderLine::SetTextures() @@ -899,8 +884,12 @@ namespace swrenderer ProjectedWallTexcoords texcoords; texcoords.ProjectTop(Thread->Viewport.get(), mFrontSector, mBackSector, mLineSegment, WallC.sx1, WallC.sx2, WallT, mTopTexture); + ProjectedWallLight walllight; + walllight.SetColormap(mFrontSector, mLineSegment); + walllight.SetLightLeft(Thread, WallC); + RenderWallPart renderWallpart(Thread); - renderWallpart.Render(mFrontSector, mLineSegment, WallC, mTopTexture, x1, x2, walltop.ScreenY, wallupper.ScreenY, texcoords, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mBackCeilingZ1, mBackCeilingZ2), false, false, OPAQUE, mLight, GetLightList()); + renderWallpart.Render(mFrontSector, mLineSegment, WallC, mTopTexture, x1, x2, walltop.ScreenY, wallupper.ScreenY, texcoords, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mBackCeilingZ1, mBackCeilingZ2), false, false, OPAQUE, walllight, GetLightList()); } void SWRenderLine::RenderMiddleTexture(int x1, int x2) @@ -911,8 +900,12 @@ namespace swrenderer ProjectedWallTexcoords texcoords; texcoords.ProjectMid(Thread->Viewport.get(), mFrontSector, mLineSegment, WallC.sx1, WallC.sx2, WallT, mMiddleTexture); + ProjectedWallLight walllight; + walllight.SetColormap(mFrontSector, mLineSegment); + walllight.SetLightLeft(Thread, WallC); + RenderWallPart renderWallpart(Thread); - renderWallpart.Render(mFrontSector, mLineSegment, WallC, mMiddleTexture, x1, x2, walltop.ScreenY, wallbottom.ScreenY, texcoords, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, false, OPAQUE, mLight, GetLightList()); + renderWallpart.Render(mFrontSector, mLineSegment, WallC, mMiddleTexture, x1, x2, walltop.ScreenY, wallbottom.ScreenY, texcoords, MAX(mFrontCeilingZ1, mFrontCeilingZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, false, OPAQUE, walllight, GetLightList()); } void SWRenderLine::RenderBottomTexture(int x1, int x2) @@ -924,8 +917,12 @@ namespace swrenderer ProjectedWallTexcoords texcoords; texcoords.ProjectBottom(Thread->Viewport.get(), mFrontSector, mBackSector, mLineSegment, WallC.sx1, WallC.sx2, WallT, mBottomTexture); + ProjectedWallLight walllight; + walllight.SetColormap(mFrontSector, mLineSegment); + walllight.SetLightLeft(Thread, WallC); + RenderWallPart renderWallpart(Thread); - renderWallpart.Render(mFrontSector, mLineSegment, WallC, mBottomTexture, x1, x2, walllower.ScreenY, wallbottom.ScreenY, texcoords, MAX(mBackFloorZ1, mBackFloorZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, false, OPAQUE, mLight, GetLightList()); + renderWallpart.Render(mFrontSector, mLineSegment, WallC, mBottomTexture, x1, x2, walllower.ScreenY, wallbottom.ScreenY, texcoords, MAX(mBackFloorZ1, mBackFloorZ2), MIN(mFrontFloorZ1, mFrontFloorZ2), false, false, OPAQUE, walllight, GetLightList()); } FLightNode *SWRenderLine::GetLightList() diff --git a/src/rendering/swrenderer/line/r_line.h b/src/rendering/swrenderer/line/r_line.h index 2944a550f..cc226d768 100644 --- a/src/rendering/swrenderer/line/r_line.h +++ b/src/rendering/swrenderer/line/r_line.h @@ -115,8 +115,6 @@ namespace swrenderer bool rw_prepped; - ProjectedWallLight mLight; - bool markfloor; // False if the back side is the same plane. bool markceiling; diff --git a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp index 076e4f822..906181087 100644 --- a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp @@ -71,25 +71,6 @@ namespace swrenderer frontsector = curline->frontsector; backsector = curline->backsector; - // killough 4/13/98: get correct lightlevel for 2s normal textures - sector_t tempsec; - const sector_t *sec = Thread->OpaquePass->FakeFlat(frontsector, &tempsec, nullptr, nullptr, nullptr, 0, 0, 0, 0); - - mLight.SetColormap(sec, curline); - mLight.SetLightLeft(ds->light, ds->lightstep, ds->x1); - - Clip3DFloors *clip3d = Thread->Clip3D.get(); - - 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()) - { - mLight.SetColormap(frontsector, curline, &frontsector->e->XFloor.lightlist[i]); - break; - } - } - if (ds->HasFogBoundary()) RenderFog(ds, x1, x2); @@ -212,6 +193,23 @@ namespace swrenderer } } + sector_t tempsec; + const sector_t* sec = Thread->OpaquePass->FakeFlat(frontsector, &tempsec, nullptr, nullptr, nullptr, 0, 0, 0, 0); + + ProjectedWallLight walllight; + walllight.SetColormap(sec, curline); + walllight.SetLightLeft(Thread, ds->WallC); + + 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()) + { + walllight.SetColormap(frontsector, curline, &frontsector->e->XFloor.lightlist[i]); + break; + } + } + double top, bot; GetMaskedWallTopBottom(ds, top, bot); @@ -219,7 +217,7 @@ namespace swrenderer bool additive = (curline->linedef->flags & ML_ADDTRANS) != 0; RenderWallPart renderWallpart(Thread); - renderWallpart.Render(frontsector, curline, ds->WallC, tex, x1, x2, mceilingclip, mfloorclip, ds->texcoords, top, bot, true, additive, alpha, mLight, nullptr); + renderWallpart.Render(frontsector, curline, ds->WallC, tex, x1, x2, mceilingclip, mfloorclip, ds->texcoords, top, bot, true, additive, alpha, walllight, nullptr); } void RenderDrawSegment::Render3DFloorWall(DrawSegment *ds, int x1, int x2, F3DFloor *rover, double clipTop, double clipBottom, FSoftwareTexture *rw_pic) @@ -228,7 +226,37 @@ namespace swrenderer if (Alpha <= 0) return; - mLight.SetLightLeft(ds->light, ds->lightstep, ds->x1); + lightlist_t* lit = nullptr; + CameraLight* cameraLight = CameraLight::Instance(); + if (cameraLight->FixedLightLevel() < 0) + { + if (ds->Has3DFloorFrontSectorWalls() && !ds->Has3DFloorBackSectorWalls()) + { + for (int j = backsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) + { + if (clipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) + { + lit = &backsector->e->XFloor.lightlist[j]; + break; + } + } + } + else + { + for (int j = frontsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) + { + if (clipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) + { + lit = &frontsector->e->XFloor.lightlist[j]; + break; + } + } + } + } + + ProjectedWallLight walllight; + walllight.SetColormap(frontsector, curline, lit); + walllight.SetLightLeft(Thread, ds->WallC); wallupper.Project(Thread->Viewport.get(), clipTop - Thread->Viewport->viewpoint.Pos.Z, &ds->WallC); walllower.Project(Thread->Viewport.get(), clipBottom - Thread->Viewport->viewpoint.Pos.Z, &ds->WallC); @@ -243,9 +271,9 @@ namespace swrenderer GetMaskedWallTopBottom(ds, top, bot); RenderWallPart renderWallpart(Thread); - renderWallpart.Render(frontsector, curline, ds->WallC, rw_pic, x1, x2, wallupper.ScreenY, walllower.ScreenY, walltexcoords, top, bot, true, (rover->flags & FF_ADDITIVETRANS) != 0, Alpha, mLight, nullptr); + renderWallpart.Render(frontsector, curline, ds->WallC, rw_pic, x1, x2, wallupper.ScreenY, walllower.ScreenY, walltexcoords, top, bot, true, (rover->flags & FF_ADDITIVETRANS) != 0, Alpha, walllight, nullptr); - RenderDecal::RenderDecals(Thread, curline->sidedef, ds, curline, mLight, wallupper.ScreenY, walllower.ScreenY, true); + RenderDecal::RenderDecals(Thread, curline->sidedef, ds, curline, walllight, wallupper.ScreenY, walllower.ScreenY, true); } void RenderDrawSegment::Render3DFloorWallRange(DrawSegment *ds, int x1, int x2) @@ -434,38 +462,6 @@ namespace swrenderer if (rw_pic && !swimmable_found) { - // correct colors now - lightlist_t *lit = nullptr; - CameraLight *cameraLight = CameraLight::Instance(); - if (cameraLight->FixedLightLevel() < 0) - { - if (ds->Has3DFloorFrontSectorWalls() && !ds->Has3DFloorBackSectorWalls()) - { - for (j = backsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) - { - if (clipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) - { - lit = &backsector->e->XFloor.lightlist[j]; - break; - } - } - } - else - { - for (j = frontsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) - { - if (clipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) - { - lit = &frontsector->e->XFloor.lightlist[j]; - break; - } - } - } - } - - //mLight.lightlevel = ds->lightlevel; - mLight.SetColormap(frontsector, curline, lit); - Render3DFloorWall(ds, x1, x2, fover ? fover : rover, clipTop, clipBottom, rw_pic); } break; @@ -617,37 +613,6 @@ namespace swrenderer if (rw_pic && !swimmable_found) { - // correct colors now - lightlist_t *lit = nullptr; - CameraLight *cameraLight = CameraLight::Instance(); - if (cameraLight->FixedLightLevel() < 0) - { - if (ds->Has3DFloorFrontSectorWalls() && !ds->Has3DFloorBackSectorWalls()) - { - for (j = backsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) - { - if (clipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) - { - lit = &backsector->e->XFloor.lightlist[j]; - break; - } - } - } - else - { - for (j = frontsector->e->XFloor.lightlist.Size() - 1; j >= 0; j--) - { - if (clipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) - { - lit = &frontsector->e->XFloor.lightlist[j]; - break; - } - } - } - } - //mLight.lightlevel = ds->lightlevel; - mLight.SetColormap(frontsector, curline, lit); - Render3DFloorWall(ds, x1, x2, fover ? fover : rover, clipTop, clipBottom, rw_pic); } break; @@ -674,8 +639,15 @@ namespace swrenderer mfloorclip = walllower.ScreenY; } + sector_t tempsec; + const sector_t* sec = Thread->OpaquePass->FakeFlat(frontsector, &tempsec, nullptr, nullptr, nullptr, 0, 0, 0, 0); + + ProjectedWallLight walllight; + walllight.SetColormap(sec, curline); + walllight.SetLightLeft(Thread, ds->WallC); + RenderFogBoundary renderfog; - renderfog.Render(Thread, x1, x2, mceilingclip, mfloorclip, mLight); + renderfog.Render(Thread, x1, x2, mceilingclip, mfloorclip, walllight); } // Clip a midtexture to the floor and ceiling of the sector in front of it. diff --git a/src/rendering/swrenderer/line/r_renderdrawsegment.h b/src/rendering/swrenderer/line/r_renderdrawsegment.h index 5a393df32..6e39a54d5 100644 --- a/src/rendering/swrenderer/line/r_renderdrawsegment.h +++ b/src/rendering/swrenderer/line/r_renderdrawsegment.h @@ -51,8 +51,6 @@ namespace swrenderer seg_t *curline = nullptr; Fake3DTranslucent m3DFloor; - ProjectedWallLight mLight; - ProjectedWallLine wallupper; ProjectedWallLine walllower; }; diff --git a/src/rendering/swrenderer/line/r_wallsetup.h b/src/rendering/swrenderer/line/r_wallsetup.h index f7b78c248..923d33fec 100644 --- a/src/rendering/swrenderer/line/r_wallsetup.h +++ b/src/rendering/swrenderer/line/r_wallsetup.h @@ -110,8 +110,6 @@ namespace swrenderer float GetLightStep() const { return lightstep; } void SetColormap(const sector_t *frontsector, seg_t *lineseg, lightlist_t *lit = nullptr); - - void SetLightLeft(float left, float step, int startx) { lightleft = left; lightstep = step; x1 = startx; } void SetLightLeft(RenderThread *thread, const FWallCoords &wallc); private: diff --git a/src/rendering/swrenderer/segments/r_drawsegment.h b/src/rendering/swrenderer/segments/r_drawsegment.h index c2b88f79e..43c33b0b4 100644 --- a/src/rendering/swrenderer/segments/r_drawsegment.h +++ b/src/rendering/swrenderer/segments/r_drawsegment.h @@ -51,8 +51,7 @@ namespace swrenderer struct DrawSegment { seg_t *curline; - float light, lightstep; - short x1, x2; // Same as sx1 and sx2, but clipped to the drawseg + short x1, x2; FWallCoords WallC; FWallTmapVals tmapvals;