Warning, /plasma/libplasma/examples/applets/testshaders/contents/ui/ColorShower.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2013 Digia Plc and /or its subsidiary(-ies) <http://www.qt-project.org/legal>
0003
0004 This file is part of the examples of the Qt Toolkit.
0005
0006 SPDX-License-Identifier: BSD-3-Clause
0007 */
0008
0009 import QtQuick
0010 import QtQuick.Particles
0011
0012 ShaderExample {
0013
0014 pageName: "Particles"
0015 pageDescription: "Fun rainbow colors using a fragment shader"
0016
0017 Item {
0018 anchors.fill: parent
0019 clip: true
0020 anchors.margins: -_s
0021 ParticleSystem {
0022 id: psItem
0023 //anchors.fill: parent
0024 x: parent.width / 2
0025 y: parent.height / 2
0026 width: parent.width
0027 height: parent.height
0028 // clip: true
0029 anchors.topMargin: 48
0030 //anchors.leftMargin: 42
0031
0032 Emitter {
0033 emitRate: 400
0034 lifeSpan: 8000
0035 size: 24
0036 sizeVariation: 16
0037 velocity: PointDirection {x: psItem.width/20; y: psItem.height/20;}
0038 acceleration: PointDirection {x: -psItem.width/40; y: -psItem.height/40; xVariation: -psItem.width/20; yVariation: -psItem.width/20}
0039 }
0040
0041 CustomParticle {
0042 vertexShader:"
0043 uniform lowp float qt_Opacity;
0044 varying lowp float fFade;
0045 varying highp vec2 fPos;
0046
0047 void main() {
0048 qt_TexCoord0 = qt_ParticleTex;
0049 highp float size = qt_ParticleData.z;
0050 highp float endSize = qt_ParticleData.w;
0051
0052 highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y;
0053
0054 highp float currentSize = mix(size, endSize, t * t);
0055
0056 if (t < 0. || t > 1.)
0057 currentSize = 0.;
0058
0059 highp vec2 pos = qt_ParticlePos
0060 - currentSize / 2. + currentSize * qt_ParticleTex // adjust size
0061 + qt_ParticleVec.xy * t * qt_ParticleData.y // apply velocity vector..
0062 + 0.5 * qt_ParticleVec.zw * pow(t * qt_ParticleData.y, 2.);
0063
0064 gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
0065
0066 highp float fadeIn = min(t * 20., 1.);
0067 highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
0068
0069 fFade = fadeIn * fadeOut * qt_Opacity;
0070 fPos = vec2(pos.x/320., pos.y/480.);
0071 }
0072 "
0073 //! [0]
0074 fragmentShader: "
0075 varying highp vec2 fPos;
0076 varying lowp float fFade;
0077 varying highp vec2 qt_TexCoord0;
0078 void main() {//*2 because this generates dark colors mostly
0079 highp vec2 circlePos = qt_TexCoord0*2.0 - vec2(1.0,1.0);
0080 highp float dist = length(circlePos);
0081 highp float circleFactor = max(min(1.0 - dist, 1.0), 0.0);
0082 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;
0083 }"
0084 //! [0]
0085
0086 }
0087 }
0088 }
0089 }