From 8e961b7b3969c5b1bb7ae13019adc3e9d7587962 Mon Sep 17 00:00:00 2001 From: s2s <12202580+standard-two-simplex@users.noreply.github.com> Date: Sat, 6 Nov 2021 10:43:14 +0100 Subject: [PATCH] Fix scale for mip-map tiles. Note: it is incomplete solution for problems with mip-mapping. Fixes Paper Mario Snow #2570 --- .../GLSL/glsl_CombinerProgramBuilderAccurate.cpp | 6 +++++- src/Textures.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilderAccurate.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilderAccurate.cpp index 6514520f..c6bd28a0 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilderAccurate.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilderAccurate.cpp @@ -751,13 +751,17 @@ public: " lowp vec4 c11 = texelFetch(tex, ivec2(tcData[3]), 0); \\\n" ; static const std::string strReadTex1 = + "#define GET_HIGH4(byte) floor(byte/16.0) \n" + "#define GET_LOW4(byte) (byte - 16.0*floor(byte/16.0)) \n" "#define READ_TEX1_MIPMAP(name, tex, tcData, tile) \\\n" "{ \\\n" // Fetch from texture atlas // First 8 texels contain info about tile size and offset, 1 texel per tile " mediump vec4 texWdthAndOff0 = 255.0 * texelFetch(tex, ivec2(0, 0), 0); \\\n" " mediump vec4 texWdthAndOff = 255.0 * texelFetch(tex, ivec2(int(tile), 0), 0); \\\n" - " mediump vec2 lod_scale = texWdthAndOff.ba / texWdthAndOff0.ba; \\\n" + " mediump float lod_scales = pow(2.0, GET_HIGH4(texWdthAndOff0.a) - GET_HIGH4(texWdthAndOff.a)); \\\n" + " mediump float lod_scalet = pow(2.0, GET_LOW4(texWdthAndOff0.a) - GET_LOW4(texWdthAndOff.a)); \\\n" + " mediump vec2 lod_scale = vec2(lod_scales, lod_scalet); \\\n" " mediump int offset = int(texWdthAndOff.r) + int(texWdthAndOff.g) * 256; \\\n" " mediump int width = int(texWdthAndOff.b); \\\n" " mediump ivec2 iCoords00 = ivec2(tcData[0] * lod_scale); \\\n" diff --git a/src/Textures.cpp b/src/Textures.cpp index be15631c..3fbf362d 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -1411,7 +1411,12 @@ void TextureCache::_loadAccurate(u32 _tile, CachedTexture *_pTexture) // Load all tiles into one 1D texture atlas. while (true) { - const u32 tileSizePacked = texDataOffset | (tmptex.width << 16) | (tmptex.height << 24); + + u32 mipRatioS = gDP.tiles[gSP.texture.tile + mipLevel + 1].shifts + 5u; + if (mipRatioS >= 16u) mipRatioS -= 16u; + u32 mipRatioT = gDP.tiles[gSP.texture.tile + mipLevel + 1].shiftt + 5u; + if (mipRatioT >= 16) mipRatioT -= 16u; + const u32 tileSizePacked = texDataOffset | (tmptex.width << 16) | (mipRatioT << 24) | (mipRatioS << 28); m_tempTextureHolder[mipLevel] = tileSizePacked; getLoadParams(tmptex.format, tmptex.size);