From 13e2b28f500f33f97aa710cea177f49049dc6684 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 23 Apr 2020 14:45:11 +1000 Subject: [PATCH] GPU/HW: Only apply vertex offset at 1x resolution scale --- src/core/gpu_hw_shadergen.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index ec57a6ccf..dd84faad1 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -399,9 +399,14 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured) ss << R"( { + // Offset the vertex position by 0.5 to ensure correct interpolation of texture coordinates + // at 1x resolution scale. This doesn't work at >1x, we adjust the texture coordinates before + // uploading there instead. + float vertex_offset = (RESOLUTION_SCALE == 1) ? 0.5 : 0.0; + // 0..+1023 -> -1..1 - float pos_x = ((float(a_pos.x) + 0.5) / 512.0) - 1.0; - float pos_y = ((float(a_pos.y) + 0.5) / -256.0) + 1.0; + float pos_x = ((float(a_pos.x) + vertex_offset) / 512.0) - 1.0; + float pos_y = ((float(a_pos.y) + vertex_offset) / -256.0) + 1.0; // OpenGL seems to be off by one pixel in the Y direction due to lower-left origin. #if API_OPENGL || API_OPENGL_ES