New test applet for shader experiments

This commit is contained in:
Sebastian Kügler 2013-03-09 01:57:42 +01:00
parent 64892e1c4e
commit 749e88af02
10 changed files with 578 additions and 0 deletions

View File

@ -1,3 +1,4 @@
installPackage(testapplet org.kde.testapplet)
installPackage(testcomponentsapplet org.kde.testcomponentsapplet)
installPackage(testshaderapplet org.kde.testshaderapplet)

View File

@ -0,0 +1,78 @@
/*
* 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
// ButtonsPage
PlasmaComponents.Page {
id: editorPage
property string shader
property alias shaderText: editor.text
property string pageName: "Shaders"
property string icon: "preferences-desktop-mouse"
anchors {
fill: parent
margins: _s
}
PlasmaExtras.Heading {
id: heading
level: 1
anchors {
top: parent.top;
left: parent.left
right: parent.right
}
text: pageName
}
PlasmaComponents.TextArea {
id: editor
anchors {
top: heading.bottom;
topMargin: _s
left: parent.left
right: parent.right
bottom: applyButton.top
bottomMargin: _s
}
// width: parent.width
// parent.height-height: _h*2
}
PlasmaComponents.Button {
id: applyButton
text: "Upload Shader"
onClicked: shader = editor.text
anchors {
right: parent.right
bottom: parent.bottom
}
}
}

View File

@ -0,0 +1,111 @@
/*
* 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
// ButtonsPage
PlasmaComponents.Page {
id: examplesPage
//property string shader
property string pageName: "Shader Examples"
property string icon: "weather-clear"
anchors {
fill: parent
margins: _s
}
PlasmaExtras.Heading {
id: heading
level: 1
anchors {
top: parent.top;
left: parent.left
right: parent.right
}
text: pageName
}
SimpleExample {
id: simpleShader
//parent: root
anchors.fill: examplesPage
parent: examplesPage.parent
opacity: 0.2
//source: effectSource
}
Image {
id: imageItem
width: 200
height: 160
anchors.centerIn: parent
///source: "http://vizzzion.org/blog/wp-content/uploads/2013/01/ktouch.png"
source: "file:///home/sebas/Pictures/Damselfly.jpg"
}
TubeExample {
id: tubeShader
anchors.fill: imageItem
source: ShaderEffectSource {
//sourceRect: Qt.rect(-50, -50, width+100, height+100)
//sourceRect: Qt.rect(10, 20, 50, 80)
sourceItem: imageItem
hideSource: hideSourceCheckbox.checked
}
}
GridView {
id: grid
anchors {
top: heading.bottom;
topMargin: _s
left: parent.left
right: parent.right
bottom: applyButton.top
bottomMargin: _s
}
model: VisualItemModel {
PlasmaComponents.Button {
checkable: true;
text: "Simple";
onClicked: {
simpleShader.visible = checked;
// fragmentPage.shaderText = simpleShader.fragmentShader;
// vertexPage.shaderText = simpleShader.vertexShader;
}
}
PlasmaComponents.Button {
checkable: true;
text: "Tube";
onClicked: {
tubeShader.visible = checked;
mainItem.opacity = checked ? 0.1 : 0.1
// fragmentPage.shaderText = tubeShader.fragmentShader;
// vertexPage.shaderText = tubeShader.vertexShader;
}
}
}
}
}

View File

@ -0,0 +1,44 @@
/*
* 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
// FragmentPage
EditorPage {
id: fragmentPage
pageName: "Fragment Shader"
icon: "preferences-desktop-color"
shader: ""
shaderText: { "void main(void) {\
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.3);\
}"
}
onShaderChanged: {
print("Uploading fragment shader: \n" + shader);
mainShader.fragmentShader = shader;
}
}

View File

@ -0,0 +1,41 @@
/*
* 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
ShaderEffect {
visible: false
//parent: root
//anchors.fill: source.sourceItem
property variant source: ShaderEffectSource {
sourceItem: mainItem
hideSource: true
}
//property variant source: effectSource
}

View File

@ -0,0 +1,38 @@
/*
* 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
ShaderExample {
// parent: root
fragmentShader: { " \
void main(void) { \
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.3); \
} \
"
}
}

View File

@ -0,0 +1,87 @@
/*
* 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
ShaderExample {
//anchors.fill: imageItem
//property real time
property variant mouse
property variant resolution
property int fadeDuration: 250
property real amplitude: 0.04 * 0.4
property real frequency: 20
property real time: 0
// source: ShaderEffectSource {
// sourceItem: imageItem
// hideSource: true
// }
//
NumberAnimation on time { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 600 }
Behavior on amplitude { NumberAnimation { duration: fadeDuration } }
//vertexShader: ""
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;" +
"}"
/*
fragmentShader: {
"uniform float time; \
uniform vec2 mouse; \
uniform vec2 resolution; \
void main( void ) \
{ \
// vec2 uPos = ( gl_FragCoord.xy / resolution.xy );//normalize wrt y axis \
// //suPos -= vec2((resolution.x/resolution.y)/2.0, 0.0);//shift origin to center \
// uPos.x -= 8.0; \
// uPos.y -= 0.5; \
// vec3 color = vec3(0.0); \
// float vertColor = 0.0; \
// for( float i = 0.0; i < 15.0; ++i ) { \
// float t = time * (0.9); \
// uPos.y += sin( uPos.x*i + t+i/2.0 ) * 0.1; \
// float fTemp = abs(1.0 / uPos.y / 100.0); \
// vertColor += fTemp; \
// color += vec3( fTemp*(10.0-i)/10.0, fTemp*i/10.0, pow(fTemp,1.5)*1.5 ); \
// } \
// vec4 color_final = vec4(color, 1.0); \
// gl_FragColor = color_final; \
} \
"
*/
}
}

View File

@ -0,0 +1,40 @@
/*
* 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
EditorPage {
id: vertexPage
pageName: "Vertex Shader"
icon: "transform-shear-down"
shader: ""
onShaderChanged: {
print("Uploading new vertex shader: \n" + shader);
mainShader.vertexShader = shader;
}
}

View File

@ -0,0 +1,120 @@
/*
* 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
Item {
id: root
width: 400
height: 400
property int _s: theme.iconSizes.small
property int _h: theme.iconSizes.desktop
PlasmaCore.DataSource {
id: dataSource
}
Item {
id: mainItem
anchors.fill: parent
PlasmaComponents.TabBar {
id: tabBar
anchors {
left: parent.left
right: parent.right
top: parent.top
}
height: _h
PlasmaComponents.TabButton { tab: examplesPage; iconSource: examplesPage.icon; }
PlasmaComponents.TabButton { tab: vertexPage; iconSource: vertexPage.icon; }
PlasmaComponents.TabButton { tab: fragmentPage; iconSource: fragmentPage.icon; }
}
PlasmaComponents.TabGroup {
id: tabGroup
anchors {
left: parent.left
right: parent.right
top: tabBar.bottom
bottom: parent.bottom
}
//currentTab: tabBar.currentTab
ExamplesPage {
id: examplesPage
}
VertexPage {
id: vertexPage
}
FragmentPage {
id: fragmentPage
}
}
}
ShaderEffectSource {
id: effectSource
sourceItem: mainItem
hideSource: hideSourceCheckbox.checked
}
ShaderEffect {
id: mainShader
anchors.fill: mainItem
property variant source: effectSource
property real f: 0
property real f2: 0
property int intensity: 1
smooth: true
}
PlasmaComponents.CheckBox {
id: hideSourceCheckbox
text: "Hide Source Item"
anchors { bottom: parent.bottom; left: parent.left; margins: _s; }
onCheckedChanged: effectSource.hideSource = checked
}
PlasmaComponents.ToolButton {
iconSource: "dialog-close"
width: _h
height: width
visible: !(mainShader.fragmentShader == "" && mainShader.vertexShader == "")
anchors { top: parent.top; right: parent.right; }
onClicked: {
mainShader.fragmentShader = "";
mainShader.vertexShader = "";
fragmentPage.shader = ""
vertexPage.shader = ""
}
}
Component.onCompleted: {
print("Shader Test Applet loaded");
}
}

View File

@ -0,0 +1,18 @@
[Desktop Entry]
Encoding=UTF-8
Keywords=
Name=Shader Test
Type=Service
Icon=plasma
X-KDE-ServiceTypes=Plasma/Applet
X-Plasma-API=declarativeappletscript
X-KDE-ParentApp=
X-KDE-PluginInfo-Author=Sebastian Kügler
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Email=sebas@kde.org
X-KDE-PluginInfo-License=GPLv2+
X-KDE-PluginInfo-Name=org.kde.testshaderapplet
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-Plasma-MainScript=ui/testshaderapplet.qml