From eab675c0cb74a81066f77e42f5a12e55a851df40 Mon Sep 17 00:00:00 2001 From: Marisa the Magician Date: Tue, 22 Nov 2022 14:57:03 +0100 Subject: [PATCH] Make model stretch fix opt-in with a flag. --- src/r_data/models.cpp | 21 +++++++++++++++++++-- src/r_data/models.h | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index 41a6dba956..fd1fa27a09 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -135,8 +135,15 @@ void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteMod angle += actor->SpriteRotation.Degrees(); // consider the pixel stretching. For non-voxels this must be factored out here - float stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; - objectToWorldMatrix.scale(1, stretch, 1); + float stretch = 1.f; + + // [MK] distortions might happen depending on when the pixel stretch is compensated for + // so we make the "undistorted" behavior opt-in + if (smf->flags & MDL_CORRECTPIXELSTRETCH) + { + stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; + objectToWorldMatrix.scale(1, stretch, 1); + } // Applying model transformations: // 1) Applying actor angle, pitch and roll to the model @@ -173,6 +180,12 @@ void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteMod objectToWorldMatrix.rotate(smf->pitchoffset, 0, 0, 1); objectToWorldMatrix.rotate(-smf->rolloffset, 1, 0, 0); + if (!(smf->flags & MDL_CORRECTPIXELSTRETCH)) + { + stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; + objectToWorldMatrix.scale(1, stretch, 1); + } + float orientation = scaleFactorX * scaleFactorY * scaleFactorZ; renderer->BeginDrawModel(actor->RenderStyle, smf, objectToWorldMatrix, orientation < 0); @@ -846,6 +859,10 @@ static void ParseModelDefLump(int Lump) smf.rotationCenterY = 0.; smf.rotationCenterZ = 0.; } + else if (sc.Compare("correctpixelstretch")) + { + smf.flags |= MDL_CORRECTPIXELSTRETCH; + } else { sc.ScriptMessage("Unrecognized string \"%s\"", sc.String); diff --git a/src/r_data/models.h b/src/r_data/models.h index ca832a7ca6..d347c0ba6c 100644 --- a/src/r_data/models.h +++ b/src/r_data/models.h @@ -1,4 +1,4 @@ -// +// //--------------------------------------------------------------------------- // // Copyright(C) 2005-2016 Christoph Oelckers @@ -58,6 +58,7 @@ enum MDL_NOPERPIXELLIGHTING = 1024, // forces a model to not use per-pixel lighting. useful for voxel-converted-to-model objects. MDL_SCALEWEAPONFOV = 2048, // scale weapon view model with higher user FOVs MDL_MODELSAREATTACHMENTS = 4096, // any model index after 0 is treated as an attachment, and therefore will use the bone results of index 0 + MDL_CORRECTPIXELSTRETCH = 8192, // ensure model does not distort with pixel stretch when pitch/roll is applied }; FSpriteModelFrame * FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped);