From 5f727f8c00c5a0ad6c656709eb4ceedfa80d868e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 18 Mar 2021 19:52:48 +0100 Subject: [PATCH] Improved the scaling of the scanline shader in relation to screen resolution. --- es-core/src/renderers/Renderer_GL21.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/es-core/src/renderers/Renderer_GL21.cpp b/es-core/src/renderers/Renderer_GL21.cpp index 60956ad19..2aab81706 100644 --- a/es-core/src/renderers/Renderer_GL21.cpp +++ b/es-core/src/renderers/Renderer_GL21.cpp @@ -323,9 +323,25 @@ namespace Renderer if (_vertices->shaders & SHADER_SCANLINES) { Shader* runShader = getShaderProgram(SHADER_SCANLINES); float shaderWidth = width * 1.2f; - // Workaround to get the scanlines to render somehow proportional to the - // resolution. A better solution is for sure needed. - float shaderHeight = height + height / (static_cast(height) >> 7) * 2.0f; + // Scale the scanlines relative to screen resolution. + float screenHeightModifier = getScreenHeightModifier(); + float relativeHeight = height / getScreenHeight(); + float shaderHeight = 0.0f; + if (relativeHeight == 1.0f) { + // Full screen. + float modifier = 1.30f - (0.1f * screenHeightModifier); + shaderHeight = height * modifier; + } + else { + // Portion of screen, e.g. gamelist view. + // Average the relative width and height to avoid applying exaggerated + // scanlines to videos with non-standard aspect ratios. + float relativeWidth = width / getScreenWidth(); + float relativeAdjustment = (relativeWidth + relativeHeight) / 2.0f; + float modifier = 1.41f + relativeAdjustment / 7.0f - + (0.14f * screenHeightModifier); + shaderHeight = height * modifier; + } if (runShader) { runShader->activateShaders(); runShader->setModelViewProjectionMatrix(getProjectionMatrix() * _trans);