diff --git a/effects/backgroundcontrast/contrast.cpp b/effects/backgroundcontrast/contrast.cpp index dbd9933fce..96ba3706a1 100644 --- a/effects/backgroundcontrast/contrast.cpp +++ b/effects/backgroundcontrast/contrast.cpp @@ -384,6 +384,8 @@ void ContrastEffect::doContrast(const QRegion& shape, const QRect& screen, const shader->bind(); + + shader->setOpacity(opacity); // Set up the texture matrix to transform from screen coordinates // to texture coordinates. #ifdef KWIN_HAVE_OPENGL_1 diff --git a/effects/backgroundcontrast/contrastshader.cpp b/effects/backgroundcontrast/contrastshader.cpp index f814283fe8..472ca37c65 100644 --- a/effects/backgroundcontrast/contrastshader.cpp +++ b/effects/backgroundcontrast/contrastshader.cpp @@ -35,7 +35,7 @@ using namespace KWin; ContrastShader::ContrastShader() - : mValid(false), shader(NULL) + : mValid(false), shader(NULL), m_opacity(1) { } @@ -93,6 +93,20 @@ bool ContrastShader::supported() return true; } +void ContrastShader::setOpacity(float opacity) +{ + m_opacity = opacity; + + ShaderManager::instance()->pushShader(shader); + shader->setUniform(opacityLocation, opacity); + ShaderManager::instance()->popShader(); +} + +float ContrastShader::opacity() const +{ + return m_opacity; +} + void ContrastShader::setColorMatrix(const QMatrix4x4 &matrix) { if (!isValid()) @@ -181,6 +195,7 @@ void ContrastShader::init() stream2 << "uniform mat4 colorMatrix;\n"; stream2 << "uniform sampler2D sampler;\n"; + stream2 << "uniform float opacity;\n"; stream2 << "in vec4 varyingTexCoords;\n"; if (glsl_140) @@ -189,8 +204,16 @@ void ContrastShader::init() stream2 << "void main(void)\n"; stream2 << "{\n"; stream2 << " vec4 tex = " << texture2D << "(sampler, varyingTexCoords.st);\n"; + stream2 << " mat4 identity = mat4(1.0, 0.0, 0.0, 0.0,\n"; + stream2 << " 0.0, 1.0, 0.0, 0.0,\n"; + stream2 << " 0.0, 0.0, 1.0, 0.0,\n"; + stream2 << " 0.0, 0.0, 0.0, 1.0);\n"; - stream2 << " " << fragColor << " = tex * colorMatrix;\n"; + stream2 << " if (opacity >= 1.0) {\n"; + stream2 << " " << fragColor << " = tex * colorMatrix;\n"; + stream2 << " } else {\n"; + stream2 << " " << fragColor << " = tex * (opacity * colorMatrix + (1-opacity) * identity);\n"; + stream2 << " }\n"; stream2 << "}\n"; stream2.flush(); @@ -201,6 +224,7 @@ void ContrastShader::init() colorMatrixLocation = shader->uniformLocation("colorMatrix"); textureMatrixLocation = shader->uniformLocation("textureMatrix"); mvpMatrixLocation = shader->uniformLocation("modelViewProjectionMatrix"); + opacityLocation = shader->uniformLocation("opacity"); QMatrix4x4 modelViewProjection; modelViewProjection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535); @@ -208,6 +232,7 @@ void ContrastShader::init() shader->setUniform(colorMatrixLocation, QMatrix4x4()); shader->setUniform(textureMatrixLocation, QMatrix4x4()); shader->setUniform(mvpMatrixLocation, modelViewProjection); + shader->setUniform(opacityLocation, (float)1.0); ShaderManager::instance()->popShader(); } diff --git a/effects/backgroundcontrast/contrastshader.h b/effects/backgroundcontrast/contrastshader.h index cf8de81bf5..c36baed227 100644 --- a/effects/backgroundcontrast/contrastshader.h +++ b/effects/backgroundcontrast/contrastshader.h @@ -52,6 +52,9 @@ public: static bool supported(); + void setOpacity(float opacity); + float opacity() const; + protected: void setIsValid(bool value) { mValid = value; @@ -65,6 +68,8 @@ private: int textureMatrixLocation; int colorMatrixLocation; int pixelSizeLocation; + int opacityLocation; + float m_opacity; };