diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index 908988104..275310c31 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -100,7 +100,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c if (swrenderer::fixedlightlev < 0 && sub->sector->e->XFloor.lightlist.Size()) { lightlist_t *light = P_GetPlaneLight(sub->sector, &sub->sector->ceilingplane, false); - swrenderer::basecolormap = light->extra_colormap; + //basecolormap = light->extra_colormap; lightlevel = *light->p_lightlevel; } diff --git a/src/swrenderer/drawers/r_draw.cpp b/src/swrenderer/drawers/r_draw.cpp index b9a4a3ef0..f90b63af1 100644 --- a/src/swrenderer/drawers/r_draw.cpp +++ b/src/swrenderer/drawers/r_draw.cpp @@ -375,11 +375,9 @@ namespace swrenderer default: return 0; } } - - FDynamicColormap *basecolormapsave; } - bool R_SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color) + bool R_SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap) { using namespace drawerargs; @@ -428,7 +426,6 @@ namespace swrenderer } } } - basecolormapsave = basecolormap; // Check for special modes if (style.BlendOp == STYLEOP_Fuzz) @@ -488,14 +485,9 @@ namespace swrenderer return true; } - bool R_SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color) + bool R_SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap) { - return R_SetPatchStyle(style, FLOAT2FIXED(alpha), translation, color); - } - - void R_FinishSetPatchStyle() - { - basecolormap = basecolormapsave; + return R_SetPatchStyle(style, FLOAT2FIXED(alpha), translation, color, basecolormap); } DrawerFunc R_GetTransMaskDrawer() diff --git a/src/swrenderer/drawers/r_draw.h b/src/swrenderer/drawers/r_draw.h index bf26c8636..fd77d1c32 100644 --- a/src/swrenderer/drawers/r_draw.h +++ b/src/swrenderer/drawers/r_draw.h @@ -162,7 +162,7 @@ namespace swrenderer virtual void DrawSpanAddClamp() = 0; virtual void DrawSpanMaskedAddClamp() = 0; virtual void FillSpan() = 0; - virtual void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy) = 0; + virtual void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) = 0; virtual void DrawColoredSpan(int y, int x1, int x2) = 0; virtual void DrawFogBoundaryLine(int y, int x1, int x2) = 0; }; @@ -175,9 +175,8 @@ namespace swrenderer void R_InitShadeMaps(); void R_InitFuzzTable(int fuzzoff); - bool R_SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color); - bool R_SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color); - void R_FinishSetPatchStyle(); // Call this after finished drawing the current thing, in case its style was STYLE_Shade + bool R_SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap); + bool R_SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap); DrawerFunc R_GetTransMaskDrawer(); void R_UpdateFuzzPos(); diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index 18dd88adb..4e4783f3f 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -2480,7 +2480,7 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////// - DrawTiltedSpanPalCommand::DrawTiltedSpanPalCommand(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy) + DrawTiltedSpanPalCommand::DrawTiltedSpanPalCommand(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) : y(y), x1(x1), x2(x2), plane_sz(plane_sz), plane_su(plane_su), plane_sv(plane_sv), plane_shade(plane_shade), planeshade(planeshade), planelightfloat(planelightfloat), pviewx(pviewx), pviewy(pviewy) { using namespace drawerargs; diff --git a/src/swrenderer/drawers/r_draw_pal.h b/src/swrenderer/drawers/r_draw_pal.h index 06cbe1ea6..a96660f84 100644 --- a/src/swrenderer/drawers/r_draw_pal.h +++ b/src/swrenderer/drawers/r_draw_pal.h @@ -162,7 +162,7 @@ namespace swrenderer class DrawTiltedSpanPalCommand : public DrawerCommand { public: - DrawTiltedSpanPalCommand(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy); + DrawTiltedSpanPalCommand(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap); void Execute(DrawerThread *thread) override; FString DebugInfo() override { return "DrawTiltedSpanPalCommand"; } @@ -276,9 +276,9 @@ namespace swrenderer void DrawSpanMaskedAddClamp() override { DrawerCommandQueue::QueueCommand(); } void FillSpan() override { DrawerCommandQueue::QueueCommand(); } - void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy) override + void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) override { - DrawerCommandQueue::QueueCommand(y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy); + DrawerCommandQueue::QueueCommand(y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); } void DrawColoredSpan(int y, int x1, int x2) override { DrawerCommandQueue::QueueCommand(y, x1, x2); } diff --git a/src/swrenderer/drawers/r_draw_rgba.h b/src/swrenderer/drawers/r_draw_rgba.h index ae4957879..e1ed70350 100644 --- a/src/swrenderer/drawers/r_draw_rgba.h +++ b/src/swrenderer/drawers/r_draw_rgba.h @@ -380,7 +380,7 @@ namespace swrenderer void DrawSpanMaskedAddClamp() override { DrawerCommandQueue::QueueCommand(); } void FillSpan() override { DrawerCommandQueue::QueueCommand(); } - void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy) override + void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) override { DrawerCommandQueue::QueueCommand(y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy); } diff --git a/src/swrenderer/line/r_fogboundary.cpp b/src/swrenderer/line/r_fogboundary.cpp index 523ce4b08..18cf94055 100644 --- a/src/swrenderer/line/r_fogboundary.cpp +++ b/src/swrenderer/line/r_fogboundary.cpp @@ -45,7 +45,7 @@ namespace swrenderer { - void RenderFogBoundary::Render(int x1, int x2, short *uclip, short *dclip, int wallshade, float lightleft, float lightstep) + void RenderFogBoundary::Render(int x1, int x2, short *uclip, short *dclip, int wallshade, float lightleft, float lightstep, FDynamicColormap *basecolormap) { // This is essentially the same as R_MapVisPlane but with an extra step // to create new horizontal spans whenever the light changes enough that diff --git a/src/swrenderer/line/r_fogboundary.h b/src/swrenderer/line/r_fogboundary.h index de48738a0..ba7cd0044 100644 --- a/src/swrenderer/line/r_fogboundary.h +++ b/src/swrenderer/line/r_fogboundary.h @@ -18,7 +18,7 @@ namespace swrenderer class RenderFogBoundary { public: - static void Render(int x1, int x2, short *uclip, short *dclip, int wallshade, float lightleft, float lightstep); + static void Render(int x1, int x2, short *uclip, short *dclip, int wallshade, float lightleft, float lightstep, FDynamicColormap *basecolormap); private: static void RenderSection(int y, int y2, int x1); diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index c61caf2da..dee5f9250 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -55,7 +55,7 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor); namespace swrenderer { - void SWRenderLine::Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, visplane_t *linefloorplane, visplane_t *lineceilingplane, bool infog) + void SWRenderLine::Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, visplane_t *linefloorplane, visplane_t *lineceilingplane, bool infog, FDynamicColormap *colormap) { static sector_t tempsec; // killough 3/8/98: ceiling/water hack bool solid; @@ -67,6 +67,7 @@ namespace swrenderer floorplane = linefloorplane; ceilingplane = lineceilingplane; foggy = infog; + basecolormap = colormap; curline = line; @@ -591,7 +592,7 @@ namespace swrenderer // [ZZ] Only if not an active mirror if (!rw_markportal) { - RenderDecal::RenderDecals(curline->sidedef, draw_segment, wallshade, rw_lightleft, rw_lightstep, curline, WallC, foggy); + RenderDecal::RenderDecals(curline->sidedef, draw_segment, wallshade, rw_lightleft, rw_lightstep, curline, WallC, foggy, basecolormap); } if (rw_markportal) @@ -1079,7 +1080,7 @@ namespace swrenderer { rw_offset = -rw_offset; } - R_DrawWallSegment(frontsector, curline, WallC, rw_pic, x1, x2, walltop, wallbottom, swall, lwall, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy); + R_DrawWallSegment(frontsector, curline, WallC, rw_pic, x1, x2, walltop, wallbottom, swall, lwall, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap); } fillshort(ceilingclip + x1, x2 - x1, viewheight); fillshort(floorclip + x1, x2 - x1, 0xffff); @@ -1115,7 +1116,7 @@ namespace swrenderer { rw_offset = -rw_offset; } - R_DrawWallSegment(frontsector, curline, WallC, rw_pic, x1, x2, walltop, wallupper, swall, lwall, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_backcz1, rw_backcz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy); + R_DrawWallSegment(frontsector, curline, WallC, rw_pic, x1, x2, walltop, wallupper, swall, lwall, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_backcz1, rw_backcz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap); } memcpy(ceilingclip + x1, wallupper + x1, (x2 - x1) * sizeof(short)); } @@ -1154,7 +1155,7 @@ namespace swrenderer { rw_offset = -rw_offset; } - R_DrawWallSegment(frontsector, curline, WallC, rw_pic, x1, x2, walllower, wallbottom, swall, lwall, yscale, MAX(rw_backfz1, rw_backfz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy); + R_DrawWallSegment(frontsector, curline, WallC, rw_pic, x1, x2, walllower, wallbottom, swall, lwall, yscale, MAX(rw_backfz1, rw_backfz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap); } memcpy(floorclip + x1, walllower + x1, (x2 - x1) * sizeof(short)); } diff --git a/src/swrenderer/line/r_line.h b/src/swrenderer/line/r_line.h index 0be56dff5..c1ee23898 100644 --- a/src/swrenderer/line/r_line.h +++ b/src/swrenderer/line/r_line.h @@ -20,6 +20,7 @@ struct subsector_t; struct sector_t; struct side_t; struct line_t; +struct FDynamicColormap; namespace swrenderer { @@ -48,7 +49,7 @@ namespace swrenderer class SWRenderLine { public: - void Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, visplane_t *floorplane, visplane_t *ceilingplane, bool foggy); + void Render(seg_t *line, subsector_t *subsector, sector_t *sector, sector_t *fakebacksector, visplane_t *floorplane, visplane_t *ceilingplane, bool foggy, FDynamicColormap *basecolormap); private: bool RenderWallSegment(int x1, int x2); @@ -118,5 +119,6 @@ namespace swrenderer FTexture *midtexture; bool foggy; + FDynamicColormap *basecolormap; }; } diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index a33568472..5a13689ac 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -337,7 +337,7 @@ namespace swrenderer static void ProcessWallWorker( const FWallCoords &WallC, - int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, + int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, FDynamicColormap *basecolormap, const BYTE *(*getcol)(FTexture *tex, int x), DrawerFunc drawcolumn) { if (rw_pic->UseType == FTexture::TEX_Null) @@ -400,41 +400,39 @@ namespace swrenderer NetUpdate(); } - static void ProcessNormalWall(const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, const BYTE *(*getcol)(FTexture *tex, int x) = R_GetColumn) + static void ProcessNormalWall(const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, FDynamicColormap *basecolormap, const BYTE *(*getcol)(FTexture *tex, int x) = R_GetColumn) { - ProcessWallWorker(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, getcol, &SWPixelFormatDrawers::DrawWallColumn); + ProcessWallWorker(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap, getcol, &SWPixelFormatDrawers::DrawWallColumn); } - static void ProcessMaskedWall(const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, const BYTE *(*getcol)(FTexture *tex, int x) = R_GetColumn) + static void ProcessMaskedWall(const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, FDynamicColormap *basecolormap, const BYTE *(*getcol)(FTexture *tex, int x) = R_GetColumn) { if (!rw_pic->bMasked) // Textures that aren't masked can use the faster ProcessNormalWall. { - ProcessNormalWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, getcol); + ProcessNormalWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap, getcol); } else { - ProcessWallWorker(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, getcol, &SWPixelFormatDrawers::DrawWallMaskedColumn); + ProcessWallWorker(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap, getcol, &SWPixelFormatDrawers::DrawWallMaskedColumn); } } - static void ProcessTranslucentWall(const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, const BYTE *(*getcol)(FTexture *tex, int x) = R_GetColumn) + static void ProcessTranslucentWall(const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, FDynamicColormap *basecolormap, const BYTE *(*getcol)(FTexture *tex, int x) = R_GetColumn) { DrawerFunc drawcol1 = R_GetTransMaskDrawer(); if (drawcol1 == nullptr) { // The current translucency is unsupported, so draw with regular ProcessMaskedWall instead. - ProcessMaskedWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, getcol); + ProcessMaskedWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap, getcol); } else { - ProcessWallWorker(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, getcol, drawcol1); + ProcessWallWorker(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap, getcol, drawcol1); } } - static void ProcessStripedWall(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool foggy) + static void ProcessStripedWall(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool foggy, FDynamicColormap *basecolormap) { - FDynamicColormap *startcolormap = basecolormap; - short most1[MAXWIDTH], most2[MAXWIDTH], most3[MAXWIDTH]; short *up, *down; @@ -456,7 +454,7 @@ namespace swrenderer { down[j] = clamp(most3[j], up[j], dwal[j]); } - ProcessNormalWall(WallC, x1, x2, up, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep); + ProcessNormalWall(WallC, x1, x2, up, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap); up = down; down = (down == most1) ? most2 : most1; } @@ -466,32 +464,31 @@ namespace swrenderer wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, *lit->p_lightlevel, lit->lightsource != NULL) + R_ActualExtraLight(foggy)); } - ProcessNormalWall(WallC, x1, x2, up, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep); - basecolormap = startcolormap; + ProcessNormalWall(WallC, x1, x2, up, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap); } - static void ProcessWall(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool mask, bool foggy) + static void ProcessWall(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool mask, bool foggy, FDynamicColormap *basecolormap) { if (mask) { if (colfunc == basecolfunc) { - ProcessMaskedWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep); + ProcessMaskedWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap); } else { - ProcessTranslucentWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep); + ProcessTranslucentWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap); } } else { if (fixedcolormap != NULL || fixedlightlev >= 0 || !(frontsector->e && frontsector->e->XFloor.lightlist.Size())) { - ProcessNormalWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep); + ProcessNormalWall(WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap); } else { - ProcessStripedWall(frontsector, curline, WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, foggy); + ProcessStripedWall(frontsector, curline, WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, foggy, basecolormap); } } } @@ -507,7 +504,7 @@ namespace swrenderer // //============================================================================= - static void ProcessWallNP2(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, double top, double bot, int wallshade, fixed_t xoffset, float light, float lightstep, bool mask, bool foggy) + static void ProcessWallNP2(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, double top, double bot, int wallshade, fixed_t xoffset, float light, float lightstep, bool mask, bool foggy, FDynamicColormap *basecolormap) { short most1[MAXWIDTH], most2[MAXWIDTH], most3[MAXWIDTH]; short *up, *down; @@ -534,14 +531,14 @@ namespace swrenderer { down[j] = clamp(most3[j], up[j], dwal[j]); } - ProcessWall(frontsector, curline, WallC, x1, x2, up, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy); + ProcessWall(frontsector, curline, WallC, x1, x2, up, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy, basecolormap); up = down; down = (down == most1) ? most2 : most1; } partition -= scaledtexheight; dc_texturemid -= texheight; } - ProcessWall(frontsector, curline, WallC, x1, x2, up, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy); + ProcessWall(frontsector, curline, WallC, x1, x2, up, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy, basecolormap); } else { // upside down: draw strips from bottom to top @@ -558,18 +555,18 @@ namespace swrenderer { up[j] = clamp(most3[j], uwal[j], down[j]); } - ProcessWall(frontsector, curline, WallC, x1, x2, up, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy); + ProcessWall(frontsector, curline, WallC, x1, x2, up, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy, basecolormap); down = up; up = (up == most1) ? most2 : most1; } partition -= scaledtexheight; dc_texturemid -= texheight; } - ProcessWall(frontsector, curline, WallC, x1, x2, uwal, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy); + ProcessWall(frontsector, curline, WallC, x1, x2, uwal, down, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, mask, foggy, basecolormap); } } - void R_DrawDrawSeg(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *pic, drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool foggy) + void R_DrawDrawSeg(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *pic, drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool foggy, FDynamicColormap *basecolormap) { rw_pic = pic; if (rw_pic->GetHeight() != 1 << rw_pic->HeightBits) @@ -589,34 +586,34 @@ namespace swrenderer { bot = MAX(bot, clip3d->sclipBottom); } - ProcessWallNP2(frontsector, curline, WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, top, bot, wallshade, xoffset, light, lightstep, true, foggy); + ProcessWallNP2(frontsector, curline, WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, top, bot, wallshade, xoffset, light, lightstep, true, foggy, basecolormap); } else { - ProcessWall(frontsector, curline, WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, true, foggy); + ProcessWall(frontsector, curline, WallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, true, foggy, basecolormap); } } - void R_DrawWallSegment(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *pic, int x1, int x2, short *walltop, short *wallbottom, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, int wallshade, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy) + void R_DrawWallSegment(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *pic, int x1, int x2, short *walltop, short *wallbottom, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, int wallshade, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy, FDynamicColormap *basecolormap) { rw_pic = pic; dc_light_list = light_list; if (rw_pic->GetHeight() != 1 << rw_pic->HeightBits) { - ProcessWallNP2(frontsector, curline, WallC, x1, x2, walltop, wallbottom, swall, lwall, yscale, top, bottom, wallshade, xoffset, light, lightstep, false, foggy); + ProcessWallNP2(frontsector, curline, WallC, x1, x2, walltop, wallbottom, swall, lwall, yscale, top, bottom, wallshade, xoffset, light, lightstep, false, foggy, basecolormap); } else { - ProcessWall(frontsector, curline, WallC, x1, x2, walltop, wallbottom, swall, lwall, yscale, wallshade, xoffset, light, lightstep, false, foggy); + ProcessWall(frontsector, curline, WallC, x1, x2, walltop, wallbottom, swall, lwall, yscale, wallshade, xoffset, light, lightstep, false, foggy, basecolormap); } dc_light_list = nullptr; } - void R_DrawSkySegment(FTexture *pic, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, const uint8_t *(*getcol)(FTexture *tex, int x)) + void R_DrawSkySegment(FTexture *pic, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, FDynamicColormap *basecolormap, const uint8_t *(*getcol)(FTexture *tex, int x)) { rw_pic = pic; FWallCoords wallC; // Not used. To do: don't use r_walldraw to draw the sky!! - ProcessNormalWall(wallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, getcol); + ProcessNormalWall(wallC, x1, x2, uwal, dwal, swal, lwal, yrepeat, wallshade, xoffset, light, lightstep, basecolormap, getcol); } } diff --git a/src/swrenderer/line/r_walldraw.h b/src/swrenderer/line/r_walldraw.h index 797795099..d2d3ffbc1 100644 --- a/src/swrenderer/line/r_walldraw.h +++ b/src/swrenderer/line/r_walldraw.h @@ -37,7 +37,7 @@ namespace swrenderer uint32_t height; }; - void R_DrawWallSegment(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *rw_pic, int x1, int x2, short *walltop, short *wallbottom, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, int wallshade, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy); - void R_DrawSkySegment(FTexture *rw_pic, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, const uint8_t *(*getcol)(FTexture *tex, int col)); - void R_DrawDrawSeg(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *rw_pic, drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool foggy); + void R_DrawWallSegment(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *rw_pic, int x1, int x2, short *walltop, short *wallbottom, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, int wallshade, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy, FDynamicColormap *basecolormap); + void R_DrawSkySegment(FTexture *rw_pic, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, FDynamicColormap *basecolormap, const uint8_t *(*getcol)(FTexture *tex, int col)); + void R_DrawDrawSeg(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *rw_pic, drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, int wallshade, fixed_t xoffset, float light, float lightstep, bool foggy, FDynamicColormap *basecolormap); } diff --git a/src/swrenderer/plane/r_flatplane.cpp b/src/swrenderer/plane/r_flatplane.cpp index 9a9494833..4c020468e 100644 --- a/src/swrenderer/plane/r_flatplane.cpp +++ b/src/swrenderer/plane/r_flatplane.cpp @@ -44,7 +44,7 @@ namespace swrenderer { - void RenderFlatPlane::Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked) + void RenderFlatPlane::Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked, FDynamicColormap *colormap) { using namespace drawerargs; @@ -105,6 +105,7 @@ namespace swrenderer planeheight = fabs(pl->height.Zat0() - ViewPos.Z); + basecolormap = colormap; GlobVis = r_FloorVisibility / planeheight; ds_light = 0; if (fixedlightlev >= 0) diff --git a/src/swrenderer/plane/r_flatplane.h b/src/swrenderer/plane/r_flatplane.h index bd830f63b..c4077a908 100644 --- a/src/swrenderer/plane/r_flatplane.h +++ b/src/swrenderer/plane/r_flatplane.h @@ -22,7 +22,7 @@ namespace swrenderer class RenderFlatPlane : PlaneRenderer { public: - void Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked); + void Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked, FDynamicColormap *basecolormap); static void SetupSlope(); @@ -34,6 +34,7 @@ namespace swrenderer bool plane_shade; int planeshade; double GlobVis; + FDynamicColormap *basecolormap; fixed_t pviewx, pviewy; fixed_t xscale, yscale; double xstepscale, ystepscale; diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index ab8dedb97..14b494a81 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -446,7 +446,7 @@ namespace swrenderer lastskycol_bgra[x] = 0xffffffff; } R_DrawSkySegment(frontskytex, pl->left, pl->right, (short *)pl->top, (short *)pl->bottom, swall, lwall, - frontyScale, 0, 0, 0.0f, 0.0f, backskytex == NULL ? RenderSkyPlane::GetOneSkyColumn : RenderSkyPlane::GetTwoSkyColumns); + frontyScale, 0, 0, 0.0f, 0.0f, nullptr, backskytex == nullptr ? RenderSkyPlane::GetOneSkyColumn : RenderSkyPlane::GetTwoSkyColumns); } else { // The texture does not tile nicely @@ -483,7 +483,7 @@ namespace swrenderer lastskycol[x] = 0xffffffff; lastskycol_bgra[x] = 0xffffffff; } - R_DrawSkySegment(frontskytex, pl->left, pl->right, top, bot, swall, lwall, frontskytex->Scale.Y, 0, 0, 0.0f, 0.0f, backskytex == NULL ? RenderSkyPlane::GetOneSkyColumn : RenderSkyPlane::GetTwoSkyColumns); + R_DrawSkySegment(frontskytex, pl->left, pl->right, top, bot, swall, lwall, frontskytex->Scale.Y, 0, 0, 0.0f, 0.0f, nullptr, backskytex == nullptr ? RenderSkyPlane::GetOneSkyColumn : RenderSkyPlane::GetTwoSkyColumns); yl = yh; yh += drawheight; dc_texturemid = iscale * (centery - yl - 1); diff --git a/src/swrenderer/plane/r_slopeplane.cpp b/src/swrenderer/plane/r_slopeplane.cpp index b2d42e198..9857dc11b 100644 --- a/src/swrenderer/plane/r_slopeplane.cpp +++ b/src/swrenderer/plane/r_slopeplane.cpp @@ -48,7 +48,7 @@ namespace swrenderer { - void RenderSlopePlane::Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked) + void RenderSlopePlane::Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked, FDynamicColormap *colormap) { using namespace drawerargs; @@ -148,6 +148,8 @@ namespace swrenderer if (pl->height.fC() > 0) planelightfloat = -planelightfloat; + basecolormap = colormap; + if (fixedlightlev >= 0) { R_SetDSColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); @@ -180,6 +182,6 @@ namespace swrenderer void RenderSlopePlane::RenderLine(int y, int x1, int x2) { - R_Drawers()->DrawTiltedSpan(y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy); + R_Drawers()->DrawTiltedSpan(y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); } } diff --git a/src/swrenderer/plane/r_slopeplane.h b/src/swrenderer/plane/r_slopeplane.h index 6fad95709..7dc6e7838 100644 --- a/src/swrenderer/plane/r_slopeplane.h +++ b/src/swrenderer/plane/r_slopeplane.h @@ -20,7 +20,7 @@ namespace swrenderer class RenderSlopePlane : PlaneRenderer { public: - void Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked); + void Render(visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked, FDynamicColormap *basecolormap); private: void RenderLine(int y, int x1, int x2) override; @@ -31,5 +31,6 @@ namespace swrenderer int planeshade; fixed_t pviewx, pviewy; fixed_t xscale, yscale; + FDynamicColormap *basecolormap; }; } diff --git a/src/swrenderer/plane/r_visibleplane.cpp b/src/swrenderer/plane/r_visibleplane.cpp index 6731262f7..fbb1e37a0 100644 --- a/src/swrenderer/plane/r_visibleplane.cpp +++ b/src/swrenderer/plane/r_visibleplane.cpp @@ -108,17 +108,15 @@ namespace swrenderer double xscale = xform.xScale * tex->Scale.X; double yscale = xform.yScale * tex->Scale.Y; - basecolormap = colormap; - if (!height.isSlope() && !tilt) { RenderFlatPlane renderer; - renderer.Render(this, xscale, yscale, alpha, additive, masked); + renderer.Render(this, xscale, yscale, alpha, additive, masked, colormap); } else { RenderSlopePlane renderer; - renderer.Render(this, xscale, yscale, alpha, additive, masked); + renderer.Render(this, xscale, yscale, alpha, additive, masked, colormap); } } NetUpdate(); diff --git a/src/swrenderer/plane/r_visibleplanelist.cpp b/src/swrenderer/plane/r_visibleplanelist.cpp index 760b85560..7cdfdc425 100644 --- a/src/swrenderer/plane/r_visibleplanelist.cpp +++ b/src/swrenderer/plane/r_visibleplanelist.cpp @@ -165,7 +165,7 @@ namespace swrenderer } } - visplane_t *VisiblePlaneList::FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal) + visplane_t *VisiblePlaneList::FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal, FDynamicColormap *basecolormap) { secplane_t plane; visplane_t *check; diff --git a/src/swrenderer/plane/r_visibleplanelist.h b/src/swrenderer/plane/r_visibleplanelist.h index 3db52d5bb..a38fe2ffd 100644 --- a/src/swrenderer/plane/r_visibleplanelist.h +++ b/src/swrenderer/plane/r_visibleplanelist.h @@ -31,7 +31,7 @@ namespace swrenderer void Deinit(); void Clear(bool fullclear); - visplane_t *FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal); + visplane_t *FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive, const FTransform &xxform, int sky, FSectorPortal *portal, FDynamicColormap *basecolormap); visplane_t *GetRange(visplane_t *pl, int start, int stop); int Render(); diff --git a/src/swrenderer/scene/r_light.cpp b/src/swrenderer/scene/r_light.cpp index d6c03b831..7ef86ca25 100644 --- a/src/swrenderer/scene/r_light.cpp +++ b/src/swrenderer/scene/r_light.cpp @@ -45,7 +45,6 @@ namespace swrenderer double r_SpriteVisibility; double r_ParticleVisibility; - FDynamicColormap *basecolormap; // [RH] colormap currently drawing with int fixedlightlev; FSWColormap *fixedcolormap; FSpecialColormap *realfixedcolormap; diff --git a/src/swrenderer/scene/r_light.h b/src/swrenderer/scene/r_light.h index 245eaafc9..50b4fae84 100644 --- a/src/swrenderer/scene/r_light.h +++ b/src/swrenderer/scene/r_light.h @@ -60,7 +60,6 @@ namespace swrenderer extern int fixedlightlev; extern FSWColormap *fixedcolormap; extern FSpecialColormap *realfixedcolormap; - extern FDynamicColormap *basecolormap; // [RH] Colormap for sector currently being drawn inline int R_ActualExtraLight(bool fog) { return fog ? 0 : extralight << 4; } diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index b49782517..7db41d6f8 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -398,7 +398,7 @@ namespace swrenderer } // kg3D - add fake segs, never rendered - void RenderOpaquePass::FakeDrawLoop(subsector_t *sub, visplane_t *floorplane, visplane_t *ceilingplane, bool foggy) + void RenderOpaquePass::FakeDrawLoop(subsector_t *sub, visplane_t *floorplane, visplane_t *ceilingplane, bool foggy, FDynamicColormap *basecolormap) { int count; seg_t* line; @@ -410,7 +410,7 @@ namespace swrenderer { if ((line->sidedef) && !(line->sidedef->Flags & WALLF_POLYOBJ)) { - renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy); + renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy, basecolormap); } line++; } @@ -479,6 +479,7 @@ namespace swrenderer bool foggy = level.fadeto || frontsector->ColorMap->Fade || (level.flags & LEVEL_HASFADETABLE); // kg3D - fake lights + FDynamicColormap *basecolormap; if (fixedlightlev < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(frontsector, &frontsector->ceilingplane, false); @@ -510,7 +511,8 @@ namespace swrenderer !!(frontsector->GetFlags(sector_t::ceiling) & PLANEF_ADDITIVE), frontsector->planes[sector_t::ceiling].xform, frontsector->sky, - portal + portal, + basecolormap ) : nullptr; if (ceilingplane) @@ -550,7 +552,8 @@ namespace swrenderer !!(frontsector->GetFlags(sector_t::floor) & PLANEF_ADDITIVE), frontsector->planes[sector_t::floor].xform, frontsector->sky, - portal + portal, + basecolormap ) : nullptr; if (floorplane) @@ -615,12 +618,13 @@ namespace swrenderer !!(clip3d->fakeFloor->flags & FF_ADDITIVETRANS), frontsector->planes[position].xform, frontsector->sky, - nullptr); + nullptr, + basecolormap); if (floorplane) floorplane->AddLights(frontsector->lighthead); - FakeDrawLoop(sub, floorplane, ceilingplane, foggy); + FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap); clip3d->fake3D = 0; frontsector = sub->sector; } @@ -680,12 +684,13 @@ namespace swrenderer !!(clip3d->fakeFloor->flags & FF_ADDITIVETRANS), frontsector->planes[position].xform, frontsector->sky, - nullptr); + nullptr, + basecolormap); if (ceilingplane) ceilingplane->AddLights(frontsector->lighthead); - FakeDrawLoop(sub, floorplane, ceilingplane, foggy); + FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap); clip3d->fake3D = 0; frontsector = sub->sector; } @@ -704,7 +709,7 @@ namespace swrenderer // lightlevels on floor & ceiling lightlevels in the surrounding area. // [RH] Handle sprite lighting like Duke 3D: If the ceiling is a sky, sprites are lit by // it, otherwise they are lit by the floor. - AddSprites(sub->sector, frontsector->GetTexture(sector_t::ceiling) == skyflatnum ? ceilinglightlevel : floorlightlevel, FakeSide, foggy); + AddSprites(sub->sector, frontsector->GetTexture(sector_t::ceiling) == skyflatnum ? ceilinglightlevel : floorlightlevel, FakeSide, foggy, basecolormap); // [RH] Add particles if ((unsigned int)(sub - subsectors) < (unsigned int)numsubsectors) @@ -746,14 +751,14 @@ namespace swrenderer clip3d->fakeFloor->validcount = validcount; clip3d->NewClip(); } - renderline.Render(line, InSubsector, frontsector, &tempsec, floorplane, ceilingplane, foggy); // fake + renderline.Render(line, InSubsector, frontsector, &tempsec, floorplane, ceilingplane, foggy, basecolormap); // fake } clip3d->fakeFloor = nullptr; clip3d->fake3D = 0; floorplane = backupfp; ceilingplane = backupcp; } - renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy); // now real + renderline.Render(line, InSubsector, frontsector, nullptr, floorplane, ceilingplane, foggy, basecolormap); // now real } line++; } @@ -809,7 +814,7 @@ namespace swrenderer fillshort(ceilingclip, viewwidth, !screen->Accel2D && ConBottom > viewwindowy && !bRenderingToCanvas ? (ConBottom - viewwindowy) : 0); } - void RenderOpaquePass::AddSprites(sector_t *sec, int lightlevel, WaterFakeSide fakeside, bool foggy) + void RenderOpaquePass::AddSprites(sector_t *sec, int lightlevel, WaterFakeSide fakeside, bool foggy, FDynamicColormap *basecolormap) { F3DFloor *fakeceiling = nullptr; F3DFloor *fakefloor = nullptr; @@ -869,15 +874,15 @@ namespace swrenderer { if ((sprite.renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) { - RenderWallSprite::Project(thing, sprite.pos, sprite.picnum, sprite.spriteScale, sprite.renderflags, spriteshade, foggy); + RenderWallSprite::Project(thing, sprite.pos, sprite.picnum, sprite.spriteScale, sprite.renderflags, spriteshade, foggy, basecolormap); } else if (sprite.voxel) { - RenderVoxel::Project(thing, sprite.pos, sprite.voxel, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, spriteshade, foggy); + RenderVoxel::Project(thing, sprite.pos, sprite.voxel, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, spriteshade, foggy, basecolormap); } else { - RenderSprite::Project(thing, sprite.pos, sprite.tex, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, spriteshade, foggy); + RenderSprite::Project(thing, sprite.pos, sprite.tex, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, spriteshade, foggy, basecolormap); } } } diff --git a/src/swrenderer/scene/r_opaque_pass.h b/src/swrenderer/scene/r_opaque_pass.h index 4ea6a6465..e0a244092 100644 --- a/src/swrenderer/scene/r_opaque_pass.h +++ b/src/swrenderer/scene/r_opaque_pass.h @@ -68,9 +68,9 @@ namespace swrenderer bool CheckBBox(float *bspcoord); void AddPolyobjs(subsector_t *sub); - void FakeDrawLoop(subsector_t *sub, visplane_t *floorplane, visplane_t *ceilingplane, bool foggy); + void FakeDrawLoop(subsector_t *sub, visplane_t *floorplane, visplane_t *ceilingplane, bool foggy, FDynamicColormap *basecolormap); - void AddSprites(sector_t *sec, int lightlevel, WaterFakeSide fakeside, bool foggy); + void AddSprites(sector_t *sec, int lightlevel, WaterFakeSide fakeside, bool foggy, FDynamicColormap *basecolormap); static bool IsPotentiallyVisible(AActor *thing); static bool GetThingSprite(AActor *thing, ThingSprite &sprite); diff --git a/src/swrenderer/segments/r_drawsegment.cpp b/src/swrenderer/segments/r_drawsegment.cpp index 7d38eb2ec..5b7503c38 100644 --- a/src/swrenderer/segments/r_drawsegment.cpp +++ b/src/swrenderer/segments/r_drawsegment.cpp @@ -147,8 +147,9 @@ namespace swrenderer curline = ds->curline; + FDynamicColormap *patchstylecolormap = nullptr; bool visible = R_SetPatchStyle(LegacyRenderStyles[curline->linedef->flags & ML_ADDTRANS ? STYLE_Add : STYLE_Translucent], - (float)MIN(curline->linedef->alpha, 1.), 0, 0); + (float)MIN(curline->linedef->alpha, 1.), 0, 0, patchstylecolormap); if (!visible && !ds->bFogBoundary && !ds->bFakeBoundary) { @@ -169,7 +170,7 @@ namespace swrenderer // killough 4/13/98: get correct lightlevel for 2s normal textures sec = RenderOpaquePass::Instance()->FakeFlat(frontsector, &tempsec, nullptr, nullptr, nullptr, 0, 0, 0, 0); - basecolormap = sec->ColorMap; // [RH] Set basecolormap + FDynamicColormap *basecolormap = sec->ColorMap; // [RH] Set basecolormap int wallshade = ds->shade; rw_lightstep = ds->lightstep; @@ -202,7 +203,7 @@ namespace swrenderer // [RH] Draw fog partition if (ds->bFogBoundary) { - RenderFogBoundary::Render(x1, x2, mceilingclip, mfloorclip, wallshade, rw_light, rw_lightstep); + RenderFogBoundary::Render(x1, x2, mceilingclip, mfloorclip, wallshade, rw_light, rw_lightstep, basecolormap); if (ds->maskedtexturecol == -1) { goto clearfog; @@ -420,11 +421,10 @@ namespace swrenderer rw_offset = 0; rw_pic = tex; - R_DrawDrawSeg(frontsector, curline, WallC, rw_pic, ds, x1, x2, mceilingclip, mfloorclip, MaskedSWall, maskedtexturecol, ds->yscale, wallshade, rw_offset, rw_light, rw_lightstep, ds->foggy); + R_DrawDrawSeg(frontsector, curline, WallC, rw_pic, ds, x1, x2, mceilingclip, mfloorclip, MaskedSWall, maskedtexturecol, ds->yscale, wallshade, rw_offset, rw_light, rw_lightstep, ds->foggy, basecolormap); } clearfog: - R_FinishSetPatchStyle(); if (ds->bFakeBoundary & 3) { R_RenderFakeWallRange(ds, x1, x2, wallshade); @@ -448,7 +448,7 @@ namespace swrenderer } // kg3D - render one fake wall - void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover, int wallshade) + void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover, int wallshade, FDynamicColormap *basecolormap) { int i; double xscale; @@ -456,12 +456,10 @@ namespace swrenderer fixed_t Alpha = Scale(rover->alpha, OPAQUE, 255); bool visible = R_SetPatchStyle(LegacyRenderStyles[rover->flags & FF_ADDITIVETRANS ? STYLE_Add : STYLE_Translucent], - Alpha, 0, 0); + Alpha, 0, 0, basecolormap); - if (!visible) { - R_FinishSetPatchStyle(); + if (!visible) return; - } rw_lightstep = ds->lightstep; rw_light = ds->light + (x1 - ds->x1) * rw_lightstep; @@ -547,8 +545,7 @@ namespace swrenderer } PrepLWall(lwall, curline->sidedef->TexelLength*xscale, ds->sx1, ds->sx2, WallT); - R_DrawDrawSeg(frontsector, curline, WallC, rw_pic, ds, x1, x2, wallupper, walllower, MaskedSWall, lwall, yscale, wallshade, rw_offset, rw_light, rw_lightstep, ds->foggy); - R_FinishSetPatchStyle(); + R_DrawDrawSeg(frontsector, curline, WallC, rw_pic, ds, x1, x2, wallupper, walllower, MaskedSWall, lwall, yscale, wallshade, rw_offset, rw_light, rw_lightstep, ds->foggy, basecolormap); } // kg3D - walls of fake floors @@ -734,7 +731,7 @@ namespace swrenderer } } // correct colors now - basecolormap = frontsector->ColorMap; + FDynamicColormap *basecolormap = frontsector->ColorMap; wallshade = ds->shade; if (fixedlightlev < 0) { @@ -767,7 +764,7 @@ namespace swrenderer } if (rw_pic != DONT_DRAW) { - R_RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade); + R_RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade, basecolormap); } else rw_pic = nullptr; break; @@ -908,7 +905,7 @@ namespace swrenderer } } // correct colors now - basecolormap = frontsector->ColorMap; + FDynamicColormap *basecolormap = frontsector->ColorMap; wallshade = ds->shade; if (fixedlightlev < 0) { @@ -942,7 +939,7 @@ namespace swrenderer if (rw_pic != DONT_DRAW) { - R_RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade); + R_RenderFakeWall(ds, x1, x2, fover ? fover : rover, wallshade, basecolormap); } else { diff --git a/src/swrenderer/segments/r_drawsegment.h b/src/swrenderer/segments/r_drawsegment.h index eaa1283a0..5533ec430 100644 --- a/src/swrenderer/segments/r_drawsegment.h +++ b/src/swrenderer/segments/r_drawsegment.h @@ -60,6 +60,6 @@ namespace swrenderer drawseg_t *R_AddDrawSegment(); void ClipMidtex(int x1, int x2); void R_RenderMaskedSegRange(drawseg_t *ds, int x1, int x2); - void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover, int wallshade); + void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover, int wallshade, FDynamicColormap *basecolormap); void R_RenderFakeWallRange(drawseg_t *ds, int x1, int x2, int wallshade); } diff --git a/src/swrenderer/things/r_decal.cpp b/src/swrenderer/things/r_decal.cpp index 7011bb08b..1f0c02d0a 100644 --- a/src/swrenderer/things/r_decal.cpp +++ b/src/swrenderer/things/r_decal.cpp @@ -47,11 +47,11 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor); namespace swrenderer { - void RenderDecal::RenderDecals(side_t *sidedef, drawseg_t *draw_segment, int wallshade, float lightleft, float lightstep, seg_t *curline, const FWallCoords &wallC, bool foggy) + void RenderDecal::RenderDecals(side_t *sidedef, drawseg_t *draw_segment, int wallshade, float lightleft, float lightstep, seg_t *curline, const FWallCoords &wallC, bool foggy, FDynamicColormap *basecolormap) { for (DBaseDecal *decal = sidedef->AttachedDecals; decal != NULL; decal = decal->WallNext) { - Render(sidedef, decal, draw_segment, wallshade, lightleft, lightstep, curline, wallC, foggy, 0); + Render(sidedef, decal, draw_segment, wallshade, lightleft, lightstep, curline, wallC, foggy, basecolormap, 0); } } @@ -59,7 +59,7 @@ namespace swrenderer // = 1: drawing masked textures (including sprites) // Currently, only pass = 0 is done or used - void RenderDecal::Render(side_t *wall, DBaseDecal *decal, drawseg_t *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, FWallCoords WallC, bool foggy, int pass) + void RenderDecal::Render(side_t *wall, DBaseDecal *decal, drawseg_t *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, FWallCoords WallC, bool foggy, FDynamicColormap *basecolormap, int pass) { DVector2 decal_left, decal_right, decal_pos; int x1, x2; @@ -277,7 +277,7 @@ namespace swrenderer { int x = x1; - bool visible = R_SetPatchStyle(decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor); + bool visible = R_SetPatchStyle(decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, basecolormap); // R_SetPatchStyle can modify basecolormap. if (rereadcolormap) @@ -304,12 +304,10 @@ namespace swrenderer // needrepeat will be 0, and the while will fail. mceilingclip = RenderOpaquePass::Instance()->floorclip; mfloorclip = wallbottom; - R_FinishSetPatchStyle(); } while (needrepeat--); colfunc = basecolfunc; - R_FinishSetPatchStyle(); done: WallC = savecoord; } diff --git a/src/swrenderer/things/r_decal.h b/src/swrenderer/things/r_decal.h index c16c2047e..2bee90036 100644 --- a/src/swrenderer/things/r_decal.h +++ b/src/swrenderer/things/r_decal.h @@ -23,10 +23,10 @@ namespace swrenderer class RenderDecal { public: - static void RenderDecals(side_t *wall, drawseg_t *draw_segment, int wallshade, float lightleft, float lightstep, seg_t *curline, const FWallCoords &wallC, bool foggy); + static void RenderDecals(side_t *wall, drawseg_t *draw_segment, int wallshade, float lightleft, float lightstep, seg_t *curline, const FWallCoords &wallC, bool foggy, FDynamicColormap *basecolormap); private: - static void Render(side_t *wall, DBaseDecal *first, drawseg_t *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, FWallCoords wallC, bool foggy, int pass); + static void Render(side_t *wall, DBaseDecal *first, drawseg_t *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, FWallCoords wallC, bool foggy, FDynamicColormap *basecolormap, int pass); static void DrawColumn(int x, FTexture *WallSpriteTile, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); }; } diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index 17c1d4da7..b94ce1941 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -99,6 +99,7 @@ namespace swrenderer (r_deathcamera && camera->health <= 0)) return; + FDynamicColormap *basecolormap; if (fixedlightlev < 0 && viewsector->e && viewsector->e->XFloor.lightlist.Size()) { for (i = viewsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) @@ -183,7 +184,7 @@ namespace swrenderer if ((psp->GetID() != PSP_TARGETCENTER || CrosshairImage == nullptr) && psp->GetCaller() != nullptr) { - Render(psp, camera, bobx, boby, wx, wy, r_TicFracF, spriteshade); + Render(psp, camera, bobx, boby, wx, wy, r_TicFracF, spriteshade, basecolormap); } psp = psp->GetNext(); @@ -193,7 +194,7 @@ namespace swrenderer } } - void RenderPlayerSprite::Render(DPSprite *pspr, AActor *owner, float bobx, float boby, double wx, double wy, double ticfrac, int spriteshade) + void RenderPlayerSprite::Render(DPSprite *pspr, AActor *owner, float bobx, float boby, double wx, double wy, double ticfrac, int spriteshade, FDynamicColormap *basecolormap) { double tx; int x1; diff --git a/src/swrenderer/things/r_playersprite.h b/src/swrenderer/things/r_playersprite.h index 6030c2ad3..b1eebe431 100644 --- a/src/swrenderer/things/r_playersprite.h +++ b/src/swrenderer/things/r_playersprite.h @@ -28,7 +28,7 @@ namespace swrenderer static void RenderRemainingPlayerSprites(); private: - static void Render(DPSprite *pspr, AActor *owner, float bobx, float boby, double wx, double wy, double ticfrac, int spriteshade); + static void Render(DPSprite *pspr, AActor *owner, float bobx, float boby, double wx, double wy, double ticfrac, int spriteshade, FDynamicColormap *basecolormap); enum { BASEXCENTER = 160 }; enum { BASEYCENTER = 100 }; diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index 75033349c..57e6d46d1 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -60,7 +60,7 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) namespace swrenderer { - void RenderSprite::Project(AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy) + void RenderSprite::Project(AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap) { // transform the origin point double tr_x = pos.X - ViewPos.X; @@ -295,7 +295,9 @@ namespace swrenderer fixed_t centeryfrac = FLOAT2FIXED(CenterY); R_SetColorMapLight(vis->Style.BaseColormap, 0, vis->Style.ColormapNum << FRACBITS); - bool visible = R_SetPatchStyle(vis->Style.RenderStyle, vis->Style.Alpha, vis->Translation, vis->FillColor); + FDynamicColormap *basecolormap = static_cast(vis->Style.BaseColormap); + + bool visible = R_SetPatchStyle(vis->Style.RenderStyle, vis->Style.Alpha, vis->Translation, vis->FillColor, basecolormap); if (vis->Style.RenderStyle == LegacyRenderStyles[STYLE_Shaded]) { // For shaded sprites, R_SetPatchStyle sets a dc_colormap to an alpha table, but @@ -343,8 +345,6 @@ namespace swrenderer } } - R_FinishSetPatchStyle(); - NetUpdate(); } } diff --git a/src/swrenderer/things/r_sprite.h b/src/swrenderer/things/r_sprite.h index c345d85f2..7c5a68a07 100644 --- a/src/swrenderer/things/r_sprite.h +++ b/src/swrenderer/things/r_sprite.h @@ -20,7 +20,7 @@ namespace swrenderer class RenderSprite { public: - static void Project(AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy); + static void Project(AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap); static void Render(vissprite_t *vis, const short *mfloorclip, const short *mceilingclip); }; } diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index 951948288..c7cdee660 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -46,7 +46,7 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) namespace swrenderer { - void RenderVoxel::Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy) + void RenderVoxel::Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap) { // transform the origin point double tr_x = pos.X - ViewPos.X; @@ -206,6 +206,7 @@ namespace swrenderer { mybasecolormap = GetSpecialLights(mybasecolormap->Color, mybasecolormap->Fade.InverseColor(), mybasecolormap->Desaturate); } + if (fixedlightlev >= 0) { vis->Style.BaseColormap = mybasecolormap; @@ -226,8 +227,11 @@ namespace swrenderer void RenderVoxel::Render(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom) { + FDynamicColormap *basecolormap = static_cast(sprite->Style.BaseColormap); + R_SetColorMapLight(sprite->Style.BaseColormap, 0, sprite->Style.ColormapNum << FRACBITS); - bool visible = R_SetPatchStyle(sprite->Style.RenderStyle, sprite->Style.Alpha, sprite->Translation, sprite->FillColor); + + bool visible = R_SetPatchStyle(sprite->Style.RenderStyle, sprite->Style.Alpha, sprite->Translation, sprite->FillColor, basecolormap); if (!visible) return; diff --git a/src/swrenderer/things/r_voxel.h b/src/swrenderer/things/r_voxel.h index 56180d758..3788d0b19 100644 --- a/src/swrenderer/things/r_voxel.h +++ b/src/swrenderer/things/r_voxel.h @@ -55,7 +55,7 @@ namespace swrenderer class RenderVoxel { public: - static void Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy); + static void Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap); static void Render(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom); static void Deinit(); diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index 4dd4823a3..06f1b0bed 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -62,7 +62,7 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor); namespace swrenderer { - void RenderWallSprite::Project(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, int renderflags, int spriteshade, bool foggy) + void RenderWallSprite::Project(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, int renderflags, int spriteshade, bool foggy, FDynamicColormap *basecolormap) { FWallCoords wallc; double x1, x2; @@ -165,7 +165,7 @@ namespace swrenderer } // Prepare lighting bool calclighting = false; - FDynamicColormap *usecolormap = basecolormap; + FSWColormap *usecolormap = spr->Style.BaseColormap; bool rereadcolormap = true; // Decals that are added to the scene must fade to black. @@ -206,12 +206,14 @@ namespace swrenderer int x = x1; - bool visible = R_SetPatchStyle(spr->Style.RenderStyle, spr->Style.Alpha, spr->Translation, spr->FillColor); + FDynamicColormap *basecolormap = static_cast(spr->Style.BaseColormap); + + bool visible = R_SetPatchStyle(spr->Style.RenderStyle, spr->Style.Alpha, spr->Translation, spr->FillColor, basecolormap); // R_SetPatchStyle can modify basecolormap. if (rereadcolormap) { - usecolormap = basecolormap; + usecolormap = spr->Style.BaseColormap; } if (!visible) @@ -232,7 +234,6 @@ namespace swrenderer x++; } } - R_FinishSetPatchStyle(); } void RenderWallSprite::DrawColumn(int x, FTexture *WallSpriteTile, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip) diff --git a/src/swrenderer/things/r_wallsprite.h b/src/swrenderer/things/r_wallsprite.h index 57a19a122..d478bf83f 100644 --- a/src/swrenderer/things/r_wallsprite.h +++ b/src/swrenderer/things/r_wallsprite.h @@ -20,7 +20,7 @@ namespace swrenderer class RenderWallSprite { public: - static void Project(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, int renderflags, int spriteshade, bool foggy); + static void Project(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, int renderflags, int spriteshade, bool foggy, FDynamicColormap *basecolormap); static void Render(vissprite_t *spr, const short *mfloorclip, const short *mceilingclip); private: diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 689546f8c..5a2a2485a 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -189,10 +189,11 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) fixedcolormap = dc_fcolormap; bool visible; + FDynamicColormap *basecolormap = nullptr; if (r_swtruecolor) - visible = R_SetPatchStyle(parms.style, parms.Alpha, -1, parms.fillcolor); + visible = R_SetPatchStyle(parms.style, parms.Alpha, -1, parms.fillcolor, basecolormap); else - visible = R_SetPatchStyle(parms.style, parms.Alpha, 0, parms.fillcolor); + visible = R_SetPatchStyle(parms.style, parms.Alpha, 0, parms.fillcolor, basecolormap); BYTE *destorgsave = dc_destorg; int destheightsave = dc_destheight; @@ -287,7 +288,6 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) CenterY = centeryback; } - R_FinishSetPatchStyle (); dc_destorg = destorgsave; dc_destheight = destheightsave;