ImageParticle{
particles: ["works", "fire", "splode"]
source: "content/particle.png"
+ entryEffect: ImageParticle.Scale
}
}
}
uniform highp mat4 qt_Matrix;
uniform highp float timestamp;
+uniform highp float entry;
varying lowp vec4 fColor;
if (t < 0. || t > 1.)
currentSize = 0.;
+ lowp float fFade = 1.;
+
+ if (entry == 1.){
+ highp float fadeIn = min(t * 10., 1.);
+ highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+ fFade = fadeIn * fadeOut;
+ }else if(entry == 2.){
+ highp float sizeIn = min(t * 10., 1.);
+ highp float sizeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+ currentSize = currentSize * sizeIn * sizeOut;
+ }
+
gl_PointSize = currentSize;
highp vec2 pos = vPos
gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
- highp float fadeIn = min(t * 10., 1.);
- highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
-
- fColor = vColor * (fadeIn * fadeOut);
+ fColor = vColor * (fFade);
}
uniform highp mat4 qt_Matrix;
uniform highp float timestamp;
+uniform highp float entry;
varying highp vec2 fTex;
varying lowp vec4 fColor;
if (t < 0. || t > 1.)
currentSize = 0.;
+ lowp float fFade = 1.;
+
+ if (entry == 1.){
+ highp float fadeIn = min(t * 10., 1.);
+ highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+ fFade = fadeIn * fadeOut;
+ }else if(entry == 2.){
+ highp float sizeIn = min(t * 10., 1.);
+ highp float sizeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+ currentSize = currentSize * sizeIn * sizeOut;
+ }
+
highp vec2 pos;
highp float rotation = vRotation.x + vRotation.y * t * vData.y;
if(vRotation.z == 1.0){
gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
- highp float fadeIn = min(t * 10., 1.);
- highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
-
- fColor = vColor * (fadeIn * fadeOut);
+ fColor = vColor * fFade;
}
uniform highp mat4 qt_Matrix;
uniform highp float timestamp;
+uniform highp float entry;
varying lowp float fFade;
void main() {
- highp float size = vData.z;
- highp float endSize = vData.w;
-
highp float t = (timestamp - vData.x) / vData.y;
- highp float currentSize = mix(size, endSize, t * t);
+ highp float currentSize = mix(vData.z, vData.w, t * t);
if (t < 0. || t > 1.)
currentSize = 0.;
+ fFade = 1.;
+
+ if (entry == 1.){
+ highp float fadeIn = min(t * 10., 1.);
+ highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+ fFade = fadeIn * fadeOut;
+ }else if(entry == 2.){
+ highp float sizeIn = min(t * 10., 1.);
+ highp float sizeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+ currentSize = currentSize * sizeIn * sizeOut;
+ }
+
gl_PointSize = currentSize;
highp vec2 pos = vPos
gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
- highp float fadeIn = min(t * 10., 1.);
- highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
-
- fFade = fadeIn * fadeOut;
}
void main() {
- highp float size = vData.z;
- highp float endSize = vData.w;
highp float t = (timestamp - vData.x) / vData.y;
frameTex.y = 1. * ((vAnimData.x + 1.)/animcount);
fTexB = frameTex;
- highp float currentSize = mix(size, endSize, t * t);
+ highp float currentSize = mix(vData.z, vData.w, t * t);
if (t < 0. || t > 1.)
currentSize = 0.;
fColor = vColor;
tt = t;
-
}
QSGTexture *opacitytable;
qreal timestamp;
+ qreal entry;
qreal framecount;
qreal animcount;
};
program()->setUniformValue("opacitytable", 3);
glFuncs = QGLContext::currentContext()->functions();
m_timestamp_id = program()->uniformLocation("timestamp");
+ m_entry_id = program()->uniformLocation("entry");
}
void updateState(const TabledMaterialData* d, const TabledMaterialData*) {
program()->setUniformValue(m_timestamp_id, (float) d->timestamp);
program()->setUniformValue("framecount", (float) 1);
program()->setUniformValue("animcount", (float) 1);
+ program()->setUniformValue(m_entry_id, (float) d->entry);
}
+ int m_entry_id;
int m_timestamp_id;
QByteArray m_vertex_code;
QByteArray m_fragment_code;
program()->setUniformValue("texture", 0);
glFuncs = QGLContext::currentContext()->functions();
m_timestamp_id = program()->uniformLocation("timestamp");
+ m_entry_id = program()->uniformLocation("entry");
}
void updateState(const DeformableMaterialData* d, const DeformableMaterialData*) {
d->texture->bind();
program()->setUniformValue(m_timestamp_id, (float) d->timestamp);
+ program()->setUniformValue(m_entry_id, (float) d->entry);
}
+ int m_entry_id;
int m_timestamp_id;
QByteArray m_vertex_code;
QByteArray m_fragment_code;
m_timestamp_id = program()->uniformLocation("timestamp");
m_framecount_id = program()->uniformLocation("framecount");
m_animcount_id = program()->uniformLocation("animcount");
+ m_entry_id = program()->uniformLocation("entry");
}
void updateState(const SpriteMaterialData* d, const SpriteMaterialData*) {
program()->setUniformValue(m_timestamp_id, (float) d->timestamp);
program()->setUniformValue(m_framecount_id, (float) d->framecount);
program()->setUniformValue(m_animcount_id, (float) d->animcount);
+ program()->setUniformValue(m_entry_id, (float) d->entry);
}
int m_timestamp_id;
int m_framecount_id;
int m_animcount_id;
+ int m_entry_id;
QByteArray m_vertex_code;
QByteArray m_fragment_code;
QGLFunctions* glFuncs;
program()->setUniformValue("texture", 0);
glFuncs = QGLContext::currentContext()->functions();
m_timestamp_id = program()->uniformLocation("timestamp");
+ m_entry_id = program()->uniformLocation("entry");
}
void updateState(const ColoredMaterialData* d, const ColoredMaterialData*) {
d->texture->bind();
program()->setUniformValue(m_timestamp_id, (float) d->timestamp);
+ program()->setUniformValue(m_entry_id, (float) d->entry);
}
int m_timestamp_id;
+ int m_entry_id;
QByteArray m_vertex_code;
QByteArray m_fragment_code;
QGLFunctions* glFuncs;
program()->setUniformValue("texture", 0);
glFuncs = QGLContext::currentContext()->functions();
m_timestamp_id = program()->uniformLocation("timestamp");
+ m_entry_id = program()->uniformLocation("entry");
}
void updateState(const SimpleMaterialData* d, const SimpleMaterialData*) {
d->texture->bind();
program()->setUniformValue(m_timestamp_id, (float) d->timestamp);
+ program()->setUniformValue(m_entry_id, (float) d->entry);
}
int m_timestamp_id;
+ int m_entry_id;
QByteArray m_vertex_code;
QByteArray m_fragment_code;
QGLFunctions* glFuncs;
/*!
\qmlproperty list<Sprite> QtQuick.Particles2::ImageParticle::sprites
*/
+/*!
+ \qmlproperty EntryEffect QtQuick.Particles2::ImageParticle::entryEffect
+
+ This property provides basic and cheap entrance and exit effects for the particles.
+ For fine-grained control, see sizeTable and opacityTable.
+
+ Acceptable values are
+ \list
+ \o None: Particles just appear and disappear.
+ \o Fade: Particles fade in from 0. opacity at the start of their life, and fade out to 0. at the end.
+ \o Scale: Particles scale in from 0 size at the start of their life, and scale back to 0 at the end.
+ \endlist
+
+ Default value is Fade.
+*/
QSGImageParticle::QSGImageParticle(QSGItem* parent)
, perfLevel(Unknown)
, m_lastLevel(Unknown)
, m_debugMode(false)
+ , m_entryEffect(Fade)
{
setFlag(ItemHasContents);
m_debugMode = qmlParticlesDebug();
reset();
}
+void QSGImageParticle::setEntryEffect(EntryEffect arg)
+{
+ if (m_entryEffect != arg) {
+ m_entryEffect = arg;
+ if (m_material)
+ getState<ImageMaterialData>(m_material)->entry = (qreal) m_entryEffect;
+ emit entryEffectChanged(arg);
+ }
+}
+
void QSGImageParticle::reset()
{
QSGParticlePainter::reset();
m_material = SimpleMaterial::createMaterial();
getState<ImageMaterialData>(m_material)->texture = sceneGraphEngine()->createTextureFromImage(image);
getState<ImageMaterialData>(m_material)->texture->setFiltering(QSGTexture::Linear);
+ getState<ImageMaterialData>(m_material)->entry = (qreal) m_entryEffect;
m_material->setFlag(QSGMaterial::Blending);
}
//yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
Q_PROPERTY(QSGStochasticDirection* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
+
+ Q_PROPERTY(EntryEffect entryEffect READ entryEffect WRITE setEntryEffect NOTIFY entryEffectChanged)
Q_PROPERTY(bool bloat READ bloat WRITE setBloat NOTIFY bloatChanged)//Just a debugging property to bypass optimizations
+ Q_ENUMS(EntryEffect)
public:
explicit QSGImageParticle(QSGItem *parent = 0);
virtual ~QSGImageParticle();
QDeclarativeListProperty<QSGSprite> sprites();
QSGSpriteEngine* spriteEngine() {return m_spriteEngine;}
+ enum EntryEffect {
+ None = 0,
+ Fade = 1,
+ Scale = 2
+ };
+
enum PerformanceLevel{//TODO: Expose?
Unknown = 0,
Simple,
bool bloat() const { return m_bloat; }
+ EntryEffect entryEffect() const { return m_entryEffect; }
+
signals:
void imageChanged();
void bloatChanged(bool arg);
+ void entryEffectChanged(EntryEffect arg);
+
public slots:
void reloadColor(const Color4ub &c, QSGParticleData* d);
void setAlphaVariation(qreal arg);
void setBloat(bool arg);
+ void setEntryEffect(EntryEffect arg);
+
protected:
void reset();
virtual void initialize(int gIdx, int pIdx);
MaterialData* getState(QSGMaterial* m){
return static_cast<QSGSimpleMaterial<MaterialData> *>(m)->state();
}
+ EntryEffect m_entryEffect;
};
QT_END_NAMESPACE