From ab36b86a597e653c965b9d4b56c532ecad156dd7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 3 Apr 2021 21:06:02 +0200 Subject: [PATCH] - sky tweaking * Build skies need a different mesh for the dome - the one from GZDoom distorts them too much. * made adjustment to the positioning math after redoing the mesh * Exhumed abuses some strange effect of the original sky placement math which means the y-offsetting must be disabled for this game. * RRRA sky initialization fixed. It must be done after setting up the tiles. --- .../rendering/hwrenderer/data/hw_skydome.cpp | 30 +++++++++++++++++-- source/core/rendering/scene/hw_sky.cpp | 9 ++++-- source/core/rendering/scene/hw_skyportal.cpp | 20 +++++++------ source/core/version.h | 1 + source/games/duke/src/game.cpp | 2 +- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/source/common/rendering/hwrenderer/data/hw_skydome.cpp b/source/common/rendering/hwrenderer/data/hw_skydome.cpp index c4a831f5a..340957a3e 100644 --- a/source/common/rendering/hwrenderer/data/hw_skydome.cpp +++ b/source/common/rendering/hwrenderer/data/hw_skydome.cpp @@ -62,6 +62,7 @@ #include "hw_renderstate.h" #include "v_video.h" #include "hwrenderer/data/buffers.h" +#include "version.h" //----------------------------------------------------------------------------- // @@ -139,10 +140,10 @@ FSkyVertexBuffer::~FSkyVertexBuffer() //----------------------------------------------------------------------------- // -// +// todo: make both available at the same time. // //----------------------------------------------------------------------------- - +#ifndef BUILD_SKY void FSkyVertexBuffer::SkyVertex(int r, int c, bool zflip) { static const FAngle maxSideAngle = 60.f; @@ -179,8 +180,33 @@ void FSkyVertexBuffer::SkyVertex(int r, int c, bool zflip) mVertices.Push(vert); } +#else +void FSkyVertexBuffer::SkyVertex(int r, int c, bool zflip) +{ + static const FAngle maxSideAngle = 60.f; + static const float scale = 10000.; + FAngle topAngle = (c / (float)mColumns * 360.f); + FVector2 pos = topAngle.ToVector(scale); + float z = (!zflip) ? (mRows - r) * 4000.f : -(mRows - r) * 4000.f; + FSkyVertex vert; + + vert.color = r == 0 ? 0xffffff : 0xffffffff; + + // And the texture coordinates. + if (zflip) r = mRows * 2 - r; + vert.u = 0.5 + (-c / (float)mColumns); + vert.v = (r / (float)(2*mRows)); + + // And finally the vertex. + vert.x = pos.X; + vert.y = z - 1.f; + vert.z = pos.Y; + + mVertices.Push(vert); +} +#endif //----------------------------------------------------------------------------- // // diff --git a/source/core/rendering/scene/hw_sky.cpp b/source/core/rendering/scene/hw_sky.cpp index 30cc3f3b3..913338a2c 100644 --- a/source/core/rendering/scene/hw_sky.cpp +++ b/source/core/rendering/scene/hw_sky.cpp @@ -53,16 +53,21 @@ void initSkyInfo(HWDrawInfo *di, HWSkyInfo* sky, sectortype* sector, int plane, int remap = TRANSLATION(Translation_Remap + curbasepal, palette); int16_t const* dapskyoff = getpsky(picnum, &dapyscale, &dapskybits, &dapyoffs, &daptileyscale); + int tw = tileWidth(picnum); + if ((1 << sizeToBits(tw)) < tw) dapskybits--; // Build math is weird. + skytex = GetSkyTexture(picnum, dapskybits, dapskyoff, remap); realskybits = dapskybits; if (skytex) dapskybits = 0; else skytex = tileGetTexture(picnum); } + float xpanning = plane == plane_ceiling ? sector->ceilingxpan_ : sector->floorxpan_; + // dapyscale is not relvant for a sky dome. sky->y_scale = FixedToFloat(daptileyscale); - sky->y_offset = dapyoffs*2; - sky->x_offset = 0;// xpanning / (1 << (realskybits - dapskybits)); + sky->y_offset = dapyoffs*1.5; + sky->x_offset = xpanning / (1 << (realskybits - dapskybits)); sky->fadecolor = FadeColor; sky->shade = 0;// clamp(plane == plane_ceiling ? sector->ceilingshade : sector->floorshade, 0, numshades - 1); sky->texture = skytex; diff --git a/source/core/rendering/scene/hw_skyportal.cpp b/source/core/rendering/scene/hw_skyportal.cpp index b7bb106a6..4c12754e5 100644 --- a/source/core/rendering/scene/hw_skyportal.cpp +++ b/source/core/rendering/scene/hw_skyportal.cpp @@ -65,22 +65,24 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) float texh = tex->GetDisplayHeight(); auto& modelMatrix = state.mModelMatrix; auto& textureMatrix = state.mTextureMatrix; - auto texskyoffset = tex->GetSkyOffset() + origin->y_offset + skyoffsettest; + auto texskyoffset = tex->GetSkyOffset() + skyoffsettest; + if (!(g_gameType & GAMEFLAG_PSEXHUMED)) texskyoffset += origin->y_offset; - int repeat_fac = 1; - if (texh <= 192) + float repeat_fac = 1; + if (texh <= 256) { - repeat_fac = 384 / texh; - texh *= repeat_fac; + repeat_fac = 336.f / texh; + texh = 336; } modelMatrix.loadIdentity(); modelMatrix.rotate(-180.0f + origin->x_offset, 0.f, 1.f, 0.f); - modelMatrix.translate(0.f, -40 + texskyoffset + (texh - 300) / 2 * skyoffsetfactor, 0.f); - //modelMatrix.scale(1.f, 0.8f * 1.17f, 1.f); + modelMatrix.translate(0.f, -40 + texskyoffset * skyoffsetfactor, 0.f); + modelMatrix.scale(1.f, texh / 400.f, 1.f); textureMatrix.loadIdentity(); - textureMatrix.scale(-1.f, 0.5*repeat_fac, 1.f); - textureMatrix.translate(1.f, 0/*origin->y_offset / texh*/, 1.f); + state.EnableTextureMatrix(true); + textureMatrix.scale(1.f, repeat_fac, 1.f); vertexBuffer->RenderDome(state, origin->texture, FSkyVertexBuffer::SKYMODE_MAINLAYER); + state.EnableTextureMatrix(false); } state.SetTextureMode(TM_NORMAL); if (origin->fadecolor & 0xffffff) diff --git a/source/core/version.h b/source/core/version.h index c8a5949a0..e11683536 100644 --- a/source/core/version.h +++ b/source/core/version.h @@ -92,5 +92,6 @@ const int SAVEPICHEIGHT = 180; const int VID_MIN_WIDTH = 640; const int VID_MIN_HEIGHT = 400; #define NPOT_EMULATION +#define BUILD_SKY #endif //__VERSION_H__ diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 8b284df75..181997346 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -313,10 +313,10 @@ void GameInterface::app_init() if (engineInit()) G_FatalEngineError(); - setupbackdrop(); //Net_SendClientInfo(); initTiles(); + setupbackdrop(); genspriteremaps(); SetupGameButtons(); InitCheats();