diff --git a/include/gz/gui/qml/IgnGammaAdjust.qml b/include/gz/gui/qml/IgnGammaAdjust.qml new file mode 100644 index 000000000..07d3ba427 --- /dev/null +++ b/include/gz/gui/qml/IgnGammaAdjust.qml @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2020 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +/* + * IgnGammaAdjust.qml is based upon GammaAdjust.qml from the QtGraphicalEffects + * module in Qt 5.15.2 which has the license listed below. + * + * The +*/ + +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 + +Item { + id: rootItem + + property variant source + + property real gamma: 1.0 + + property bool cached: false + + // Replaces SourceProxy in the QtGraphicalEffects version + ShaderEffectSource { + id: sourceProxy + sourceItem: rootItem.source + visible: rootItem.visible + smooth: true + live: true + hideSource: visible + } + + // Output + ShaderEffectSource { + id: cacheItem + anchors.fill: parent + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + // Apply the gamma adjustment to the source proxy + ShaderEffect { + id: shaderItem + property variant source: sourceProxy + property real gamma: 1.0 / Math.max(rootItem.gamma, 0.0001) + + anchors.fill: parent + + fragmentShader: "qrc:qml/private/shaders/gammaadjust.frag" + } +} diff --git a/include/gz/gui/qml/private/gammaadjust.frag b/include/gz/gui/qml/private/gammaadjust.frag new file mode 100644 index 000000000..e85d4aa09 --- /dev/null +++ b/include/gz/gui/qml/private/gammaadjust.frag @@ -0,0 +1,19 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + mat4 qt_Matrix; + float qt_Opacity; + float gamma; +}; + +layout(binding = 1) uniform sampler2D source; + +void main() { + vec4 originalColor = texture(source, qt_TexCoord0); + originalColor.rgb = originalColor.rgb / max(1.0/256.0, originalColor.a); + vec3 adjustedColor = pow(originalColor.rgb, vec3(gamma)); + fragColor = vec4(adjustedColor * originalColor.a, originalColor.a) * qt_Opacity; +} diff --git a/include/gz/gui/qml/private/gammaadjust.frag.qsb b/include/gz/gui/qml/private/gammaadjust.frag.qsb new file mode 100644 index 000000000..8c7b8a2c6 Binary files /dev/null and b/include/gz/gui/qml/private/gammaadjust.frag.qsb differ diff --git a/include/gz/gui/qml/private/shaders/+glslcore/gammaadjust.frag b/include/gz/gui/qml/private/shaders/+glslcore/gammaadjust.frag new file mode 100644 index 000000000..7efdd89a7 --- /dev/null +++ b/include/gz/gui/qml/private/shaders/+glslcore/gammaadjust.frag @@ -0,0 +1,13 @@ +#version 150 core +in vec2 qt_TexCoord0; +uniform float qt_Opacity; +uniform sampler2D source; +uniform float gamma; +out vec4 fragColor; + +void main(void) { + vec4 originalColor = texture(source, qt_TexCoord0.st); + originalColor.rgb = originalColor.rgb / max(1.0/256.0, originalColor.a); + vec3 adjustedColor = pow(originalColor.rgb, vec3(gamma)); + fragColor = vec4(adjustedColor * originalColor.a, originalColor.a) * qt_Opacity; +} diff --git a/include/gz/gui/qml/private/shaders/+qsb/gammaadjust.frag b/include/gz/gui/qml/private/shaders/+qsb/gammaadjust.frag new file mode 100644 index 000000000..8c7b8a2c6 Binary files /dev/null and b/include/gz/gui/qml/private/shaders/+qsb/gammaadjust.frag differ diff --git a/include/gz/gui/qml/private/shaders/gammaadjust.frag b/include/gz/gui/qml/private/shaders/gammaadjust.frag new file mode 100644 index 000000000..f87492a5b --- /dev/null +++ b/include/gz/gui/qml/private/shaders/gammaadjust.frag @@ -0,0 +1,10 @@ +varying highp vec2 qt_TexCoord0; +uniform highp float qt_Opacity; +uniform lowp sampler2D source; +uniform highp float gamma; +void main(void) { + highp vec4 originalColor = texture2D(source, qt_TexCoord0.st); + originalColor.rgb = originalColor.rgb / max(1.0/256.0, originalColor.a); + highp vec3 adjustedColor = pow(originalColor.rgb, vec3(gamma)); + gl_FragColor = vec4(adjustedColor * originalColor.a, originalColor.a) * qt_Opacity; +} diff --git a/include/gz/gui/resources.qrc b/include/gz/gui/resources.qrc index d2db5833c..855bb07f1 100644 --- a/include/gz/gui/resources.qrc +++ b/include/gz/gui/resources.qrc @@ -24,6 +24,11 @@ qml/images/export_icon.png qml/images/search.svg + qml/IgnGammaAdjust.qml + qml/private/shaders/gammaadjust.frag + qml/private/shaders/+glslcore/gammaadjust.frag + qml/private/shaders/+qsb/gammaadjust.frag + qml/GzCard.qml qml/GzCardSettings.qml qml/GzHelpers.qml diff --git a/src/plugins/minimal_scene/MinimalScene.qml b/src/plugins/minimal_scene/MinimalScene.qml index 5969a31c6..15ea4a48d 100644 --- a/src/plugins/minimal_scene/MinimalScene.qml +++ b/src/plugins/minimal_scene/MinimalScene.qml @@ -19,6 +19,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 import RenderWindow 1.0 +import "qrc:/qml" Rectangle { Layout.minimumWidth: 200 @@ -57,7 +58,7 @@ Rectangle { /* * Gamma correction for sRGB output. Enabled when engine is set to ogre2 */ - GammaAdjust { + IgnGammaAdjust { anchors.fill: renderWindow source: renderWindow gamma: 2.4 diff --git a/src/plugins/scene3d/Scene3D.qml b/src/plugins/scene3d/Scene3D.qml index 817dc9413..2f18acdfb 100644 --- a/src/plugins/scene3d/Scene3D.qml +++ b/src/plugins/scene3d/Scene3D.qml @@ -19,6 +19,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 import RenderWindow 1.0 +import "qrc:/qml" Rectangle { Layout.minimumWidth: 200 @@ -57,7 +58,7 @@ Rectangle { /* * Gamma correction for sRGB output. Enabled when engine is set to ogre2 */ - GammaAdjust { + IgnGammaAdjust { anchors.fill: renderWindow source: renderWindow gamma: 2.4