diff options
author | Gareth Stockwell <gareth.stockwell@accenture.com> | 2011-12-14 15:00:36 +0000 |
---|---|---|
committer | Gareth Stockwell <ext-gareth.stockwell@nokia.com> | 2011-12-14 15:36:06 +0000 |
commit | 2e8f3ffb805f071107eb99949a6c21ce52ac40a0 (patch) | |
tree | 6e33873ae0d3b1dfef85c819a4f874c1b54f39ab | |
parent | ca0fa90277e65cff44262315ea1bd0f6594aa915 (diff) |
Moved shader programs in qmlvideofx demo into separate files
Moving shader programs into .glsl files means that QtCreator can
apply syntax highlighting and autocompletion.
Reviewed-by: TrustMe
49 files changed, 1892 insertions, 820 deletions
diff --git a/demos/video/qmlvideofx/filereader.cpp b/demos/video/qmlvideofx/filereader.cpp new file mode 100644 index 0000000000..f3c08272a7 --- /dev/null +++ b/demos/video/qmlvideofx/filereader.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "filereader.h" +#include "trace.h" +#include <QtCore/QFile> +#include <QtCore/QTextStream> + +QString FileReader::readFile(const QString &fileName) +{ + qtTrace() << "FileReader::readFile" << "fileName" << fileName; + QString content; + QFile file(fileName); + if (file.open(QIODevice::ReadOnly)) { + QTextStream stream(&file); + content = stream.readAll(); + } + return content; +} + diff --git a/demos/video/qmlvideofx/filereader.h b/demos/video/qmlvideofx/filereader.h new file mode 100644 index 0000000000..ff4ff35345 --- /dev/null +++ b/demos/video/qmlvideofx/filereader.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/QObject> + +class FileReader : public QObject +{ + Q_OBJECT +public: + Q_INVOKABLE QString readFile(const QString &fileName); +}; + diff --git a/demos/video/qmlvideofx/main.cpp b/demos/video/qmlvideofx/main.cpp index 755d940016..f43af8f5da 100644 --- a/demos/video/qmlvideofx/main.cpp +++ b/demos/video/qmlvideofx/main.cpp @@ -39,8 +39,10 @@ ** ****************************************************************************/ +#include <QtDeclarative/QDeclarativeContext> #include <QtGui/QApplication> #include <QtGui/QGraphicsObject> +#include "filereader.h" #include "qmlapplicationviewer.h" #include "trace.h" @@ -132,6 +134,9 @@ int main(int argc, char *argv[]) rootObject, SLOT(qmlFramePainted())); #endif + FileReader fileReader; + viewer.rootContext()->setContextProperty("fileReader", &fileReader); + #ifdef SMALL_SCREEN_PHYSICAL viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape); viewer.showFullScreen(); diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/Effect.qml b/demos/video/qmlvideofx/qml/qmlvideofx/Effect.qml index b037d2bc04..a28696544f 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/Effect.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/Effect.qml @@ -48,14 +48,28 @@ ShaderEffectItem { property bool supportsDivider: false property real targetWidth: 0 property real targetHeight: 0 + property string fragmentShaderFilename + property string vertexShaderFilename - property string fragmentShaderCommon: " - #ifdef GL_ES - precision mediump float; - #else - # define lowp - # define mediump - # define highp - #endif // GL_ES - " + QtObject { + id: d + property string fragmentShaderCommon: " + #ifdef GL_ES + precision mediump float; + #else + # define lowp + # define mediump + # define highp + #endif // GL_ES + " + } + + // The following is a workaround for the fact that ShaderEffectItem + // doesn't provide a way for shader programs to be read from a file, + // rather than being inline in the QML file + + onFragmentShaderFilenameChanged: + fragmentShader = d.fragmentShaderCommon + fileReader.readFile(fragmentShaderFilename) + onVertexShaderFilenameChanged: + vertexShader = fileReader.readFile(vertexShaderFilename) } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectBillboard.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectBillboard.qml index 4fa6d30abd..b85ea1d48f 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectBillboard.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectBillboard.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -52,36 +50,8 @@ Effect { property real dividerValue: 0.5 property real grid: 10.0 * param1Value - fragmentShader: fragmentShaderCommon + " - uniform float grid; - uniform float dividerValue; - const float step_x = 0.0015625; - const float step_y = 0.0027778; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; + property real step_x: 0.0015625 + property real step_y: targetHeight ? (step_x * targetWidth / targetHeight) : 0.0 - void main() - { - vec2 uv = qt_TexCoord0.xy; - float offx = floor(uv.x / (grid * step_x)); - float offy = floor(uv.y / (grid * step_y)); - vec3 res = texture2D(source, vec2(offx * grid * step_x , offy * grid * step_y)).rgb; - vec2 prc = fract(uv / vec2(grid * step_x, grid * step_y)); - vec2 pw = pow(abs(prc - 0.5), vec2(2.0)); - float rs = pow(0.45, 2.0); - float gr = smoothstep(rs - 0.1, rs + 0.1, pw.x + pw.y); - float y = (res.r + res.g + res.b) / 3.0; - vec3 ra = res / y; - float ls = 0.3; - float lb = ceil(y / ls); - float lf = ls * lb + 0.3; - res = lf * res; - vec3 col = mix(res, vec3(0.1, 0.1, 0.1), gr); - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(col, 1.0); - else - gl_FragColor = qt_Opacity * texture2D(source, uv); - }" + fragmentShaderFilename: "shaders/billboard.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectBlackAndWhite.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectBlackAndWhite.qml index bf4d9d7a94..9e80636214 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectBlackAndWhite.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectBlackAndWhite.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -51,24 +49,5 @@ Effect { property real param1Value: 0.5 property real dividerValue: 0.5 - fragmentShader: fragmentShaderCommon + " - uniform float param1Value; - uniform float dividerValue; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 orig = texture2D(source, uv); - vec3 col = orig.rgb; - float y = 0.3 *col.r + 0.59 * col.g + 0.11 * col.b; - y = y < param1Value ? 0.0 : 1.0; - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(y, y, y, 1.0); - else - gl_FragColor = qt_Opacity * orig; - }" + fragmentShaderFilename: "shaders/blackandwhite.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectEmboss.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectEmboss.qml index 8ba4988f31..758c3e0e46 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectEmboss.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectEmboss.qml @@ -38,7 +38,6 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html import QtQuick 1.0 @@ -49,33 +48,5 @@ Effect { property real dividerValue: 0.5 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - const float step_w = 0.0015625; - const float step_h = 0.0027778; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec3 t1 = texture2D(source, vec2(uv.x - step_w, uv.y - step_h)).rgb; - vec3 t2 = texture2D(source, vec2(uv.x, uv.y - step_h)).rgb; - vec3 t3 = texture2D(source, vec2(uv.x + step_w, uv.y - step_h)).rgb; - vec3 t4 = texture2D(source, vec2(uv.x - step_w, uv.y)).rgb; - vec3 t5 = texture2D(source, uv).rgb; - vec3 t6 = texture2D(source, vec2(uv.x + step_w, uv.y)).rgb; - vec3 t7 = texture2D(source, vec2(uv.x - step_w, uv.y + step_h)).rgb; - vec3 t8 = texture2D(source, vec2(uv.x, uv.y + step_h)).rgb; - vec3 t9 = texture2D(source, vec2(uv.x + step_w, uv.y + step_h)).rgb; - vec3 rr = -4.0 * t1 - 4.0 * t2 - 4.0 * t4 + 12.0 * t5; - float y = (rr.r + rr.g + rr.b) / 3.0; - vec3 col = vec3(y, y, y) + 0.3; - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(col, 1.0); - else - gl_FragColor = qt_Opacity * texture2D(source, uv); - }" + fragmentShaderFilename: "shaders/emboss.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectGaussianBlur.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectGaussianBlur.qml index 067dd05a9c..27f761eaeb 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectGaussianBlur.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectGaussianBlur.qml @@ -61,33 +61,7 @@ Item { property real dividerValue: parent.dividerValue property real blurSize: 4.0 * parent.param1Value / targetWidth - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float blurSize; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 c = vec4(0.0); - if (uv.x < dividerValue) { - c += texture2D(source, uv - vec2(0.0, 4.0*blurSize)) * 0.05; - c += texture2D(source, uv - vec2(0.0, 3.0*blurSize)) * 0.09; - c += texture2D(source, uv - vec2(0.0, 2.0*blurSize)) * 0.12; - c += texture2D(source, uv - vec2(0.0, 1.0*blurSize)) * 0.15; - c += texture2D(source, uv) * 0.16; - c += texture2D(source, uv + vec2(0.0, 1.0*blurSize)) * 0.15; - c += texture2D(source, uv + vec2(0.0, 2.0*blurSize)) * 0.12; - c += texture2D(source, uv + vec2(0.0, 3.0*blurSize)) * 0.09; - c += texture2D(source, uv + vec2(0.0, 4.0*blurSize)) * 0.05; - } else { - c = texture2D(source, qt_TexCoord0); - } - gl_FragColor = qt_Opacity * c; - }" + fragmentShaderFilename: "shaders/gaussianblur_v.fsh" Effect { id: horizontalShader @@ -95,33 +69,7 @@ Item { property real dividerValue: parent.dividerValue property real blurSize: parent.blurSize - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float blurSize; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 c = vec4(0.0); - if (uv.x < dividerValue) { - c += texture2D(source, uv - vec2(4.0*blurSize, 0.0)) * 0.05; - c += texture2D(source, uv - vec2(3.0*blurSize, 0.0)) * 0.09; - c += texture2D(source, uv - vec2(2.0*blurSize, 0.0)) * 0.12; - c += texture2D(source, uv - vec2(1.0*blurSize, 0.0)) * 0.15; - c += texture2D(source, uv) * 0.16; - c += texture2D(source, uv + vec2(1.0*blurSize, 0.0)) * 0.15; - c += texture2D(source, uv + vec2(2.0*blurSize, 0.0)) * 0.12; - c += texture2D(source, uv + vec2(3.0*blurSize, 0.0)) * 0.09; - c += texture2D(source, uv + vec2(4.0*blurSize, 0.0)) * 0.05; - } else { - c = texture2D(source, qt_TexCoord0); - } - gl_FragColor = qt_Opacity * c; - }" + fragmentShaderFilename: "shaders/gaussianblur_h.fsh" } } } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectGlow.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectGlow.qml index 36c3dfb3b5..70ed7520ec 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectGlow.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectGlow.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -50,34 +48,5 @@ Effect { property real dividerValue: 0.5 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - const float step_w = 0.0015625; - const float step_h = 0.0027778; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec3 t1 = texture2D(source, vec2(uv.x - step_w, uv.y - step_h)).rgb; - vec3 t2 = texture2D(source, vec2(uv.x, uv.y - step_h)).rgb; - vec3 t3 = texture2D(source, vec2(uv.x + step_w, uv.y - step_h)).rgb; - vec3 t4 = texture2D(source, vec2(uv.x - step_w, uv.y)).rgb; - vec3 t5 = texture2D(source, uv).rgb; - vec3 t6 = texture2D(source, vec2(uv.x + step_w, uv.y)).rgb; - vec3 t7 = texture2D(source, vec2(uv.x - step_w, uv.y + step_h)).rgb; - vec3 t8 = texture2D(source, vec2(uv.x, uv.y + step_h)).rgb; - vec3 t9 = texture2D(source, vec2(uv.x + step_w, uv.y + step_h)).rgb; - vec3 xx = t1 + 2.0*t2 + t3 - t7 - 2.0*t8 - t9; - vec3 yy = t1 - t3 + 2.0*t4 - 2.0*t6 + t7 - t9; - vec3 rr = sqrt(xx * xx + yy * yy); - vec3 col = rr * 2.0 * t5; - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(col, 1.0); - else - gl_FragColor = qt_Opacity * texture2D(source, uv); - }" + fragmentShaderFilename: "shaders/glow.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectIsolate.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectIsolate.qml index 11ea99a2b8..c7ce9c7f3f 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectIsolate.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectIsolate.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -55,50 +53,5 @@ Effect { property real targetHue: 360.0 * param1Value property real windowWidth: 60.0 * param2Value - fragmentShader: fragmentShaderCommon + " - uniform float targetHue; - uniform float windowWidth; - uniform float dividerValue; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void rgb2hsl(vec3 rgb, out float h, out float s, float l) - { - float maxval = max(rgb.r, max(rgb.g, rgb.b)); - float minval = min(rgb.r, min(rgb.g, rgb.b)); - float delta = maxval - minval; - l = (minval + maxval) / 2.0; - s = 0.0; - if (l > 0.0 && l < 1.0) - s = delta / (l < 0.5 ? 2.0 * l : 2.0 - 2.0 * l); - h = 0.0; - if (delta > 0.0) - { - if (rgb.r == maxval && rgb.g != maxval) - h += (rgb.g - rgb.b ) / delta; - if (rgb.g == maxval && rgb.b != maxval) - h += 2.0 + (rgb.b - rgb.r) / delta; - if (rgb.b == maxval && rgb.r != maxval) - h += 4.0 + (rgb.r - rgb.g) / delta; - h *= 60.0; - } - } - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec3 col = texture2D(source, uv).rgb; - float h, s, l; - rgb2hsl(col, h, s, l); - float h2 = (h > targetHue) ? h - 360.0 : h + 360.0; - float y = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; - vec3 result; - if (uv.x > dividerValue || (abs(h - targetHue) < windowWidth) || (abs(h2 - targetHue) < windowWidth)) - result = col; - else - result = vec3(y, y, y); - gl_FragColor = qt_Opacity * vec4(result, 1.0); - }" + fragmentShaderFilename: "shaders/isolate.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectMagnify.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectMagnify.qml index 7886d40b73..81a4e44ad2 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectMagnify.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectMagnify.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://www.reddit.com/r/programming/comments/losip/shader_toy/c2upn1e - import QtQuick 1.0 Effect { @@ -62,31 +60,10 @@ Effect { onTargetWidthChanged: if (posX == -1) posX = targetWidth / 2 onTargetHeightChanged: if (posY == -1) posY = targetHeight / 2 - fragmentShader: fragmentShaderCommon + " - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - uniform float radius; - uniform float diffractionIndex; - uniform float targetWidth; - uniform float targetHeight; - uniform float posX; - uniform float posY; - - void main() - { - float h = diffractionIndex * 0.5 * radius; - vec2 targetSize = vec2(targetWidth, targetHeight); - vec2 center = vec2(posX, posY); - vec2 xy = gl_FragCoord.xy - center.xy; - float r = sqrt(xy.x * xy.x + xy.y * xy.y); - vec2 new_xy = r < radius ? xy * (radius - h) / sqrt(radius * radius - r * r) : xy; - gl_FragColor = qt_Opacity * texture2D(source, (new_xy + center) / targetSize); - }" + fragmentShaderFilename: "shaders/magnify.fsh" MouseArea { anchors.fill: parent onPositionChanged: { root.posX = mouse.x; root.posY = root.targetHeight - mouse.y } } } - diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectPageCurl.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectPageCurl.qml index ec531ea8b0..2699cd6830 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectPageCurl.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectPageCurl.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://rectalogic.github.com/webvfx/examples_2transition-shader-pagecurl_8html-example.html - import QtQuick 1.0 Effect { @@ -53,150 +51,5 @@ Effect { property real curlExtent: 1.0 - param1Value - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float curlExtent; - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - const float minAmount = -0.16; - const float maxAmount = 1.3; - const float PI = 3.141592653589793; - const float scale = 512.0; - const float sharpness = 3.0; - const vec4 bgColor = vec4(1.0, 1.0, 0.8, 1.0); - - float amount = curlExtent * (maxAmount - minAmount) + minAmount; - float cylinderCenter = amount; - // 360 degrees * amount - float cylinderAngle = 2.0 * PI * amount; - const float cylinderRadius = 1.0 / PI / 2.0; - - vec3 hitPoint(float hitAngle, float yc, vec3 point, mat3 rrotation) - { - float hitPoint = hitAngle / (2.0 * PI); - point.y = hitPoint; - return rrotation * point; - } - - vec4 antiAlias(vec4 color1, vec4 color2, float distance) - { - distance *= scale; - if (distance < 0.0) return color2; - if (distance > 2.0) return color1; - float dd = pow(1.0 - distance / 2.0, sharpness); - return ((color2 - color1) * dd) + color1; - } - - float distanceToEdge(vec3 point) - { - float dx = abs(point.x > 0.5 ? 1.0 - point.x : point.x); - float dy = abs(point.y > 0.5 ? 1.0 - point.y : point.y); - if (point.x < 0.0) dx = -point.x; - if (point.x > 1.0) dx = point.x - 1.0; - if (point.y < 0.0) dy = -point.y; - if (point.y > 1.0) dy = point.y - 1.0; - if ((point.x < 0.0 || point.x > 1.0) && (point.y < 0.0 || point.y > 1.0)) return sqrt(dx * dx + dy * dy); - return min(dx, dy); - } - - vec4 seeThrough(float yc, vec2 p, mat3 rotation, mat3 rrotation) - { - float hitAngle = PI - (acos(yc / cylinderRadius) - cylinderAngle); - vec3 point = hitPoint(hitAngle, yc, rotation * vec3(p, 1.0), rrotation); - if (yc <= 0.0 && (point.x < 0.0 || point.y < 0.0 || point.x > 1.0 || point.y > 1.0)) - return bgColor; - if (yc > 0.0) - return texture2D(source, p); - vec4 color = texture2D(source, point.xy); - vec4 tcolor = vec4(0.0); - return antiAlias(color, tcolor, distanceToEdge(point)); - } - - vec4 seeThroughWithShadow(float yc, vec2 p, vec3 point, mat3 rotation, mat3 rrotation) - { - float shadow = distanceToEdge(point) * 30.0; - shadow = (1.0 - shadow) / 3.0; - if (shadow < 0.0) - shadow = 0.0; - else - shadow *= amount; - vec4 shadowColor = seeThrough(yc, p, rotation, rrotation); - shadowColor.r -= shadow; - shadowColor.g -= shadow; - shadowColor.b -= shadow; - return shadowColor; - } - - vec4 backside(float yc, vec3 point) - { - vec4 color = texture2D(source, point.xy); - float gray = (color.r + color.b + color.g) / 15.0; - gray += (8.0 / 10.0) * (pow(1.0 - abs(yc / cylinderRadius), 2.0 / 10.0) / 2.0 + (5.0 / 10.0)); - color.rgb = vec3(gray); - return color; - } - - void main(void) - { - const float angle = 30.0 * PI / 180.0; - float c = cos(-angle); - float s = sin(-angle); - mat3 rotation = mat3( - c, s, 0, - -s, c, 0, - 0.12, 0.258, 1 - ); - c = cos(angle); - s = sin(angle); - mat3 rrotation = mat3( - c, s, 0, - -s, c, 0, - 0.15, -0.5, 1 - ); - vec3 point = rotation * vec3(qt_TexCoord0, 1.0); - float yc = point.y - cylinderCenter; - vec4 color = vec4(1.0, 0.0, 0.0, 1.0); - if (yc < -cylinderRadius) { - // See through to background - color = bgColor; - } else if (yc > cylinderRadius) { - // Flat surface - color = texture2D(source, qt_TexCoord0); - } else { - float hitAngle = (acos(yc / cylinderRadius) + cylinderAngle) - PI; - float hitAngleMod = mod(hitAngle, 2.0 * PI); - if ((hitAngleMod > PI && amount < 0.5) || (hitAngleMod > PI/2.0 && amount < 0.0)) { - color = seeThrough(yc, qt_TexCoord0, rotation, rrotation); - } else { - point = hitPoint(hitAngle, yc, point, rrotation); - if (point.x < 0.0 || point.y < 0.0 || point.x > 1.0 || point.y > 1.0) { - color = seeThroughWithShadow(yc, qt_TexCoord0, point, rotation, rrotation); - } else { - color = backside(yc, point); - vec4 otherColor; - if (yc < 0.0) { - float shado = 1.0 - (sqrt(pow(point.x - 0.5, 2.0) + pow(point.y - 0.5, 2.0)) / 0.71); - shado *= pow(-yc / cylinderRadius, 3.0); - shado *= 0.5; - otherColor = vec4(0.0, 0.0, 0.0, shado); - } else { - otherColor = texture2D(source, qt_TexCoord0); - } - color = antiAlias(color, otherColor, cylinderRadius - abs(yc)); - - // This second antialiasing step causes the shader to fail to render, on - // Symbian devices (tested so far using IVE3.5). Running out of scratch - // memory? - /* - vec4 cl = seeThroughWithShadow(yc, qt_TexCoord0, point, rotation, rrotation); - float dist = distanceToEdge(point); - color = antiAlias(color, cl, dist); - */ - } - } - } - gl_FragColor = qt_Opacity * color; - }" + fragmentShaderFilename: "shaders/pagecurl.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectPixelate.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectPixelate.qml index 5d4e519ae0..b0d7b274c8 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectPixelate.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectPixelate.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/ - import QtQuick 1.0 Effect { @@ -53,26 +51,5 @@ Effect { property real granularity: param1Value * 20 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float granularity; - uniform float targetWidth; - uniform float targetHeight; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec2 tc = qt_TexCoord0; - if (uv.x < dividerValue && granularity > 0.0) { - float dx = granularity / targetWidth; - float dy = granularity / targetHeight; - tc = vec2(dx*(floor(uv.x/dx) + 0.5), - dy*(floor(uv.y/dy) + 0.5)); - } - gl_FragColor = qt_Opacity * texture2D(source, tc); - }" + fragmentShaderFilename: "shaders/pixelate.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectPosterize.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectPosterize.qml index 2b3358a1d7..91245c1bc1 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectPosterize.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectPosterize.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://www.geeks3d.com/20091027/shader-library-posterization-post-processing-effect-glsl/ - import QtQuick 1.0 Effect { @@ -54,30 +52,5 @@ Effect { property real gamma: param1Value property real numColors: 8.0 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float gamma; - uniform float numColors; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 c = vec4(0.0); - if (uv.x < dividerValue) { - vec3 x = texture2D(source, uv).rgb; - x = pow(x, vec3(gamma, gamma, gamma)); - x = x * numColors; - x = floor(x); - x = x / numColors; - x = pow(x, vec3(1.0/gamma)); - c = vec4(x, 1.0); - } else { - c = texture2D(source, uv); - } - gl_FragColor = qt_Opacity * c; - }" + fragmentShaderFilename: "shaders/posterize.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectRipple.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectRipple.qml index 76a4768992..59765a6151 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectRipple.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectRipple.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://labs.qt.nokia.com/2011/03/22/the-convenient-power-of-qml-scene-graph/ - import QtQuick 1.0 Effect { @@ -59,40 +57,5 @@ Effect { property real amplitude: param1Value * 0.03 property real n: param2Value * 7 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float targetWidth; - uniform float targetHeight; - uniform float time; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - const float PI = 3.1415926535; - const int ITER = 7; - const float RATE = 0.1; - uniform float amplitude; - uniform float n; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec2 tc = uv; - vec2 p = vec2(-1.0 + 2.0 * gl_FragCoord.x / targetWidth, -1.0 + 2.0 * gl_FragCoord.y / targetHeight); - float diffx = 0.0; - float diffy = 0.0; - vec4 col; - if (uv.x < dividerValue) { - for (int i=0; i<ITER; ++i) { - float theta = float(i) * PI / float(ITER); - vec2 r = vec2(cos(theta) * p.x + sin(theta) * p.y, -1.0 * sin(theta) * p.x + cos(theta) * p.y); - float diff = (sin(2.0 * PI * n * (r.y + time * RATE)) + 1.0) / 2.0; - diffx += diff * sin(theta); - diffy += diff * cos(theta); - } - tc = 0.5*(vec2(1.0,1.0) + p) + amplitude * vec2(diffx, diffy); - } - gl_FragColor = qt_Opacity * texture2D(source, tc); - }" + fragmentShaderFilename: "shaders/ripple.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSepia.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSepia.qml index 6513748cd5..d88b2fd454 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSepia.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSepia.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -50,22 +48,5 @@ Effect { property real dividerValue: 0.5 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 orig = texture2D(source, uv); - vec3 col = orig.rgb; - float y = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(y + 0.15, y + 0.07, y - 0.12, 1.0); - else - gl_FragColor = qt_Opacity * orig; - }" + fragmentShaderFilename: "shaders/sepia.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSharpen.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSharpen.qml index 4aa17657d3..c8d18ed9e4 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSharpen.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSharpen.qml @@ -38,7 +38,6 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html import QtQuick 1.0 @@ -52,37 +51,5 @@ Effect { property real amount: 18.0 * param1Value - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float amount; - const float step_w = 0.0015625; - const float step_h = 0.0027778; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - vec3 sharpen(vec3 t1, vec3 t2, vec3 t3, vec3 t4, vec3 t5, vec3 t6, vec3 t7, vec3 t8, vec3 t9) - { - return -t1 - t2 - t3 - t4 + amount * t5 - t6 - t7 - t8 - t9; - } - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec3 t1 = texture2D(source, vec2(uv.x - step_w, uv.y - step_h)).rgb; - vec3 t2 = texture2D(source, vec2(uv.x, uv.y - step_h)).rgb; - vec3 t3 = texture2D(source, vec2(uv.x + step_w, uv.y - step_h)).rgb; - vec3 t4 = texture2D(source, vec2(uv.x - step_w, uv.y)).rgb; - vec3 t5 = texture2D(source, uv).rgb; - vec3 t6 = texture2D(source, vec2(uv.x + step_w, uv.y)).rgb; - vec3 t7 = texture2D(source, vec2(uv.x - step_w, uv.y + step_h)).rgb; - vec3 t8 = texture2D(source, vec2(uv.x, uv.y + step_h)).rgb; - vec3 t9 = texture2D(source, vec2(uv.x + step_w, uv.y + step_h)).rgb; - vec3 col = sharpen(t1, t2, t3, t4, t5, t6, t7, t8, t9); - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(col, 1.0); - else - gl_FragColor = qt_Opacity * texture2D(source, uv); - }" + fragmentShaderFilename: "shaders/sharpen.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectShockwave.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectShockwave.qml index fcc05520a1..46088f27e3 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectShockwave.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectShockwave.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://www.geeks3d.com/20091116/shader-library-2d-shockwave-post-processing-filter-glsl/ - import QtQuick 1.0 Effect { @@ -79,35 +77,5 @@ Effect { property real weight: param1Value - fragmentShader: fragmentShaderCommon + " - uniform float centerX; - uniform float centerY; - uniform float dividerValue; - uniform float granularity; - uniform float time; - uniform float weight; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec2 tc = qt_TexCoord0; - vec2 center = vec2(centerX, centerY); - const vec3 shock = vec3(10.0, 1.5, 0.1); - if (uv.x < dividerValue) { - float distance = distance(uv, center); - if ((distance <= (time + shock.z)) && - (distance >= (time - shock.z))) { - float diff = (distance - time); - float powDiff = 1.0 - pow(abs(diff*shock.x), shock.y*weight); - float diffTime = diff * powDiff; - vec2 diffUV = normalize(uv - center); - tc += (diffUV * diffTime); - } - } - gl_FragColor = qt_Opacity * texture2D(source, tc); - }" + fragmentShaderFilename: "shaders/shockwave.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection1.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection1.qml index bfd0a26660..fc09242fe4 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection1.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection1.qml @@ -38,7 +38,6 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -// Based on "Graphics Shaders: Theory and Practice" (http://cgeducation.org/ShadersBook/) import QtQuick 1.0 @@ -55,45 +54,5 @@ Effect { property real resS: targetSize property real resT: targetSize - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float mixLevel; - uniform float resS; - uniform float resT; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 c = vec4(0.0); - if (uv.x < dividerValue) { - vec2 st = qt_TexCoord0.st; - vec3 irgb = texture2D(source, st).rgb; - vec2 stp0 = vec2(1.0 / resS, 0.0); - vec2 st0p = vec2(0.0 , 1.0 / resT); - vec2 stpp = vec2(1.0 / resS, 1.0 / resT); - vec2 stpm = vec2(1.0 / resS, -1.0 / resT); - const vec3 W = vec3(0.2125, 0.7154, 0.0721); - float i00 = dot(texture2D(source, st).rgb, W); - float im1m1 = dot(texture2D(source, st-stpp).rgb, W); - float ip1p1 = dot(texture2D(source, st+stpp).rgb, W); - float im1p1 = dot(texture2D(source, st-stpm).rgb, W); - float ip1m1 = dot(texture2D(source, st+stpm).rgb, W); - float im10 = dot(texture2D(source, st-stp0).rgb, W); - float ip10 = dot(texture2D(source, st+stp0).rgb, W); - float i0m1 = dot(texture2D(source, st-st0p).rgb, W); - float i0p1 = dot(texture2D(source, st+st0p).rgb, W); - float h = -1.0*im1p1 - 2.0*i0p1 - 1.0*ip1p1 + 1.0*im1m1 + 2.0*i0m1 + 1.0*ip1m1; - float v = -1.0*im1m1 - 2.0*im10 - 1.0*im1p1 + 1.0*ip1m1 + 2.0*ip10 + 1.0*ip1p1; - float mag = 1.0 - length(vec2(h, v)); - vec3 target = vec3(mag, mag, mag); - c = vec4(target, 1.0); - } else { - c = texture2D(source, qt_TexCoord0); - } - gl_FragColor = qt_Opacity * c; - }" + fragmentShaderFilename: "shaders/sobeledgedetection1.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection2.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection2.qml index 66954ae962..3171751983 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection2.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectSobelEdgeDetection2.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://rastergrid.com/blog/downloads/frei-chen-edge-detector/ - import QtQuick 1.0 Effect { @@ -53,39 +51,5 @@ Effect { property real weight: param1Value - fragmentShader: fragmentShaderCommon + " - #version 130 - uniform sampler2D source; - uniform float dividerValue; - uniform float weight; - mat3 G[2] = mat3[]( - mat3( 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0 ), - mat3( 1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0 ) - ); - uniform lowp float qt_Opacity; - in vec2 qt_TexCoord0; - out vec4 FragmentColor; - void main() { - vec2 uv = qt_TexCoord0.xy; - vec4 c = vec4(0.0); - if (uv.x < dividerValue) { - mat3 intensity; - float conv[2]; - vec3 sample; - for (int i=0; i<3; ++i) { - for (int j=0; j<3; ++j) { - sample = texelFetch(source, ivec2(gl_FragCoord) + ivec2(i-1, j-1), 0).rgb; - intensity[i][j] = length(sample) * weight; - } - } - for (int i=0; i<2; ++i) { - float dp3 = dot(G[i][0], intensity[0]) + dot(G[i][1], intensity[1]) + dot(G[i][2], intensity[2]); - conv[i] = dp3 * dp3; - } - c = vec4(0.5 * sqrt(conv[0]*conv[0] + conv[1]*conv[1])); - } else { - c = texture2D(source, qt_TexCoord0); - } - FragmentColor = qt_Opacity * c; - }" + fragmentShaderFilename: "shaders/sobeledgedetection2.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectTiltShift.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectTiltShift.qml index 95bcc2ce2d..191311584a 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectTiltShift.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectTiltShift.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -50,37 +48,5 @@ Effect { property real dividerValue: 0.5 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - const float step_w = 0.0015625; - const float step_h = 0.0027778; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - vec3 blur() - { - vec2 uv = qt_TexCoord0.xy; - float y = uv.y < 0.4 ? uv.y : 1.0 - uv.y; - float dist = 8.0 - 20.0 * y; - vec3 acc = vec3(0.0, 0.0, 0.0); - for (float y=-2.0; y<=2.0; ++y) { - for (float x=-2.0; x<=2.0; ++x) { - acc += texture2D(source, vec2(uv.x + dist * x * step_w, uv.y + 0.5 * dist * y * step_h)).rgb; - } - } - return acc / 25.0; - } - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec3 col; - if (uv.x < dividerValue && uv.y >= 0.4 && uv.y <= 0.6) - col = texture2D(source, uv).rgb; - else - col = blur(); - gl_FragColor = qt_Opacity * vec4(col, 1.0); - }" + fragmentShaderFilename: "shaders/tiltshift.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectToon.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectToon.qml index 553258ea11..a1a84c6575 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectToon.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectToon.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/ - import QtQuick 1.0 Effect { @@ -60,54 +58,5 @@ Effect { property real magTol: 0.3 property real quantize: 8.0 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - uniform float threshold; - uniform float resS; - uniform float resT; - uniform float magTol; - uniform float quantize; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec4 color = vec4(1.0, 0.0, 0.0, 1.1); - vec2 uv = qt_TexCoord0.xy; - if (uv.x < dividerValue) { - vec2 st = qt_TexCoord0.st; - vec3 rgb = texture2D(source, st).rgb; - vec2 stp0 = vec2(1.0/resS, 0.0); - vec2 st0p = vec2(0.0 , 1.0/resT); - vec2 stpp = vec2(1.0/resS, 1.0/resT); - vec2 stpm = vec2(1.0/resS, -1.0/resT); - float i00 = dot( texture2D(source, st).rgb, vec3(0.2125,0.7154,0.0721)); - float im1m1 = dot( texture2D(source, st-stpp).rgb, vec3(0.2125,0.7154,0.0721)); - float ip1p1 = dot( texture2D(source, st+stpp).rgb, vec3(0.2125,0.7154,0.0721)); - float im1p1 = dot( texture2D(source, st-stpm).rgb, vec3(0.2125,0.7154,0.0721)); - float ip1m1 = dot( texture2D(source, st+stpm).rgb, vec3(0.2125,0.7154,0.0721)); - float im10 = dot( texture2D(source, st-stp0).rgb, vec3(0.2125,0.7154,0.0721)); - float ip10 = dot( texture2D(source, st+stp0).rgb, vec3(0.2125,0.7154,0.0721)); - float i0m1 = dot( texture2D(source, st-st0p).rgb, vec3(0.2125,0.7154,0.0721)); - float i0p1 = dot( texture2D(source, st+st0p).rgb, vec3(0.2125,0.7154,0.0721)); - float h = -1.*im1p1 - 2.*i0p1 - 1.*ip1p1 + 1.*im1m1 + 2.*i0m1 + 1.*ip1m1; - float v = -1.*im1m1 - 2.*im10 - 1.*im1p1 + 1.*ip1m1 + 2.*ip10 + 1.*ip1p1; - float mag = sqrt(h*h + v*v); - if (mag > magTol) { - color = vec4(0.0, 0.0, 0.0, 1.0); - } - else { - rgb.rgb *= quantize; - rgb.rgb += vec3(0.5, 0.5, 0.5); - ivec3 irgb = ivec3(rgb.rgb); - rgb.rgb = vec3(irgb) / quantize; - color = vec4(rgb, 1.0); - } - } else { - color = texture2D(source, uv); - } - gl_FragColor = qt_Opacity * color; - }" + fragmentShaderFilename: "shaders/toon.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectVignette.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectVignette.qml index 682de629c6..a3b0b6c2bc 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectVignette.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectVignette.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -50,27 +48,5 @@ Effect { property real dividerValue: 0.5 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 orig = texture2D(source, uv); - float cr = pow(0.1, 2.0); - float pt = pow(uv.x - 0.5, 2.0) + pow(uv.y - 0.5, 2.0); - float d = pt - cr; - float cf = 1.0; - if (d > 0.0) - cf = 1.0 - 2.0 * d; - vec3 col = cf * orig.rgb; - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(col, 1.0); - else - gl_FragColor = qt_Opacity * orig; - }" + fragmentShaderFilename: "shaders/vignette.fsh" } diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectWarhol.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectWarhol.qml index b82696a119..cdd61a1b48 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectWarhol.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectWarhol.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html - import QtQuick 1.0 Effect { @@ -50,30 +48,5 @@ Effect { property real dividerValue: 0.5 - fragmentShader: fragmentShaderCommon + " - uniform float dividerValue; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec4 orig = texture2D(source, uv); - vec3 col = orig.rgb; - float y = 0.3 *col.r + 0.59 * col.g + 0.11 * col.b; - y = y < 0.3 ? 0.0 : (y < 0.6 ? 0.5 : 1.0); - if (y == 0.5) - col = vec3(0.8, 0.0, 0.0); - else if (y == 1.0) - col = vec3(0.9, 0.9, 0.0); - else - col = vec3(0.0, 0.0, 0.0); - if (uv.x < dividerValue) - gl_FragColor = qt_Opacity * vec4(col, 1.0); - else - gl_FragColor = qt_Opacity * orig; - }" + fragmentShaderFilename: "shaders/warhol.fsh" } - diff --git a/demos/video/qmlvideofx/qml/qmlvideofx/EffectWobble.qml b/demos/video/qmlvideofx/qml/qmlvideofx/EffectWobble.qml index f26893eaba..c9a3e08d9a 100644 --- a/demos/video/qmlvideofx/qml/qmlvideofx/EffectWobble.qml +++ b/demos/video/qmlvideofx/qml/qmlvideofx/EffectWobble.qml @@ -39,8 +39,6 @@ ** ****************************************************************************/ -// Based on http://labs.qt.nokia.com/2011/03/22/the-convenient-power-of-qml-scene-graph/ - import QtQuick 1.0 Effect { @@ -57,24 +55,5 @@ Effect { NumberAnimation on time { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 600 } - fragmentShader: fragmentShaderCommon + " - uniform float amplitude; - uniform float dividerValue; - uniform float frequency; - uniform float time; - - uniform sampler2D source; - uniform lowp float qt_Opacity; - varying vec2 qt_TexCoord0; - - void main() - { - vec2 uv = qt_TexCoord0.xy; - vec2 tc = qt_TexCoord0; - if (uv.x < dividerValue) { - vec2 p = sin(time + frequency * qt_TexCoord0); - tc += amplitude * vec2(p.y, -p.x); - } - gl_FragColor = qt_Opacity * texture2D(source, tc); - }" + fragmentShaderFilename: "shaders/wobble.fsh" } diff --git a/demos/video/qmlvideofx/qmlvideofx.pro b/demos/video/qmlvideofx/qmlvideofx.pro index 5e820216d0..90bec66df6 100644 --- a/demos/video/qmlvideofx/qmlvideofx.pro +++ b/demos/video/qmlvideofx/qmlvideofx.pro @@ -2,8 +2,10 @@ TEMPLATE = app TARGET = qmlvideofx QT += opengl -SOURCES += main.cpp -HEADERS += trace.h +SOURCES += filereader.cpp \ + main.cpp +HEADERS += filereader.h \ + trace.h RESOURCES += qmlvideofx.qrc qml_folder.source = qml/qmlvideofx @@ -14,6 +16,10 @@ images_folder.source = images images_folder.target = . DEPLOYMENTFOLDERS += images_folder +shaders_folder.source = shaders +shaders_folder.target = . +DEPLOYMENTFOLDERS += shaders_folder + SNIPPETS_PATH = ../snippets include($$SNIPPETS_PATH/performancemonitor/performancemonitordeclarative.pri) performanceItemAddDeployment() diff --git a/demos/video/qmlvideofx/shaders/billboard.fsh b/demos/video/qmlvideofx/shaders/billboard.fsh new file mode 100644 index 0000000000..0264f450c6 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/billboard.fsh @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float grid; +uniform float dividerValue; +uniform float step_x; +uniform float step_y; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + float offx = floor(uv.x / (grid * step_x)); + float offy = floor(uv.y / (grid * step_y)); + vec3 res = texture2D(source, vec2(offx * grid * step_x , offy * grid * step_y)).rgb; + vec2 prc = fract(uv / vec2(grid * step_x, grid * step_y)); + vec2 pw = pow(abs(prc - 0.5), vec2(2.0)); + float rs = pow(0.45, 2.0); + float gr = smoothstep(rs - 0.1, rs + 0.1, pw.x + pw.y); + float y = (res.r + res.g + res.b) / 3.0; + vec3 ra = res / y; + float ls = 0.3; + float lb = ceil(y / ls); + float lf = ls * lb + 0.3; + res = lf * res; + vec3 col = mix(res, vec3(0.1, 0.1, 0.1), gr); + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(col, 1.0); + else + gl_FragColor = qt_Opacity * texture2D(source, uv); +} diff --git a/demos/video/qmlvideofx/shaders/blackandwhite.fsh b/demos/video/qmlvideofx/shaders/blackandwhite.fsh new file mode 100644 index 0000000000..7e0dc9d996 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/blackandwhite.fsh @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float param1Value; +uniform float dividerValue; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 orig = texture2D(source, uv); + vec3 col = orig.rgb; + float y = 0.3 *col.r + 0.59 * col.g + 0.11 * col.b; + y = y < param1Value ? 0.0 : 1.0; + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(y, y, y, 1.0); + else + gl_FragColor = qt_Opacity * orig; +} diff --git a/demos/video/qmlvideofx/shaders/emboss.fsh b/demos/video/qmlvideofx/shaders/emboss.fsh new file mode 100644 index 0000000000..091e260505 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/emboss.fsh @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float dividerValue; +const float step_w = 0.0015625; +const float step_h = 0.0027778; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec3 t1 = texture2D(source, vec2(uv.x - step_w, uv.y - step_h)).rgb; + vec3 t2 = texture2D(source, vec2(uv.x, uv.y - step_h)).rgb; + vec3 t3 = texture2D(source, vec2(uv.x + step_w, uv.y - step_h)).rgb; + vec3 t4 = texture2D(source, vec2(uv.x - step_w, uv.y)).rgb; + vec3 t5 = texture2D(source, uv).rgb; + vec3 t6 = texture2D(source, vec2(uv.x + step_w, uv.y)).rgb; + vec3 t7 = texture2D(source, vec2(uv.x - step_w, uv.y + step_h)).rgb; + vec3 t8 = texture2D(source, vec2(uv.x, uv.y + step_h)).rgb; + vec3 t9 = texture2D(source, vec2(uv.x + step_w, uv.y + step_h)).rgb; + vec3 rr = -4.0 * t1 - 4.0 * t2 - 4.0 * t4 + 12.0 * t5; + float y = (rr.r + rr.g + rr.b) / 3.0; + vec3 col = vec3(y, y, y) + 0.3; + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(col, 1.0); + else + gl_FragColor = qt_Opacity * texture2D(source, uv); +} diff --git a/demos/video/qmlvideofx/shaders/gaussianblur_h.fsh b/demos/video/qmlvideofx/shaders/gaussianblur_h.fsh new file mode 100644 index 0000000000..249ee30404 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/gaussianblur_h.fsh @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +uniform float dividerValue; +uniform float blurSize; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 c = vec4(0.0); + if (uv.x < dividerValue) { + c += texture2D(source, uv - vec2(4.0*blurSize, 0.0)) * 0.05; + c += texture2D(source, uv - vec2(3.0*blurSize, 0.0)) * 0.09; + c += texture2D(source, uv - vec2(2.0*blurSize, 0.0)) * 0.12; + c += texture2D(source, uv - vec2(1.0*blurSize, 0.0)) * 0.15; + c += texture2D(source, uv) * 0.16; + c += texture2D(source, uv + vec2(1.0*blurSize, 0.0)) * 0.15; + c += texture2D(source, uv + vec2(2.0*blurSize, 0.0)) * 0.12; + c += texture2D(source, uv + vec2(3.0*blurSize, 0.0)) * 0.09; + c += texture2D(source, uv + vec2(4.0*blurSize, 0.0)) * 0.05; + } else { + c = texture2D(source, qt_TexCoord0); + } + gl_FragColor = qt_Opacity * c; +} diff --git a/demos/video/qmlvideofx/shaders/gaussianblur_v.fsh b/demos/video/qmlvideofx/shaders/gaussianblur_v.fsh new file mode 100644 index 0000000000..249052c9fa --- /dev/null +++ b/demos/video/qmlvideofx/shaders/gaussianblur_v.fsh @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +uniform float dividerValue; +uniform float blurSize; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 c = vec4(0.0); + if (uv.x < dividerValue) { + c += texture2D(source, uv - vec2(0.0, 4.0*blurSize)) * 0.05; + c += texture2D(source, uv - vec2(0.0, 3.0*blurSize)) * 0.09; + c += texture2D(source, uv - vec2(0.0, 2.0*blurSize)) * 0.12; + c += texture2D(source, uv - vec2(0.0, 1.0*blurSize)) * 0.15; + c += texture2D(source, uv) * 0.16; + c += texture2D(source, uv + vec2(0.0, 1.0*blurSize)) * 0.15; + c += texture2D(source, uv + vec2(0.0, 2.0*blurSize)) * 0.12; + c += texture2D(source, uv + vec2(0.0, 3.0*blurSize)) * 0.09; + c += texture2D(source, uv + vec2(0.0, 4.0*blurSize)) * 0.05; + } else { + c = texture2D(source, qt_TexCoord0); + } + gl_FragColor = qt_Opacity * c; +} diff --git a/demos/video/qmlvideofx/shaders/glow.fsh b/demos/video/qmlvideofx/shaders/glow.fsh new file mode 100644 index 0000000000..8c40452d50 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/glow.fsh @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float dividerValue; +const float step_w = 0.0015625; +const float step_h = 0.0027778; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec3 t1 = texture2D(source, vec2(uv.x - step_w, uv.y - step_h)).rgb; + vec3 t2 = texture2D(source, vec2(uv.x, uv.y - step_h)).rgb; + vec3 t3 = texture2D(source, vec2(uv.x + step_w, uv.y - step_h)).rgb; + vec3 t4 = texture2D(source, vec2(uv.x - step_w, uv.y)).rgb; + vec3 t5 = texture2D(source, uv).rgb; + vec3 t6 = texture2D(source, vec2(uv.x + step_w, uv.y)).rgb; + vec3 t7 = texture2D(source, vec2(uv.x - step_w, uv.y + step_h)).rgb; + vec3 t8 = texture2D(source, vec2(uv.x, uv.y + step_h)).rgb; + vec3 t9 = texture2D(source, vec2(uv.x + step_w, uv.y + step_h)).rgb; + vec3 xx = t1 + 2.0*t2 + t3 - t7 - 2.0*t8 - t9; + vec3 yy = t1 - t3 + 2.0*t4 - 2.0*t6 + t7 - t9; + vec3 rr = sqrt(xx * xx + yy * yy); + vec3 col = rr * 2.0 * t5; + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(col, 1.0); + else + gl_FragColor = qt_Opacity * texture2D(source, uv); +} diff --git a/demos/video/qmlvideofx/shaders/isolate.fsh b/demos/video/qmlvideofx/shaders/isolate.fsh new file mode 100644 index 0000000000..2b0fad5668 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/isolate.fsh @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float targetHue; +uniform float windowWidth; +uniform float dividerValue; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void rgb2hsl(vec3 rgb, out float h, out float s, float l) +{ + float maxval = max(rgb.r, max(rgb.g, rgb.b)); + float minval = min(rgb.r, min(rgb.g, rgb.b)); + float delta = maxval - minval; + l = (minval + maxval) / 2.0; + s = 0.0; + if (l > 0.0 && l < 1.0) + s = delta / (l < 0.5 ? 2.0 * l : 2.0 - 2.0 * l); + h = 0.0; + if (delta > 0.0) + { + if (rgb.r == maxval && rgb.g != maxval) + h += (rgb.g - rgb.b ) / delta; + if (rgb.g == maxval && rgb.b != maxval) + h += 2.0 + (rgb.b - rgb.r) / delta; + if (rgb.b == maxval && rgb.r != maxval) + h += 4.0 + (rgb.r - rgb.g) / delta; + h *= 60.0; + } +} + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec3 col = texture2D(source, uv).rgb; + float h, s, l; + rgb2hsl(col, h, s, l); + float h2 = (h > targetHue) ? h - 360.0 : h + 360.0; + float y = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + vec3 result; + if (uv.x > dividerValue || (abs(h - targetHue) < windowWidth) || (abs(h2 - targetHue) < windowWidth)) + result = col; + else + result = vec3(y, y, y); + gl_FragColor = qt_Opacity * vec4(result, 1.0); +} diff --git a/demos/video/qmlvideofx/shaders/magnify.fsh b/demos/video/qmlvideofx/shaders/magnify.fsh new file mode 100644 index 0000000000..8ec72dfab8 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/magnify.fsh @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://www.reddit.com/r/programming/comments/losip/shader_toy/c2upn1e + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; +uniform float radius; +uniform float diffractionIndex; +uniform float targetWidth; +uniform float targetHeight; +uniform float posX; +uniform float posY; + +void main() +{ + float h = diffractionIndex * 0.5 * radius; + vec2 targetSize = vec2(targetWidth, targetHeight); + vec2 center = vec2(posX, posY); + vec2 xy = gl_FragCoord.xy - center.xy; + float r = sqrt(xy.x * xy.x + xy.y * xy.y); + vec2 new_xy = r < radius ? xy * (radius - h) / sqrt(radius * radius - r * r) : xy; + gl_FragColor = qt_Opacity * texture2D(source, (new_xy + center) / targetSize); +} diff --git a/demos/video/qmlvideofx/shaders/pagecurl.fsh b/demos/video/qmlvideofx/shaders/pagecurl.fsh new file mode 100644 index 0000000000..5334b869d6 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/pagecurl.fsh @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://rectalogic.github.com/webvfx/examples_2transition-shader-pagecurl_8html-example.html + +uniform float dividerValue; +uniform float curlExtent; +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +const float minAmount = -0.16; +const float maxAmount = 1.3; +const float PI = 3.141592653589793; +const float scale = 512.0; +const float sharpness = 3.0; +const vec4 bgColor = vec4(1.0, 1.0, 0.8, 1.0); + +float amount = curlExtent * (maxAmount - minAmount) + minAmount; +float cylinderCenter = amount; +// 360 degrees * amount +float cylinderAngle = 2.0 * PI * amount; +const float cylinderRadius = 1.0 / PI / 2.0; + +vec3 hitPoint(float hitAngle, float yc, vec3 point, mat3 rrotation) +{ + float hitPoint = hitAngle / (2.0 * PI); + point.y = hitPoint; + return rrotation * point; +} + +vec4 antiAlias(vec4 color1, vec4 color2, float distance) +{ + distance *= scale; + if (distance < 0.0) return color2; + if (distance > 2.0) return color1; + float dd = pow(1.0 - distance / 2.0, sharpness); + return ((color2 - color1) * dd) + color1; +} + +float distanceToEdge(vec3 point) +{ + float dx = abs(point.x > 0.5 ? 1.0 - point.x : point.x); + float dy = abs(point.y > 0.5 ? 1.0 - point.y : point.y); + if (point.x < 0.0) dx = -point.x; + if (point.x > 1.0) dx = point.x - 1.0; + if (point.y < 0.0) dy = -point.y; + if (point.y > 1.0) dy = point.y - 1.0; + if ((point.x < 0.0 || point.x > 1.0) && (point.y < 0.0 || point.y > 1.0)) return sqrt(dx * dx + dy * dy); + return min(dx, dy); +} + +vec4 seeThrough(float yc, vec2 p, mat3 rotation, mat3 rrotation) +{ + float hitAngle = PI - (acos(yc / cylinderRadius) - cylinderAngle); + vec3 point = hitPoint(hitAngle, yc, rotation * vec3(p, 1.0), rrotation); + if (yc <= 0.0 && (point.x < 0.0 || point.y < 0.0 || point.x > 1.0 || point.y > 1.0)) + return bgColor; + if (yc > 0.0) + return texture2D(source, p); + vec4 color = texture2D(source, point.xy); + vec4 tcolor = vec4(0.0); + return antiAlias(color, tcolor, distanceToEdge(point)); +} + +vec4 seeThroughWithShadow(float yc, vec2 p, vec3 point, mat3 rotation, mat3 rrotation) +{ + float shadow = distanceToEdge(point) * 30.0; + shadow = (1.0 - shadow) / 3.0; + if (shadow < 0.0) + shadow = 0.0; + else + shadow *= amount; + vec4 shadowColor = seeThrough(yc, p, rotation, rrotation); + shadowColor.r -= shadow; + shadowColor.g -= shadow; + shadowColor.b -= shadow; + return shadowColor; +} + +vec4 backside(float yc, vec3 point) +{ + vec4 color = texture2D(source, point.xy); + float gray = (color.r + color.b + color.g) / 15.0; + gray += (8.0 / 10.0) * (pow(1.0 - abs(yc / cylinderRadius), 2.0 / 10.0) / 2.0 + (5.0 / 10.0)); + color.rgb = vec3(gray); + return color; +} + +void main(void) +{ + const float angle = 30.0 * PI / 180.0; + float c = cos(-angle); + float s = sin(-angle); + mat3 rotation = mat3( + c, s, 0, + -s, c, 0, + 0.12, 0.258, 1 + ); + c = cos(angle); + s = sin(angle); + mat3 rrotation = mat3( + c, s, 0, + -s, c, 0, + 0.15, -0.5, 1 + ); + vec3 point = rotation * vec3(qt_TexCoord0, 1.0); + float yc = point.y - cylinderCenter; + vec4 color = vec4(1.0, 0.0, 0.0, 1.0); + if (yc < -cylinderRadius) { + // See through to background + color = bgColor; + } else if (yc > cylinderRadius) { + // Flat surface + color = texture2D(source, qt_TexCoord0); + } else { + float hitAngle = (acos(yc / cylinderRadius) + cylinderAngle) - PI; + float hitAngleMod = mod(hitAngle, 2.0 * PI); + if ((hitAngleMod > PI && amount < 0.5) || (hitAngleMod > PI/2.0 && amount < 0.0)) { + color = seeThrough(yc, qt_TexCoord0, rotation, rrotation); + } else { + point = hitPoint(hitAngle, yc, point, rrotation); + if (point.x < 0.0 || point.y < 0.0 || point.x > 1.0 || point.y > 1.0) { + color = seeThroughWithShadow(yc, qt_TexCoord0, point, rotation, rrotation); + } else { + color = backside(yc, point); + vec4 otherColor; + if (yc < 0.0) { + float shado = 1.0 - (sqrt(pow(point.x - 0.5, 2.0) + pow(point.y - 0.5, 2.0)) / 0.71); + shado *= pow(-yc / cylinderRadius, 3.0); + shado *= 0.5; + otherColor = vec4(0.0, 0.0, 0.0, shado); + } else { + otherColor = texture2D(source, qt_TexCoord0); + } + color = antiAlias(color, otherColor, cylinderRadius - abs(yc)); + + // This second antialiasing step causes the shader to fail to render, on + // Symbian devices (tested so far using IVE3.5). Running out of scratch + // memory? + } + } + } + gl_FragColor = qt_Opacity * color; +} diff --git a/demos/video/qmlvideofx/shaders/pixelate.fsh b/demos/video/qmlvideofx/shaders/pixelate.fsh new file mode 100644 index 0000000000..577e2582af --- /dev/null +++ b/demos/video/qmlvideofx/shaders/pixelate.fsh @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/ + +uniform float dividerValue; +uniform float granularity; +uniform float targetWidth; +uniform float targetHeight; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec2 tc = qt_TexCoord0; + if (uv.x < dividerValue && granularity > 0.0) { + float dx = granularity / targetWidth; + float dy = granularity / targetHeight; + tc = vec2(dx*(floor(uv.x/dx) + 0.5), + dy*(floor(uv.y/dy) + 0.5)); + } + gl_FragColor = qt_Opacity * texture2D(source, tc); +} diff --git a/demos/video/qmlvideofx/shaders/posterize.fsh b/demos/video/qmlvideofx/shaders/posterize.fsh new file mode 100644 index 0000000000..2769aac2f6 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/posterize.fsh @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://www.geeks3d.com/20091027/shader-library-posterization-post-processing-effect-glsl/ + +uniform float dividerValue; +uniform float gamma; +uniform float numColors; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 c = vec4(0.0); + if (uv.x < dividerValue) { + vec3 x = texture2D(source, uv).rgb; + x = pow(x, vec3(gamma, gamma, gamma)); + x = x * numColors; + x = floor(x); + x = x / numColors; + x = pow(x, vec3(1.0/gamma)); + c = vec4(x, 1.0); + } else { + c = texture2D(source, uv); + } + gl_FragColor = qt_Opacity * c; +} diff --git a/demos/video/qmlvideofx/shaders/ripple.fsh b/demos/video/qmlvideofx/shaders/ripple.fsh new file mode 100644 index 0000000000..bd79c763b6 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/ripple.fsh @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://labs.qt.nokia.com/2011/03/22/the-convenient-power-of-qml-scene-graph/ + +uniform float dividerValue; +uniform float targetWidth; +uniform float targetHeight; +uniform float time; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +const float PI = 3.1415926535; +const int ITER = 7; +const float RATE = 0.1; +uniform float amplitude; +uniform float n; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec2 tc = uv; + vec2 p = vec2(-1.0 + 2.0 * gl_FragCoord.x / targetWidth, -1.0 + 2.0 * gl_FragCoord.y / targetHeight); + float diffx = 0.0; + float diffy = 0.0; + vec4 col; + if (uv.x < dividerValue) { + for (int i=0; i<ITER; ++i) { + float theta = float(i) * PI / float(ITER); + vec2 r = vec2(cos(theta) * p.x + sin(theta) * p.y, -1.0 * sin(theta) * p.x + cos(theta) * p.y); + float diff = (sin(2.0 * PI * n * (r.y + time * RATE)) + 1.0) / 2.0; + diffx += diff * sin(theta); + diffy += diff * cos(theta); + } + tc = 0.5*(vec2(1.0,1.0) + p) + amplitude * vec2(diffx, diffy); + } + gl_FragColor = qt_Opacity * texture2D(source, tc); +} diff --git a/demos/video/qmlvideofx/shaders/selectionpanel.fsh b/demos/video/qmlvideofx/shaders/selectionpanel.fsh new file mode 100644 index 0000000000..250accb143 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/selectionpanel.fsh @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/demos/video/qmlvideofx/shaders/sepia.fsh b/demos/video/qmlvideofx/shaders/sepia.fsh new file mode 100644 index 0000000000..46b0935ae9 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/sepia.fsh @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float dividerValue; +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 orig = texture2D(source, uv); + vec3 col = orig.rgb; + float y = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(y + 0.15, y + 0.07, y - 0.12, 1.0); + else + gl_FragColor = qt_Opacity * orig; +} diff --git a/demos/video/qmlvideofx/shaders/sharpen.fsh b/demos/video/qmlvideofx/shaders/sharpen.fsh new file mode 100644 index 0000000000..f4cbc67d39 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/sharpen.fsh @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float dividerValue; +uniform float amount; +const float step_w = 0.0015625; +const float step_h = 0.0027778; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +vec3 sharpen(vec3 t1, vec3 t2, vec3 t3, vec3 t4, vec3 t5, vec3 t6, vec3 t7, vec3 t8, vec3 t9) +{ + return -t1 - t2 - t3 - t4 + amount * t5 - t6 - t7 - t8 - t9; +} + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec3 t1 = texture2D(source, vec2(uv.x - step_w, uv.y - step_h)).rgb; + vec3 t2 = texture2D(source, vec2(uv.x, uv.y - step_h)).rgb; + vec3 t3 = texture2D(source, vec2(uv.x + step_w, uv.y - step_h)).rgb; + vec3 t4 = texture2D(source, vec2(uv.x - step_w, uv.y)).rgb; + vec3 t5 = texture2D(source, uv).rgb; + vec3 t6 = texture2D(source, vec2(uv.x + step_w, uv.y)).rgb; + vec3 t7 = texture2D(source, vec2(uv.x - step_w, uv.y + step_h)).rgb; + vec3 t8 = texture2D(source, vec2(uv.x, uv.y + step_h)).rgb; + vec3 t9 = texture2D(source, vec2(uv.x + step_w, uv.y + step_h)).rgb; + vec3 col = sharpen(t1, t2, t3, t4, t5, t6, t7, t8, t9); + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(col, 1.0); + else + gl_FragColor = qt_Opacity * texture2D(source, uv); +} diff --git a/demos/video/qmlvideofx/shaders/shockwave.fsh b/demos/video/qmlvideofx/shaders/shockwave.fsh new file mode 100644 index 0000000000..33c382657d --- /dev/null +++ b/demos/video/qmlvideofx/shaders/shockwave.fsh @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://www.geeks3d.com/20091116/shader-library-2d-shockwave-post-processing-filter-glsl/ + +uniform float centerX; +uniform float centerY; +uniform float dividerValue; +uniform float granularity; +uniform float time; +uniform float weight; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec2 tc = qt_TexCoord0; + vec2 center = vec2(centerX, centerY); + const vec3 shock = vec3(10.0, 1.5, 0.1); + if (uv.x < dividerValue) { + float distance = distance(uv, center); + if ((distance <= (time + shock.z)) && + (distance >= (time - shock.z))) { + float diff = (distance - time); + float powDiff = 1.0 - pow(abs(diff*shock.x), shock.y*weight); + float diffTime = diff * powDiff; + vec2 diffUV = normalize(uv - center); + tc += (diffUV * diffTime); + } + } + gl_FragColor = qt_Opacity * texture2D(source, tc); +} diff --git a/demos/video/qmlvideofx/shaders/sobeledgedetection1.fsh b/demos/video/qmlvideofx/shaders/sobeledgedetection1.fsh new file mode 100644 index 0000000000..d71b4e8336 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/sobeledgedetection1.fsh @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on "Graphics Shaders: Theory and Practice" (http://cgeducation.org/ShadersBook/) + +uniform float dividerValue; +uniform float mixLevel; +uniform float resS; +uniform float resT; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 c = vec4(0.0); + if (uv.x < dividerValue) { + vec2 st = qt_TexCoord0.st; + vec3 irgb = texture2D(source, st).rgb; + vec2 stp0 = vec2(1.0 / resS, 0.0); + vec2 st0p = vec2(0.0 , 1.0 / resT); + vec2 stpp = vec2(1.0 / resS, 1.0 / resT); + vec2 stpm = vec2(1.0 / resS, -1.0 / resT); + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + float i00 = dot(texture2D(source, st).rgb, W); + float im1m1 = dot(texture2D(source, st-stpp).rgb, W); + float ip1p1 = dot(texture2D(source, st+stpp).rgb, W); + float im1p1 = dot(texture2D(source, st-stpm).rgb, W); + float ip1m1 = dot(texture2D(source, st+stpm).rgb, W); + float im10 = dot(texture2D(source, st-stp0).rgb, W); + float ip10 = dot(texture2D(source, st+stp0).rgb, W); + float i0m1 = dot(texture2D(source, st-st0p).rgb, W); + float i0p1 = dot(texture2D(source, st+st0p).rgb, W); + float h = -1.0*im1p1 - 2.0*i0p1 - 1.0*ip1p1 + 1.0*im1m1 + 2.0*i0m1 + 1.0*ip1m1; + float v = -1.0*im1m1 - 2.0*im10 - 1.0*im1p1 + 1.0*ip1m1 + 2.0*ip10 + 1.0*ip1p1; + float mag = 1.0 - length(vec2(h, v)); + vec3 target = vec3(mag, mag, mag); + c = vec4(target, 1.0); + } else { + c = texture2D(source, qt_TexCoord0); + } + gl_FragColor = qt_Opacity * c; +} diff --git a/demos/video/qmlvideofx/shaders/sobeledgedetection2.fsh b/demos/video/qmlvideofx/shaders/sobeledgedetection2.fsh new file mode 100644 index 0000000000..bb97da10b6 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/sobeledgedetection2.fsh @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://rastergrid.com/blog/downloads/frei-chen-edge-detector/ + +#version 130 +uniform sampler2D source; +uniform float dividerValue; +uniform float weight; +mat3 G[2] = mat3[]( + mat3( 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0 ), + mat3( 1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0 ) +); +uniform lowp float qt_Opacity; +in vec2 qt_TexCoord0; +out vec4 FragmentColor; +void main() { + vec2 uv = qt_TexCoord0.xy; + vec4 c = vec4(0.0); + if (uv.x < dividerValue) { + mat3 intensity; + float conv[2]; + vec3 sample; + for (int i=0; i<3; ++i) { + for (int j=0; j<3; ++j) { + sample = texelFetch(source, ivec2(gl_FragCoord) + ivec2(i-1, j-1), 0).rgb; + intensity[i][j] = length(sample) * weight; + } + } + for (int i=0; i<2; ++i) { + float dp3 = dot(G[i][0], intensity[0]) + dot(G[i][1], intensity[1]) + dot(G[i][2], intensity[2]); + conv[i] = dp3 * dp3; + } + c = vec4(0.5 * sqrt(conv[0]*conv[0] + conv[1]*conv[1])); + } else { + c = texture2D(source, qt_TexCoord0); + } + FragmentColor = qt_Opacity * c; +} diff --git a/demos/video/qmlvideofx/shaders/tiltshift.fsh b/demos/video/qmlvideofx/shaders/tiltshift.fsh new file mode 100644 index 0000000000..4323e7f008 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/tiltshift.fsh @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float dividerValue; +const float step_w = 0.0015625; +const float step_h = 0.0027778; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +vec3 blur() +{ + vec2 uv = qt_TexCoord0.xy; + float y = uv.y < 0.4 ? uv.y : 1.0 - uv.y; + float dist = 8.0 - 20.0 * y; + vec3 acc = vec3(0.0, 0.0, 0.0); + for (float y=-2.0; y<=2.0; ++y) { + for (float x=-2.0; x<=2.0; ++x) { + acc += texture2D(source, vec2(uv.x + dist * x * step_w, uv.y + 0.5 * dist * y * step_h)).rgb; + } + } + return acc / 25.0; +} + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec3 col; + if (uv.x < dividerValue && uv.y >= 0.4 && uv.y <= 0.6) + col = texture2D(source, uv).rgb; + else + col = blur(); + gl_FragColor = qt_Opacity * vec4(col, 1.0); +} diff --git a/demos/video/qmlvideofx/shaders/toon.fsh b/demos/video/qmlvideofx/shaders/toon.fsh new file mode 100644 index 0000000000..5c895fa3dc --- /dev/null +++ b/demos/video/qmlvideofx/shaders/toon.fsh @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/ + +uniform float dividerValue; +uniform float threshold; +uniform float resS; +uniform float resT; +uniform float magTol; +uniform float quantize; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec4 color = vec4(1.0, 0.0, 0.0, 1.1); + vec2 uv = qt_TexCoord0.xy; + if (uv.x < dividerValue) { + vec2 st = qt_TexCoord0.st; + vec3 rgb = texture2D(source, st).rgb; + vec2 stp0 = vec2(1.0/resS, 0.0); + vec2 st0p = vec2(0.0 , 1.0/resT); + vec2 stpp = vec2(1.0/resS, 1.0/resT); + vec2 stpm = vec2(1.0/resS, -1.0/resT); + float i00 = dot( texture2D(source, st).rgb, vec3(0.2125,0.7154,0.0721)); + float im1m1 = dot( texture2D(source, st-stpp).rgb, vec3(0.2125,0.7154,0.0721)); + float ip1p1 = dot( texture2D(source, st+stpp).rgb, vec3(0.2125,0.7154,0.0721)); + float im1p1 = dot( texture2D(source, st-stpm).rgb, vec3(0.2125,0.7154,0.0721)); + float ip1m1 = dot( texture2D(source, st+stpm).rgb, vec3(0.2125,0.7154,0.0721)); + float im10 = dot( texture2D(source, st-stp0).rgb, vec3(0.2125,0.7154,0.0721)); + float ip10 = dot( texture2D(source, st+stp0).rgb, vec3(0.2125,0.7154,0.0721)); + float i0m1 = dot( texture2D(source, st-st0p).rgb, vec3(0.2125,0.7154,0.0721)); + float i0p1 = dot( texture2D(source, st+st0p).rgb, vec3(0.2125,0.7154,0.0721)); + float h = -1.*im1p1 - 2.*i0p1 - 1.*ip1p1 + 1.*im1m1 + 2.*i0m1 + 1.*ip1m1; + float v = -1.*im1m1 - 2.*im10 - 1.*im1p1 + 1.*ip1m1 + 2.*ip10 + 1.*ip1p1; + float mag = sqrt(h*h + v*v); + if (mag > magTol) { + color = vec4(0.0, 0.0, 0.0, 1.0); + } + else { + rgb.rgb *= quantize; + rgb.rgb += vec3(0.5, 0.5, 0.5); + ivec3 irgb = ivec3(rgb.rgb); + rgb.rgb = vec3(irgb) / quantize; + color = vec4(rgb, 1.0); + } + } else { + color = texture2D(source, uv); + } + gl_FragColor = qt_Opacity * color; +} diff --git a/demos/video/qmlvideofx/shaders/vignette.fsh b/demos/video/qmlvideofx/shaders/vignette.fsh new file mode 100644 index 0000000000..6f89f192e5 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/vignette.fsh @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float dividerValue; +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 orig = texture2D(source, uv); + float cr = pow(0.1, 2.0); + float pt = pow(uv.x - 0.5, 2.0) + pow(uv.y - 0.5, 2.0); + float d = pt - cr; + float cf = 1.0; + if (d > 0.0) + cf = 1.0 - 2.0 * d; + vec3 col = cf * orig.rgb; + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(col, 1.0); + else + gl_FragColor = qt_Opacity * orig; +} diff --git a/demos/video/qmlvideofx/shaders/warhol.fsh b/demos/video/qmlvideofx/shaders/warhol.fsh new file mode 100644 index 0000000000..5bd438e562 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/warhol.fsh @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://kodemongki.blogspot.com/2011/06/kameraku-custom-shader-effects-example.html + +uniform float dividerValue; +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec4 orig = texture2D(source, uv); + vec3 col = orig.rgb; + float y = 0.3 *col.r + 0.59 * col.g + 0.11 * col.b; + y = y < 0.3 ? 0.0 : (y < 0.6 ? 0.5 : 1.0); + if (y == 0.5) + col = vec3(0.8, 0.0, 0.0); + else if (y == 1.0) + col = vec3(0.9, 0.9, 0.0); + else + col = vec3(0.0, 0.0, 0.0); + if (uv.x < dividerValue) + gl_FragColor = qt_Opacity * vec4(col, 1.0); + else + gl_FragColor = qt_Opacity * orig; +} diff --git a/demos/video/qmlvideofx/shaders/wobble.fsh b/demos/video/qmlvideofx/shaders/wobble.fsh new file mode 100644 index 0000000000..5a8771d216 --- /dev/null +++ b/demos/video/qmlvideofx/shaders/wobble.fsh @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Based on http://labs.qt.nokia.com/2011/03/22/the-convenient-power-of-qml-scene-graph/ + +uniform float amplitude; +uniform float dividerValue; +uniform float frequency; +uniform float time; + +uniform sampler2D source; +uniform lowp float qt_Opacity; +varying vec2 qt_TexCoord0; + +void main() +{ + vec2 uv = qt_TexCoord0.xy; + vec2 tc = qt_TexCoord0; + if (uv.x < dividerValue) { + vec2 p = sin(time + frequency * qt_TexCoord0); + tc += amplitude * vec2(p.y, -p.x); + } + gl_FragColor = qt_Opacity * texture2D(source, tc); +} |