From 5d458e1ef23274921295bfbc20bebf439643d1a2 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 2 Nov 2015 11:36:54 +0100 Subject: Use fallback blur shader for radius * 2 + 1 != sampleCount. The faster code path looks a lot worse in this case, so fall back to use the generic arbitrary large blur size for this case. Change-Id: I3984b3bf48732a83dd112b7beb0fb4c3f8d38568 Reviewed-by: Mitch Curtis --- src/effects/GaussianBlur.qml | 21 +++++++++------------ src/effects/private/DropShadowBase.qml | 2 +- src/effects/private/qgfxshaderbuilder.cpp | 7 ++++--- 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/effects/GaussianBlur.qml b/src/effects/GaussianBlur.qml index 82bc290..70943a0 100644 --- a/src/effects/GaussianBlur.qml +++ b/src/effects/GaussianBlur.qml @@ -253,9 +253,9 @@ Item { // private members... /*! \internal */ - property int _paddedTexWidth: transparentBorder ? width + 2 * _kernelRadius: width; + property int _paddedTexWidth: transparentBorder ? width + 2 * radius: width; /*! \internal */ - property int _paddedTexHeight: transparentBorder ? height + 2 * _kernelRadius: height; + property int _paddedTexHeight: transparentBorder ? height + 2 * radius: height; /*! \internal */ property int _kernelRadius: Math.max(0, samples / 2); /*! \internal */ @@ -285,14 +285,13 @@ Item { /*! \internal */ function _rebuildShaders() { - if (samples < 1) - return; - var params = { radius: _kernelRadius, - deviation: deviation, + // Limit deviation to something very small avoid getting NaN in the shader. + deviation: Math.max(0.00001, deviation), alphaOnly: root._alphaOnly, - masked: _maskSource != undefined + masked: _maskSource != undefined, + fallback: root.radius != _kernelRadius } var shaders = ShaderBuilder.gaussianBlur(params); horizontalBlur.fragmentShader = shaders.fragmentShader; @@ -304,7 +303,7 @@ Item { interpolation: SourceProxy.LinearInterpolation input: root.source sourceRect: root.transparentBorder - ? Qt.rect(-root._kernelRadius, 0, root._paddedTexWidth, parent.height) + ? Qt.rect(-root.radius, 0, root._paddedTexWidth, parent.height) : Qt.rect(0, 0, 0, 0) } @@ -320,7 +319,6 @@ Item { // Used by fallback shader (sampleCount exceeds number of varyings) property real deviation: root.deviation - property real radius: root._kernelRadius // Only in use for DropShadow and Glow property color color: "white" @@ -332,7 +330,7 @@ Item { layer.enabled: true layer.smooth: true layer.sourceRect: root.transparentBorder - ? Qt.rect(0, -root._kernelRadius, width, root._paddedTexHeight) + ? Qt.rect(0, -root.radius, width, root._paddedTexHeight) : Qt.rect(0, 0, 0, 0) visible: false blending: false @@ -340,7 +338,7 @@ Item { ShaderEffect { id: verticalBlur - x: transparentBorder ? -root._kernelRadius : 0 + x: transparentBorder ? -root.radius : 0 y: x; width: root.transparentBorder ? root._paddedTexWidth: root.width height: root.transparentBorder ? root._paddedTexHeight : root.height; @@ -352,7 +350,6 @@ Item { property var dirstep: Qt.vector2d(0, 1 / (root._paddedTexHeight * root._dpr)); property real deviation: horizontalBlur.deviation - property real radius: horizontalBlur.radius property color color: "black" property real thickness: horizontalBlur.thickness; diff --git a/src/effects/private/DropShadowBase.qml b/src/effects/private/DropShadowBase.qml index 21ef0ea..3660619 100644 --- a/src/effects/private/DropShadowBase.qml +++ b/src/effects/private/DropShadowBase.qml @@ -62,7 +62,7 @@ Item { x: Math.round(horizontalOffset) y: Math.round(verticalOffset) source: root.source - radius: Math.min(Math.floor(root.samples / 2), root.radius) + radius: root.radius samples: root.samples _thickness: root.spread transparentBorder: root.transparentBorder diff --git a/src/effects/private/qgfxshaderbuilder.cpp b/src/effects/private/qgfxshaderbuilder.cpp index 81a3c12..fe1d7fe 100644 --- a/src/effects/private/qgfxshaderbuilder.cpp +++ b/src/effects/private/qgfxshaderbuilder.cpp @@ -312,10 +312,11 @@ QVariantMap QGfxShaderBuilder::gaussianBlur(const QJSValue ¶meters) int requestedSamples = requestedRadius * 2 + 1; int samples = 1 + requestedSamples / 2; int radius = requestedSamples / 4; + bool fallback = parameters.property(QStringLiteral("fallback")).toBool(); QVariantMap result; - if (samples > m_maxBlurSamples || masked) { + if (samples > m_maxBlurSamples || masked || fallback) { QByteArray fragShader; if (masked) fragShader += "uniform mediump sampler2D mask;\n"; @@ -354,9 +355,9 @@ QVariantMap QGfxShaderBuilder::gaussianBlur(const QJSValue ¶meters) fragShader += ".a"; fragShader += ";\n"; } - fragShader += " const mediump float wSum = "; + fragShader += " const mediump float wSum = float("; fragShader += QByteArray::number(wSum); - fragShader += ";\n" + fragShader += ");\n" " gl_FragColor = "; if (alphaOnly) fragShader += "mix(vec4(0), color, clamp((result / wSum) / thickness, 0.0, 1.0)) * qt_Opacity;\n"; -- cgit v1.2.1