aboutsummaryrefslogtreecommitdiffstats
path: root/examples/particles/customparticle
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2012-06-18 14:13:31 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-29 04:05:44 +0200
commitf4e75e134f5712156ad2b720b48265da683dda94 (patch)
treed521ea46a3222f6e31f5e646b8dc35b7125e6abc /examples/particles/customparticle
parent5df94d89033e7bbb3f41840a4c07a628ed66b4d5 (diff)
Update particles examples en masse
Change-Id: I882f59c687d790bc55cf59abf6f0ea80b65b50d9 Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Diffstat (limited to 'examples/particles/customparticle')
-rw-r--r--examples/particles/customparticle/content/blurparticles.qml (renamed from examples/particles/customparticle/blurparticles.qml)6
-rw-r--r--examples/particles/customparticle/content/fragmentshader.qml (renamed from examples/particles/customparticle/fragmentshader.qml)11
-rw-r--r--examples/particles/customparticle/content/imagecolors.qml (renamed from examples/particles/customparticle/imagecolors.qml)14
-rw-r--r--examples/particles/customparticle/customparticle.pro10
-rw-r--r--examples/particles/customparticle/customparticle.qml84
-rw-r--r--examples/particles/customparticle/customparticle.qmlproject16
-rw-r--r--examples/particles/customparticle/main.cpp41
7 files changed, 173 insertions, 9 deletions
diff --git a/examples/particles/customparticle/blurparticles.qml b/examples/particles/customparticle/content/blurparticles.qml
index 9b432e093d..c1ad03b04b 100644
--- a/examples/particles/customparticle/blurparticles.qml
+++ b/examples/particles/customparticle/content/blurparticles.qml
@@ -63,11 +63,12 @@ Rectangle {
}
Image {
id: theItem
- source: "../images/starfish_1.png"
+ source: "../../images/starfish_1.png"
}
CustomParticle {
system: sys
+ //! [vertex]
vertexShader:"
uniform lowp float qt_Opacity;
varying lowp float fFade;
@@ -83,6 +84,7 @@ Rectangle {
fBlur = max(0.2 * t, t * qt_ParticleR);
}
"
+ //! [vertex]
property variant source: theSource
property variant blurred: ShaderEffectSource {
smooth: true
@@ -125,6 +127,7 @@ Rectangle {
}"
}
}
+ //! [fragment]
fragmentShader: "
uniform sampler2D source;
uniform sampler2D blurred;
@@ -134,6 +137,7 @@ Rectangle {
void main() {
gl_FragColor = mix(texture2D(source, qt_TexCoord0), texture2D(blurred, qt_TexCoord0), min(1.0,fBlur*3.0)) * fFade;
}"
+ //! [fragment]
}
}
diff --git a/examples/particles/customparticle/fragmentshader.qml b/examples/particles/customparticle/content/fragmentshader.qml
index 367cc99b7b..e2f4f92f08 100644
--- a/examples/particles/customparticle/fragmentshader.qml
+++ b/examples/particles/customparticle/content/fragmentshader.qml
@@ -43,8 +43,8 @@ import QtQuick.Particles 2.0
ParticleSystem {
id: root
- width: 1024
- height: 768
+ width: 320
+ height: 480
Rectangle {
z: -1
anchors.fill: parent
@@ -52,7 +52,7 @@ ParticleSystem {
Text {
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
- font.pixelSize: 36
+ font.pixelSize: 14
color: "white"
text: "It's all in the fragment shader."
}
@@ -64,7 +64,6 @@ ParticleSystem {
size: 24
sizeVariation: 16
velocity: PointDirection {x: root.width/10; y: root.height/10;}
- //acceleration: AngledDirection {angle:225; magnitude: root.width/36; angleVariation: 45; magnitudeVariation: 80}
acceleration: PointDirection {x: -root.width/40; y: -root.height/40; xVariation: -root.width/20; yVariation: -root.width/20}
}
@@ -97,9 +96,10 @@ ParticleSystem {
highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
fFade = fadeIn * fadeOut * qt_Opacity;
- fPos = vec2(pos.x/1024., pos.y/768.);
+ fPos = vec2(pos.x/320., pos.y/480.);
}
"
+ //! [0]
fragmentShader: "
varying highp vec2 fPos;
varying lowp float fFade;
@@ -110,6 +110,7 @@ ParticleSystem {
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]
}
}
diff --git a/examples/particles/customparticle/imagecolors.qml b/examples/particles/customparticle/content/imagecolors.qml
index 94e5123a0c..62345f75c1 100644
--- a/examples/particles/customparticle/imagecolors.qml
+++ b/examples/particles/customparticle/content/imagecolors.qml
@@ -62,7 +62,7 @@ Rectangle {
}
Image {
id: picture
- source: "../images/starfish_3.png"
+ source: "../../images/starfish_3.png"
}
ShaderEffectSource {
id: particleSource
@@ -71,8 +71,9 @@ Rectangle {
}
Image {
id: particle
- source: "../images/particle4.png"
+ source: "../../images/particle4.png"
}
+ //! [vertex]
vertexShader:"
uniform highp float maxWidth;
uniform highp float maxHeight;
@@ -81,14 +82,20 @@ Rectangle {
uniform lowp float qt_Opacity;
void main() {
- fTex2 = vec2(qt_ParticlePos.x / maxWidth, qt_ParticlePos.y / maxHeight);
+
+ fTex2 = vec2(qt_ParticlePos.x, qt_ParticlePos.y);
+ //Uncomment this next line for each particle to use full texture, instead of the solid color at the center of the particle.
+ //fTex2 = fTex2 + ((- qt_ParticleData.z / 2. + qt_ParticleData.z) * qt_ParticleTex); //Adjusts size so it's like a chunk of image.
+ fTex2 = fTex2 / vec2(maxWidth, maxHeight);
highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y;
fFade = min(t*4., (1.-t*t)*.75) * qt_Opacity;
defaultMain();
}
"
+ //! [vertex]
property variant particleTexture: particleSource
property variant pictureTexture: pictureSource
+ //! [fragment]
fragmentShader: "
uniform sampler2D particleTexture;
uniform sampler2D pictureTexture;
@@ -98,6 +105,7 @@ Rectangle {
void main() {
gl_FragColor = texture2D(pictureTexture, fTex2) * texture2D(particleTexture, qt_TexCoord0).w * fFade;
}"
+ //! [fragment]
}
Emitter {
diff --git a/examples/particles/customparticle/customparticle.pro b/examples/particles/customparticle/customparticle.pro
new file mode 100644
index 0000000000..d26778f730
--- /dev/null
+++ b/examples/particles/customparticle/customparticle.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/customparticle
+qml.files = customparticle.qml content
+qml.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/customparticle
+INSTALLS += target qml
+
diff --git a/examples/particles/customparticle/customparticle.qml b/examples/particles/customparticle/customparticle.qml
new file mode 100644
index 0000000000..cb2972bc77
--- /dev/null
+++ b/examples/particles/customparticle/customparticle.qml
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** 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 Nokia Corporation 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 "../../shared" as Examples
+
+/*!
+ \title QtQuick.Particles Examples - CustomParticle
+ \example particles/customparticle
+ \brief This is a collection of examples using CustomParticle in the QML particle system.
+ \image qml-customparticle-example.png
+
+ This is a collection of small QML examples relating to using CustomParticle in the particle system.
+ Each example is a small QML file emphasizing a different way to use CustomParticle.
+
+ Blur Particles adds a blur effect to the particles, which increases over the particle's life time.
+ It uses a custom vertex shader:
+ \snippet examples/particles/customparticle/content/blurparticles.qml vertex
+ to propagate life time simulation to a custom fragement shader:
+ \snippet examples/particles/customparticle/content/blurparticles.qml fragment
+ which has access to both the normal image sampler and a blurred sampler, the image plus a ShaderEffect.
+
+ Fragment Shader just uses the particle system as a vertex delivery system.
+ \snippet examples/particles/customparticle/content/fragmentshader.qml 0
+
+ Image Colors uses CustomParticle to assign colors to particles based on their location in a picture.
+ The vertex shader,
+ \snippet examples/particles/customparticle/content/imagecolors.qml vertex
+ passes along the starting position for each vertex to the fragment shader,
+ \snippet examples/particles/customparticle/content/imagecolors.qml fragment
+ which uses it to determine the color for that particle.
+
+*/
+
+Item {
+ height: 480
+ width: 320
+ Examples.LauncherList {
+ id: ll
+ anchors.fill: parent
+ Component.onCompleted: {
+ addExample("Blur Particles", "Particles that get blurred over time", Qt.resolvedUrl("content/blurparticles.qml"));
+ addExample("Fragment Shader", "Particles drawn with a custom fragment shader", Qt.resolvedUrl("content/fragmentshader.qml"));
+ addExample("Image Colors", "An image explodes into colored particles", Qt.resolvedUrl("content/imagecolors.qml"));
+ }
+ }
+}
diff --git a/examples/particles/customparticle/customparticle.qmlproject b/examples/particles/customparticle/customparticle.qmlproject
new file mode 100644
index 0000000000..6ea1849e31
--- /dev/null
+++ b/examples/particles/customparticle/customparticle.qmlproject
@@ -0,0 +1,16 @@
+import QmlProject 1.1
+
+Project {
+ mainFile: "customparticle.qml"
+
+ /* Include .qml, .js, and image files from current directory and subdirectories */
+ QmlFiles {
+ directory: "."
+ }
+ JavaScriptFiles {
+ directory: "."
+ }
+ ImageFiles {
+ directory: "."
+ }
+}
diff --git a/examples/particles/customparticle/main.cpp b/examples/particles/customparticle/main.cpp
new file mode 100644
index 0000000000..f401c36687
--- /dev/null
+++ b/examples/particles/customparticle/main.cpp
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** 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 Nokia Corporation 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$
+**
+****************************************************************************/
+#include "../../shared/shared.h"
+DECLARATIVE_EXAMPLE_MAIN(customparticle)