From 628bf497dd42d031b387f1933ea3477cd324263e Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 8 Dec 2013 11:52:20 +0100 Subject: [PATCH] Hopefully fix UV scaling properly this time. Check the faces in Hexyz Force please. --- GPU/GLES/ShaderManager.cpp | 18 ++++++------------ GPU/GLES/VertexShaderGenerator.cpp | 11 +++++++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/GPU/GLES/ShaderManager.cpp b/GPU/GLES/ShaderManager.cpp index dab6c12152..348c578f53 100644 --- a/GPU/GLES/ShaderManager.cpp +++ b/GPU/GLES/ShaderManager.cpp @@ -433,18 +433,12 @@ void LinkedShader::UpdateUniforms(u32 vertType) { // These two work the same whether or not we prescale UV. case GE_TEXMAP_TEXTURE_MATRIX: - // UV coords (that need "factor") are only used here if the getUVProjMode == 1. - // Otherwise we just use it to scale the coordinates to the texture. - // Factor is used even if prescale is enabled, because prescale doesn't apply if the mode - // is texture_matrix. - if (gstate.getUVProjMode() == GE_PROJMAP_UV) { - uvscaleoff[0] = widthFactor * factor; - uvscaleoff[1] = heightFactor * factor; - } else { - // In these other modes we only use uvscaleoff to scale to the texture size. - uvscaleoff[0] = widthFactor; - uvscaleoff[1] = heightFactor; - } + // We cannot bake the UV coord scale factor in here, as we apply a matrix multiplication + // before this is applied, and the matrix multiplication may contain translation. In this case + // the translation will be scaled which breaks faces in Hexyz Force for example. + // So I've gone back to applying the scale factor in the shader. + uvscaleoff[0] = widthFactor; + uvscaleoff[1] = heightFactor; uvscaleoff[2] = 0.0f; uvscaleoff[3] = 0.0f; break; diff --git a/GPU/GLES/VertexShaderGenerator.cpp b/GPU/GLES/VertexShaderGenerator.cpp index 0463fa754a..515a11f154 100644 --- a/GPU/GLES/VertexShaderGenerator.cpp +++ b/GPU/GLES/VertexShaderGenerator.cpp @@ -110,6 +110,9 @@ void ComputeVertexShaderID(VertexShaderID *id, u32 vertType, int prim, bool useH id->d[1] |= gstate.isLightingEnabled() << 24; id->d[1] |= (vertTypeGetWeightMask(vertType) >> GE_VTYPE_WEIGHT_SHIFT) << 25; id->d[1] |= gstate.areNormalsReversed() << 26; + if (doTextureProjection && gstate.getUVProjMode() == GE_PROJMAP_UV) { + id->d[1] |= ((vertType & GE_VTYPE_TC_MASK) >> GE_VTYPE_TC_SHIFT) << 27; // two bits + } } } @@ -553,10 +556,10 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf break; case GE_PROJMAP_UV: // Use unscaled UV as source { - // As we rescale the texcoord to compensate for texture size anyway, - // we bake the UV format scale factor into u_uvscaleoffset. So no need to apply - // the factor here too. - temp_tc = "vec4(texcoord.xy, 0.0, 1.0)"; + // prescale is false here. + static const char *rescaleuv[4] = {"", " * 1.9921875", " * 1.999969482421875", ""}; // 2*127.5f/128.f, 2*32767.5f/32768.f, 1.0f}; + const char *factor = rescaleuv[(vertType & GE_VTYPE_TC_MASK) >> GE_VTYPE_TC_SHIFT]; + temp_tc = StringFromFormat("vec4(texcoord.xy %s, 0.0, 1.0)", factor); } break; case GE_PROJMAP_NORMALIZED_NORMAL: // Use normalized transformed normal as source