From 23bbc75b126c5e687d8aa92717e54eca29cec9e5 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 28 Aug 2023 19:31:40 +0200 Subject: [PATCH] plugins/{blur,contrast}: Take into account window opacity Fixes excessive blur/contrast behind a semi-transparent window. --- src/plugins/backgroundcontrast/contrast.cpp | 2 +- src/plugins/blur/blur.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/backgroundcontrast/contrast.cpp b/src/plugins/backgroundcontrast/contrast.cpp index 87576a01ff..8f704f265f 100644 --- a/src/plugins/backgroundcontrast/contrast.cpp +++ b/src/plugins/backgroundcontrast/contrast.cpp @@ -417,7 +417,7 @@ void ContrastEffect::drawWindow(const RenderTarget &renderTarget, const RenderVi } if (!shape.isEmpty()) { - doContrast(renderTarget, viewport, w, shape, screen, data.opacity(), data.projectionMatrix()); + doContrast(renderTarget, viewport, w, shape, screen, w->opacity() * data.opacity(), data.projectionMatrix()); } } diff --git a/src/plugins/blur/blur.cpp b/src/plugins/blur/blur.cpp index fa124cd6d5..d673b3bef9 100644 --- a/src/plugins/blur/blur.cpp +++ b/src/plugins/blur/blur.cpp @@ -564,6 +564,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi const QRect backgroundRect = blurShape.boundingRect(); const QRect deviceBackgroundRect = scaledRect(backgroundRect, viewport.scale()).toRect(); + const auto opacity = w->opacity() * data.opacity(); if (renderInfo.framebuffers.size() != (m_iterationCount + 1) || renderInfo.textures[0]->size() != backgroundRect.size() || renderInfo.textures[0]->internalFormat() != textureFormat) { renderInfo.framebuffers.clear(); @@ -765,9 +766,9 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi read->colorAttachment()->bind(); // Modulate the blurred texture with the window opacity if the window isn't opaque - if (data.opacity() < 1.0) { + if (opacity < 1.0) { glEnable(GL_BLEND); - float o = 1.0f - data.opacity(); + float o = 1.0f - (opacity); o = 1.0f - o * o; glBlendColor(0, 0, 0, o); glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); @@ -775,7 +776,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi vbo->draw(GL_TRIANGLES, 6, vertexCount); - if (data.opacity() < 1.0) { + if (opacity < 1.0) { glDisable(GL_BLEND); } @@ -787,7 +788,7 @@ void BlurEffect::blur(const RenderTarget &renderTarget, const RenderViewport &vi // artifacts, which often happens due to the smooth color transitions in the blurred image. glEnable(GL_BLEND); - if (data.opacity() < 1.0) { + if (opacity < 1.0) { glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE); } else { glBlendFunc(GL_ONE, GL_ONE);