Added opacity support to the scanline shader.

This commit is contained in:
Leon Styhre 2022-02-15 22:13:11 +01:00
parent a9d1f6e307
commit 5ac6bcb902
4 changed files with 20 additions and 16 deletions

View file

@ -311,12 +311,8 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("pillarboxes"))
mDrawPillarboxes = elem->get<bool>("pillarboxes");
// Scanlines are not compatible with video transparency.
if (elem->has("scanlines")) {
if (elem->has("scanlines"))
mRenderScanlines = elem->get<bool>("scanlines");
if (mRenderScanlines && mThemeOpacity != 0.0f)
mThemeOpacity = 1.0f;
}
if (elem->has("scrollFadeIn") && elem->get<bool>("scrollFadeIn"))
mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN;

View file

@ -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

View file

@ -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();
}

View file

@ -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