From 8d9d56c339c5ac0b9efdee583b684498e74e531b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 5 Oct 2021 13:57:31 +0200 Subject: [PATCH 1/4] - push sprite shadows a little back for distance sorting They always need to be behind sprites with the same distance. --- src/rendering/hwrenderer/scene/hw_sprites.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index c31ae60d05..d53e9ee1e4 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -976,6 +976,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t } depth = (float)((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin); + if (isSpriteShadow) depth += 1.f/65536.f; // always sort shadows behind the sprite. // light calculation From a8ea5bef00ba3a22c4f05fad1e583843b65c2722 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 6 Oct 2021 14:10:22 +0200 Subject: [PATCH 2/4] - removed unused static array. --- src/scripting/backend/codegen_doom.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripting/backend/codegen_doom.cpp b/src/scripting/backend/codegen_doom.cpp index e107563543..30385519ce 100644 --- a/src/scripting/backend/codegen_doom.cpp +++ b/src/scripting/backend/codegen_doom.cpp @@ -521,7 +521,6 @@ ExpEmit FxActionSpecialCall::Emit(VMFunctionBuilder *build) unsigned i = 0; // Call the BuiltinCallLineSpecial function to perform the desired special. - static uint8_t reginfo[] = { REGT_INT, REGT_POINTER, REGT_INT, REGT_INT, REGT_INT, REGT_INT, REGT_INT }; auto sym = FindBuiltinFunction(NAME_BuiltinCallLineSpecial); assert(sym); From 60bf096912952d00988eb825f7f84a33ad2519e4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 6 Oct 2021 20:30:29 +0200 Subject: [PATCH 3/4] - fixed palette initialization for single lump fonts (FON2 and BMF) The bad increment was due to the palette being a byte array in older versions. --- src/common/fonts/singlelumpfont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/fonts/singlelumpfont.cpp b/src/common/fonts/singlelumpfont.cpp index c4711d9022..7725cdb2df 100644 --- a/src/common/fonts/singlelumpfont.cpp +++ b/src/common/fonts/singlelumpfont.cpp @@ -527,7 +527,7 @@ void FSingleLumpFont::FixupPalette (uint8_t *identity, const PalEntry *palette, double minlum = 100000000.0; identity[0] = 0; - palette += 3; // Skip the transparent color + palette++; // Skip the transparent color for (int i = 1; i < ActiveColors; ++i, palette ++) { From 19aac25f1922f624f19cf0953e3a823a331ea679 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 7 Oct 2021 00:13:34 +0200 Subject: [PATCH 4/4] - fixed some imprecisions in font luminosity calculation. This was still going through the palette which could result in off-by-one errors. --- src/common/fonts/font.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 9663f4e1cb..6ddbe41d46 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -570,6 +570,32 @@ void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors) } } +//========================================================================== +// +// RecordLuminosity +// +// Records minimum and maximum luminosity of a texture. +// +//========================================================================== + +static void RecordLuminosity(FImageSource* pic, int* minlum, int* maxlum) +{ + auto bitmap = pic->GetCachedBitmap(nullptr, FImageSource::normal); + auto pixels = bitmap.GetPixels(); + auto size = pic->GetWidth() * pic->GetHeight(); + + for (int x = 0; x < size; x++) + { + int xx = x * 4; + if (pixels[xx + 3] > 0) + { + int lum = Luminance(pixels[xx + 2], pixels[xx + 1], pixels[xx]); + if (lum < *minlum) *minlum = lum; + if (lum > *maxlum) *maxlum = lum; + } + } +} + //========================================================================== // // RecordAllTextureColors @@ -969,27 +995,22 @@ int FFont::GetMaxAscender(const uint8_t* string) const void FFont::LoadTranslations() { unsigned int count = min(Chars.Size(), LastChar - FirstChar + 1); - uint32_t usedcolors[256] = {}; - TArray Luminosity; if (count == 0) return; + int minlum = 255, maxlum = 0; for (unsigned int i = 0; i < count; i++) { if (Chars[i].OriginalPic) { auto pic = Chars[i].OriginalPic->GetTexture()->GetImage(); - if (pic) RecordTextureColors(pic, usedcolors); + RecordLuminosity(pic, &minlum, &maxlum); } } - int minlum = 0, maxlum = 0; - GetLuminosity (usedcolors, Luminosity, &minlum, &maxlum); if (MinLum >= 0 && MinLum < minlum) minlum = MinLum; if (MaxLum > maxlum) maxlum = MaxLum; // Here we can set everything to a luminosity translation. - - // Create different translations for different color ranges Translations.Resize(NumTextColors); for (int i = 0; i < NumTextColors; i++) {