From 5ac6bcb9024de4103a8609762a3fb6a2799eac20 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 15 Feb 2022 22:13:11 +0100 Subject: [PATCH] Added opacity support to the scanline shader. --- es-core/src/components/VideoComponent.cpp | 6 +----- .../src/components/VideoFFmpegComponent.cpp | 7 ++++++- es-core/src/renderers/Renderer_GL21.cpp | 4 ++-- resources/shaders/glsl/scanlines.glsl | 19 +++++++++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index dbf8e42b6..13fa9e0b8 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -311,12 +311,8 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("pillarboxes")) mDrawPillarboxes = elem->get("pillarboxes"); - // Scanlines are not compatible with video transparency. - if (elem->has("scanlines")) { + if (elem->has("scanlines")) mRenderScanlines = elem->get("scanlines"); - if (mRenderScanlines && mThemeOpacity != 0.0f) - mThemeOpacity = 1.0f; - } if (elem->has("scrollFadeIn") && elem->get("scrollFadeIn")) mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN; diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 825c042d8..aba309809 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -216,9 +216,14 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans) // or the video screensaver, then skip this as the scanline rendering is then handled // in those modules as a postprocessing step. if (!mScreensaverMode && !mMediaViewerMode) { + vertices[0].opacity = mFadeIn * mThemeOpacity; if ((mLegacyTheme && Settings::getInstance()->getBool("GamelistVideoScanlines")) || - (!mLegacyTheme && mRenderScanlines)) + (!mLegacyTheme && mRenderScanlines)) { vertices[0].shaders = Renderer::SHADER_SCANLINES; + } + else { + vertices[0].shaders = Renderer::SHADER_OPACITY; + } } #endif diff --git a/es-core/src/renderers/Renderer_GL21.cpp b/es-core/src/renderers/Renderer_GL21.cpp index 199edb421..baced99e9 100644 --- a/es-core/src/renderers/Renderer_GL21.cpp +++ b/es-core/src/renderers/Renderer_GL21.cpp @@ -352,6 +352,7 @@ namespace Renderer if (runShader) { runShader->activateShaders(); runShader->setModelViewProjectionMatrix(getProjectionMatrix() * trans); + runShader->setOpacity(vertices->opacity); runShader->setTextureSize({shaderWidth, shaderHeight}); GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices)); runShader->deactivateShaders(); @@ -363,8 +364,7 @@ namespace Renderer if (runShader) { runShader->activateShaders(); runShader->setModelViewProjectionMatrix(getProjectionMatrix() * trans); - if (vertices->opacity < 1.0f) - runShader->setOpacity(vertices->opacity); + runShader->setOpacity(vertices->opacity); GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices)); runShader->deactivateShaders(); } diff --git a/resources/shaders/glsl/scanlines.glsl b/resources/shaders/glsl/scanlines.glsl index 3d92c4e58..91d56ea0f 100644 --- a/resources/shaders/glsl/scanlines.glsl +++ b/resources/shaders/glsl/scanlines.glsl @@ -93,6 +93,7 @@ uniform COMPAT_PRECISION int FrameCount; uniform COMPAT_PRECISION vec2 OutputSize; uniform COMPAT_PRECISION vec2 TextureSize; uniform COMPAT_PRECISION vec2 InputSize; +uniform COMPAT_PRECISION float opacity = 1.0; uniform sampler2D Texture; COMPAT_VARYING vec4 TEX0; COMPAT_VARYING vec2 onex; @@ -126,10 +127,11 @@ uniform COMPAT_PRECISION float OutputGamma; #define TEX2D(coords) GAMMA_IN(COMPAT_TEXTURE(Source, coords)) // Macro for weights computing. -#define WEIGHT(w) \ -if (w > 1.0) w = 1.0; \ -w = 1.0 - w * w; \ -w = w * w; +#define WEIGHT(w) \ + if (w > 1.0) \ + w = 1.0; \ + w = 1.0 - w * w; \ + w = w * w; void main() { @@ -143,7 +145,7 @@ void main() float h_weight_00 = dx / SPOT_WIDTH; WEIGHT(h_weight_00); - color *= vec4( h_weight_00, h_weight_00, h_weight_00, h_weight_00 ); + color *= vec4(h_weight_00, h_weight_00, h_weight_00, h_weight_00); // Get closest horizontal neighbour to blend. vec2 coords01; @@ -184,12 +186,13 @@ void main() WEIGHT(v_weight_10); color = color + colorNB * vec4(v_weight_10 * h_weight_00, v_weight_10 * h_weight_00, - v_weight_10 * h_weight_00, v_weight_10 * h_weight_00); + v_weight_10 * h_weight_00, v_weight_10 * h_weight_00); colorNB = TEX2D(texture_coords + coords01 + coords10); color = color + colorNB * vec4(v_weight_10 * h_weight_01, v_weight_10 * h_weight_01, - v_weight_10 * h_weight_01, v_weight_10 * h_weight_01); + v_weight_10 * h_weight_01, v_weight_10 * h_weight_01); color *= vec4(COLOR_BOOST); - FragColor = clamp(GAMMA_OUT(color), 0.0, 1.0); + vec4 colorTemp = clamp(GAMMA_OUT(color), 0.0, 1.0); + FragColor = vec4(colorTemp.rgb, colorTemp.a * opacity); } #endif