forked from gazebosim/gz-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metal] Add cross-platform gamma adjustment for texture rendered into…
… QML - Adapt the GammaAdjust element from QtGraphicalEffects to work with Metal - Add shaders from Qt - Create a Vulkan supported version of the fragment shader - Generate a shader pack using qsb - Refactor gamma adjustment QML - Move to own QML file and locate with ignition/gui/qml - Move shaders to a private subfolder - Update resources.qrc - Replace import QtGraphicalEffects 1.0 with import "qrc:/qml" Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com> Move header files with git mv (gazebosim#395) Signed-off-by: methylDragon <methylDragon@gmail.com> Create redirection aliases (gazebosim#395) Signed-off-by: methylDragon <methylDragon@gmail.com> Migrate sources in src, test, examples, and include (gazebosim#395) Signed-off-by: methylDragon <methylDragon@gmail.com> Migrate CMake files (gazebosim#395) Signed-off-by: methylDragon <methylDragon@gmail.com> Update name and logo on UI, examples and API docs (gazebosim#398) Signed-off-by: Louise Poubel <louise@openrobotics.org>
- Loading branch information
1 parent
9b65b81
commit d36a34a
Showing
9 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
include/gz/gui/qml/private/shaders/+glslcore/gammaadjust.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters