Pages with various effects for the Demo applet
This demo shows very simple and slightly more complex shaders used with Plasma Components.
This commit is contained in:
parent
ca81fda6e7
commit
905080a416
17
src/shell/applets/testshaderapplet/contents/config/main.xml
Normal file
17
src/shell/applets/testshaderapplet/contents/config/main.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
|
||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
|
||||
<kcfgfile name=""/>
|
||||
|
||||
<group name="General">
|
||||
<entry name="Speed" type="int">
|
||||
<label>Speed of the leaves</label>
|
||||
<default>60</default>
|
||||
<min>20</min>
|
||||
<max>150</max>
|
||||
</entry>
|
||||
</group>
|
||||
|
||||
</kcfg>
|
Binary file not shown.
After Width: | Height: | Size: 85 KiB |
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
ShaderExample {
|
||||
|
||||
pageName: "Colors"
|
||||
pageDescription: ""
|
||||
|
||||
ShaderEffect {
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 48
|
||||
opacity: 0.2
|
||||
|
||||
fragmentShader: {
|
||||
"uniform mat4 gl_ModelViewMatrix;" +
|
||||
"uniform mat4 gl_ProjectionMatrix;" +
|
||||
//"attribute vec4 gl_Vertex;" +
|
||||
"void main(void) {" +
|
||||
" gl_FragColor = vec4(1.0, 0.0, 0.0, 0.3); " +
|
||||
" gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; " +
|
||||
"}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
121
src/shell/applets/testshaderapplet/contents/ui/ColorShower.qml
Normal file
121
src/shell/applets/testshaderapplet/contents/ui/ColorShower.qml
Normal file
@ -0,0 +1,121 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Particles 2.0
|
||||
|
||||
ShaderExample {
|
||||
|
||||
pageName: "Particles"
|
||||
pageDescription: "Fun rainbow colors using a fragment shader"
|
||||
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
anchors.margins: -_s
|
||||
ParticleSystem {
|
||||
id: psItem
|
||||
//anchors.fill: parent
|
||||
x: parent.width / 2
|
||||
y: parent.height / 2
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
// clip: true
|
||||
anchors.topMargin: 48
|
||||
//anchors.leftMargin: 42
|
||||
|
||||
Emitter {
|
||||
emitRate: 400
|
||||
lifeSpan: 8000
|
||||
size: 24
|
||||
sizeVariation: 16
|
||||
velocity: PointDirection {x: psItem.width/20; y: psItem.height/20;}
|
||||
acceleration: PointDirection {x: -psItem.width/40; y: -psItem.height/40; xVariation: -psItem.width/20; yVariation: -psItem.width/20}
|
||||
}
|
||||
|
||||
CustomParticle {
|
||||
vertexShader:"
|
||||
uniform lowp float qt_Opacity;
|
||||
varying lowp float fFade;
|
||||
varying highp vec2 fPos;
|
||||
|
||||
void main() {
|
||||
qt_TexCoord0 = qt_ParticleTex;
|
||||
highp float size = qt_ParticleData.z;
|
||||
highp float endSize = qt_ParticleData.w;
|
||||
|
||||
highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y;
|
||||
|
||||
highp float currentSize = mix(size, endSize, t * t);
|
||||
|
||||
if (t < 0. || t > 1.)
|
||||
currentSize = 0.;
|
||||
|
||||
highp vec2 pos = qt_ParticlePos
|
||||
- currentSize / 2. + currentSize * qt_ParticleTex // adjust size
|
||||
+ qt_ParticleVec.xy * t * qt_ParticleData.y // apply velocity vector..
|
||||
+ 0.5 * qt_ParticleVec.zw * pow(t * qt_ParticleData.y, 2.);
|
||||
|
||||
gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
|
||||
|
||||
highp float fadeIn = min(t * 20., 1.);
|
||||
highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
|
||||
|
||||
fFade = fadeIn * fadeOut * qt_Opacity;
|
||||
fPos = vec2(pos.x/320., pos.y/480.);
|
||||
}
|
||||
"
|
||||
//! [0]
|
||||
fragmentShader: "
|
||||
varying highp vec2 fPos;
|
||||
varying lowp float fFade;
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
void main() {//*2 because this generates dark colors mostly
|
||||
highp vec2 circlePos = qt_TexCoord0*2.0 - vec2(1.0,1.0);
|
||||
highp float dist = length(circlePos);
|
||||
highp float circleFactor = max(min(1.0 - dist, 1.0), 0.0);
|
||||
gl_FragColor = vec4(fPos.x*2.0 - fPos.y, fPos.y*2.0 - fPos.x, fPos.x*fPos.y*2.0, 0.0) * circleFactor * fFade;
|
||||
}"
|
||||
//! [0]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -68,7 +68,7 @@ PlasmaComponents.Page {
|
||||
onClicked: {
|
||||
mainShader.fragmentShader = "";
|
||||
mainShader.vertexShader = "";
|
||||
fragmentPage.shader = ""
|
||||
editorPage.shader = ""
|
||||
vertexPage.shader = ""
|
||||
}
|
||||
}
|
||||
|
110
src/shell/applets/testshaderapplet/contents/ui/WaterEffect.qml
Normal file
110
src/shell/applets/testshaderapplet/contents/ui/WaterEffect.qml
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
||||
import org.kde.plasma.components 0.1 as PlasmaComponents
|
||||
import org.kde.plasma.extras 0.1 as PlasmaExtras
|
||||
import org.kde.qtextracomponents 0.1 as QtExtras
|
||||
|
||||
// VertexPage
|
||||
|
||||
Item {
|
||||
id: waterRoot
|
||||
property alias sourceItem: effectsource.sourceItem
|
||||
property bool waving: true
|
||||
//anchors.top: parent.bottom
|
||||
anchors.top: iconCol.bottom
|
||||
width: sourceItem.width
|
||||
height: sourceItem.height
|
||||
|
||||
ShaderEffect {
|
||||
anchors.fill: parent
|
||||
property variant source: effectsource
|
||||
property real f: 0
|
||||
property real f2: 0
|
||||
property real intensity: 1
|
||||
smooth: true
|
||||
|
||||
ShaderEffectSource {
|
||||
id: effectsource
|
||||
//hideSource: false
|
||||
//smooth: true
|
||||
sourceItem: mainItem
|
||||
}
|
||||
|
||||
fragmentShader:
|
||||
"
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform sampler2D source;
|
||||
uniform lowp float qt_Opacity;
|
||||
uniform highp float f;
|
||||
uniform highp float f2;
|
||||
uniform highp float intensity;
|
||||
|
||||
void main() {
|
||||
const highp float twopi = 3.141592653589 * 2.0;
|
||||
|
||||
highp float distanceFactorToPhase = pow(qt_TexCoord0.y + 0.5, 8.0) * 5.0;
|
||||
highp float ofx = sin(f * twopi + distanceFactorToPhase) / 100.0;
|
||||
highp float ofy = sin(f2 * twopi + distanceFactorToPhase * qt_TexCoord0.x) / 60.0;
|
||||
|
||||
highp float intensityDampingFactor = (qt_TexCoord0.x + 0.1) * (qt_TexCoord0.y + 0.2);
|
||||
highp float distanceFactor = (1.0 - qt_TexCoord0.y) * 4.0 * intensity * intensityDampingFactor;
|
||||
|
||||
ofx *= distanceFactor;
|
||||
ofy *= distanceFactor;
|
||||
|
||||
highp float x = qt_TexCoord0.x + ofx;
|
||||
highp float y = 1.0 - qt_TexCoord0.y + ofy;
|
||||
|
||||
highp float fake = (sin((ofy + ofx) * twopi) + 0.5) * 0.05 * (1.2 - qt_TexCoord0.y) * intensity * intensityDampingFactor;
|
||||
|
||||
highp vec4 pix =
|
||||
texture2D(source, vec2(x, y)) * 0.6 +
|
||||
texture2D(source, vec2(x-fake, y)) * 0.15 +
|
||||
texture2D(source, vec2(x, y-fake)) * 0.15 +
|
||||
texture2D(source, vec2(x+fake, y)) * 0.15 +
|
||||
texture2D(source, vec2(x, y+fake)) * 0.15;
|
||||
|
||||
highp float darken = 0.6 - (ofx - ofy) / 2.0;
|
||||
pix.b *= 1.2 * darken;
|
||||
pix.r *= 0.9 * darken;
|
||||
pix.g *= darken;
|
||||
|
||||
gl_FragColor = qt_Opacity * vec4(pix.r, pix.g, pix.b, 1.0);
|
||||
}
|
||||
"
|
||||
|
||||
NumberAnimation on f {
|
||||
running: waterRoot.waving
|
||||
loops: Animation.Infinite
|
||||
from: 0
|
||||
to: 1
|
||||
duration: 2410
|
||||
}
|
||||
NumberAnimation on f2 {
|
||||
running: waterRoot.waving
|
||||
loops: Animation.Infinite
|
||||
from: 0
|
||||
to: 1
|
||||
duration: 1754
|
||||
}
|
||||
}
|
||||
}
|
141
src/shell/applets/testshaderapplet/contents/ui/WobbleExample.qml
Normal file
141
src/shell/applets/testshaderapplet/contents/ui/WobbleExample.qml
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
||||
import org.kde.plasma.components 0.1 as PlasmaComponents
|
||||
|
||||
ShaderExample {
|
||||
|
||||
pageName: "Wobble"
|
||||
pageDescription: "Makes an image wobble"
|
||||
|
||||
Grid {
|
||||
id: cfgrid
|
||||
columns: 2
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
width: parent.width * 0.6
|
||||
height: 96
|
||||
spacing: 6
|
||||
columnSpacing: _m
|
||||
PlasmaComponents.Label {
|
||||
text: "Amplitude (" + amplitudeSlider.value +"):";
|
||||
width: parent.width * 0.5;
|
||||
elide: Text.ElideRight
|
||||
// height: 24
|
||||
}
|
||||
PlasmaComponents.Slider {
|
||||
width: parent.width * 0.4
|
||||
id: amplitudeSlider
|
||||
stepSize: 0.05
|
||||
minimumValue: 0
|
||||
maximumValue: 1.0
|
||||
value: 0.4
|
||||
}
|
||||
|
||||
PlasmaComponents.Label {
|
||||
text: "Speed (" + speedSlider.value +"):";
|
||||
elide: Text.ElideRight
|
||||
// width: parent.width * 0.4;
|
||||
// height: 24
|
||||
}
|
||||
PlasmaComponents.Slider {
|
||||
width: parent.width * 0.4
|
||||
id: speedSlider
|
||||
stepSize: 250
|
||||
minimumValue: 0
|
||||
maximumValue: 6000
|
||||
value: 3000
|
||||
onValueChanged: {
|
||||
timeAnimation.duration = maximumValue - value +1;
|
||||
timeAnimation.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
PlasmaComponents.Button {
|
||||
anchors { right: parent.right; bottom: parent.bottom; }
|
||||
// height: theme.iconSizes.toolbar
|
||||
text: "Busy"
|
||||
checked: plasmoid.busy
|
||||
onClicked: {
|
||||
plasmoid.busy = !plasmoid.busy
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Item {
|
||||
id: imageItem
|
||||
opacity: 0.0
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 48
|
||||
Image {
|
||||
source: "../images/elarun-small.png"
|
||||
anchors.fill: parent
|
||||
anchors.margins: parent.height / 10
|
||||
}
|
||||
}
|
||||
|
||||
PlasmaCore.IconItem {
|
||||
id: iconItem
|
||||
source: "plasma"
|
||||
width: 400
|
||||
height: 400
|
||||
// width: parent.height
|
||||
// height: width
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: wobbleShader
|
||||
|
||||
anchors.fill: iconItem
|
||||
//property real time
|
||||
property variant mouse
|
||||
property variant resolution
|
||||
|
||||
property int fadeDuration: 2500
|
||||
property real amplitude: 0.04 * amplitudeSlider.value
|
||||
property real frequency: 20
|
||||
property real time: 10
|
||||
property int speed: (speedSlider.maximumValue - speedSlider.value + 1)
|
||||
|
||||
property variant source: ShaderEffectSource {
|
||||
sourceItem: iconItem
|
||||
hideSource: true
|
||||
}
|
||||
|
||||
NumberAnimation on time { id: timeAnimation; loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 3000 }
|
||||
Behavior on amplitude { NumberAnimation { duration: wobbleShader.fadeDuration } }
|
||||
|
||||
fragmentShader: { //mainItem.opacity = 0;
|
||||
"uniform lowp float qt_Opacity;" +
|
||||
"uniform highp float amplitude;" +
|
||||
"uniform highp float frequency;" +
|
||||
"uniform highp float time;" +
|
||||
"uniform sampler2D source;" +
|
||||
"varying highp vec2 qt_TexCoord0;" +
|
||||
"void main() {" +
|
||||
" highp vec2 p = sin(time + frequency * qt_TexCoord0);" +
|
||||
" gl_FragColor = texture2D(source, qt_TexCoord0 + amplitude * vec2(p.y, -p.x)) * qt_Opacity;" +
|
||||
"}"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
30
src/shell/applets/testshaderapplet/contents/ui/config.qml
Normal file
30
src/shell/applets/testshaderapplet/contents/ui/config.qml
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
// import org.kde.plasma.components 0.1 as PlasmaComponents
|
||||
// import org.kde.plasma.extras 0.1 as PlasmaExtras
|
||||
|
||||
Column {
|
||||
id: root
|
||||
//property alias cfg_Speed
|
||||
Rectangle { color: "green"; width: 200; height: 300; }
|
||||
// PlasmaExtras.Heading {
|
||||
// text: "Applet Config:"
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue
Block a user