QT_BEGIN_NAMESPACE
+/*!
+ \qmlclass Sprite QSGSprite
+ \inqmlmodule QtQuick 2
+ \brief The Sprite element represents a sprite animation
+
+*/
+/*!
+ \qmlproperty int QtQuick2::Sprite::duration
+
+ Time between frames.
+*/
+/*!
+ \qmlproperty int QtQuick2::Sprite::durationVariation
+
+ The time between frames can vary by up to this amount.
+
+ Default is 0.
+*/
+
+/*!
+ \qmlproperty string QtQuick2::Sprite::name
+
+ The name of this sprite, for use in the to property of other sprites.
+*/
+/*!
+ \qmlproperty QVariantMap QtQuick2::Sprite::to
+
+ A list of other sprites and weighted transitions to them,
+ for example {"a":1, "b":2, "c":0} would specify that one-third should
+ transition to sprite "a" when this sprite is done, and two-thirds should
+ transition to sprite "b" when this sprite is done. As the transitions are
+ chosen randomly, these proportions will not be exact. With "c":0 in the list,
+ no sprites will randomly transition to "c", but it wll be a valid path if a sprite
+ goal is set.
+
+ If no list is specified, or the sum of weights in the list is zero, then the sprite
+ will repeat itself after completing.
+*/
+/*!
+ \qmlproperty int QtQuick2::Sprite::frames
+
+ Number of frames in this sprite.
+*/
+/*!
+ \qmlproperty int QtQuick2::Sprite::frameHeight
+
+ Height of a single frame in this sprite.
+*/
+/*!
+ \qmlproperty int QtQuick2::Sprite::frameWidth
+
+ Width of a single frame in this sprite.
+*/
+/*!
+ \qmlproperty url QtQuick2::Sprite::source
+
+ The image source for the animation.
+
+ If frameHeight and frameWidth are not specified, it is assumed to be a single long row of square frames.
+ Otherwise, it can be multiple contiguous rows or rectangluar frames, when one row runs out the next will be used.
+*/
+ Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
+ Q_PROPERTY(int durationVariation READ durationVariance WRITE setDurationVariance NOTIFY durationVarianceChanged)
+ Q_PROPERTY(QVariantMap to READ to WRITE setTo NOTIFY toChanged)
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+ Q_PROPERTY(qreal speedModifiesDuration READ speedModifer WRITE setSpeedModifier NOTIFY speedModifierChanged)
+ Q_PROPERTY(int frames READ frames WRITE setFrames NOTIFY framesChanged)
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ //If frame height or width is not specified, it is assumed to be a single long row of square frames.
+ //Otherwise, it can be multiple contiguous rows, when one row runs out the next will be used.
+ Q_PROPERTY(int frameHeight READ frameHeight WRITE setFrameHeight NOTIFY frameHeightChanged)
+ Q_PROPERTY(int frameWidth READ frameWidth WRITE setFrameWidth NOTIFY frameWidthChanged)
+
QSGSprite::QSGSprite(QObject *parent) :
QSGStochasticState(parent)
, m_generatedCount(0)
QT_BEGIN_NAMESPACE
+static const char vertexShaderCode[] =
+ "attribute highp vec2 vTex;\n"
+ "uniform highp vec4 animData;// interpolate(bool), duration, frameCount (this anim), timestamp (this anim)\n"
+ "uniform highp vec4 animPos;//sheet x,y, width/height of this anim\n"
+ "uniform highp vec4 animSheetSize; //width/height of whole sheet, width/height of element\n"
+ "\n"
+ "uniform highp mat4 qt_Matrix;\n"
+ "uniform highp float timestamp;\n"
+ "\n"
+ "varying highp vec4 fTexS;\n"
+ "varying lowp float progress;\n"
+ "\n"
+ "\n"
+ "void main() {\n"
+ " //Calculate frame location in texture\n"
+ " highp float frameIndex = mod((((timestamp - animData.w)*1000.)/animData.y),animData.z);\n"
+ " progress = mod((timestamp - animData.w)*1000., animData.y) / animData.y;\n"
+ "\n"
+ " frameIndex = floor(frameIndex);\n"
+ " fTexS.xy = vec2(((frameIndex + vTex.x) * animPos.z / animSheetSize.x), ((animPos.y + vTex.y * animPos.w) / animSheetSize.y));\n"
+ "\n"
+ " //Next frame is also passed, for interpolation\n"
+ " //### Should the next anim be precalculated to allow for interpolation there?\n"
+ " if (animData.x == 1.0 && frameIndex != animData.z - 1.)//Can't do it for the last frame though, this anim may not loop\n"
+ " frameIndex = mod(frameIndex+1., animData.z);\n"
+ " fTexS.zw = vec2(((frameIndex + vTex.x) * animPos.z / animSheetSize.x), ((animPos.y + vTex.y * animPos.w) / animSheetSize.y));\n"
+ "\n"
+ " gl_Position = qt_Matrix * vec4(animSheetSize.z * vTex.x, animSheetSize.w * vTex.y, 0, 1);\n"
+ "}\n";
+
+static const char fragmentShaderCode[] =
+ "uniform sampler2D texture;\n"
+ "uniform lowp float qt_Opacity;\n"
+ "\n"
+ "varying highp vec4 fTexS;\n"
+ "varying lowp float progress;\n"
+ "\n"
+ "void main() {\n"
+ " gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), progress) * qt_Opacity;\n"
+ "}\n";
+
class QSGSpriteMaterial : public QSGMaterial
{
public:
QSGTexture *texture;
qreal timestamp;
- qreal timelength;
- int framecount;
- int animcount;
- int width;
- int height;
+ float interpolate;
+ float frameDuration;
+ float frameCount;
+ float animT;
+ float animX;
+ float animY;
+ float animWidth;
+ float animHeight;
+ float sheetWidth;
+ float sheetHeight;
+ float elementWidth;
+ float elementHeight;
};
QSGSpriteMaterial::QSGSpriteMaterial()
: timestamp(0)
- , timelength(1)
- , framecount(1)
- , animcount(1)
- , width(0)
- , height(0)
+ , interpolate(1.0f)
+ , frameDuration(1.0f)
+ , frameCount(1.0f)
+ , animT(0.0f)
+ , animX(0.0f)
+ , animY(0.0f)
+ , animWidth(1.0f)
+ , animHeight(1.0f)
+ , sheetWidth(1.0f)
+ , sheetHeight(1.0f)
+ , elementWidth(1.0f)
+ , elementHeight(1.0f)
{
setFlag(Blending, true);
}
public:
SpriteMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
{
- QFile vf(vertexFile ? QLatin1String(vertexFile) : QLatin1String(":defaultshaders/spriteimagevertex.shader"));
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? QLatin1String(fragmentFile) : QLatin1String(":defaultshaders/spriteimagefragment.shader"));
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
}
void deactivate() {
program()->setUniformValue(m_opacity_id, state.opacity());
program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
- program()->setUniformValue(m_framecount_id, (float) m->framecount);
- program()->setUniformValue(m_animcount_id, (float) m->animcount);
- program()->setUniformValue(m_width_id, (float) m->width);
- program()->setUniformValue(m_height_id, (float) m->height);
+ program()->setUniformValue(m_animData_id, m->interpolate, m->frameDuration, m->frameCount, m->animT);
+ program()->setUniformValue(m_animPos_id, m->animX, m->animY, m->animWidth, m->animHeight);
+ program()->setUniformValue(m_animSheetSize_id, m->sheetWidth, m->sheetHeight, m->elementWidth, m->elementHeight);
if (state.isMatrixDirty())
program()->setUniformValue(m_matrix_id, state.combinedMatrix());
}
virtual void initialize() {
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
+ m_matrix_id = program()->uniformLocation("qt_Matrix");
+ m_opacity_id = program()->uniformLocation("qt_Opacity");
m_timestamp_id = program()->uniformLocation("timestamp");
- m_framecount_id = program()->uniformLocation("framecount");
- m_animcount_id = program()->uniformLocation("animcount");
- m_width_id = program()->uniformLocation("width");
- m_height_id = program()->uniformLocation("height");
+ m_animData_id = program()->uniformLocation("animData");
+ m_animPos_id = program()->uniformLocation("animPos");
+ m_animSheetSize_id = program()->uniformLocation("animSheetSize");
}
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
+ virtual const char *vertexShader() const { return vertexShaderCode; }
+ virtual const char *fragmentShader() const { return fragmentShaderCode; }
virtual char const *const *attributeNames() const {
static const char *attr[] = {
"vTex",
- "vAnimData",
0
};
return attr;
}
- virtual bool isColorTable() const { return false; }
-
int m_matrix_id;
int m_opacity_id;
int m_timestamp_id;
- int m_framecount_id;
- int m_animcount_id;
- int m_width_id;
- int m_height_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
+ int m_animData_id;
+ int m_animPos_id;
+ int m_animSheetSize_id;
static float chunkOfBytes[1024];
};
+
float SpriteMaterialData::chunkOfBytes[1024];
QSGMaterialShader *QSGSpriteMaterial::createShader() const
struct SpriteVertex {
float tx;
float ty;
- float animIdx;
- float frameDuration;
- float frameCount;
- float animT;
};
struct SpriteVertices {
SpriteVertex v4;
};
+/*!
+ \qmlclass SpriteImage QSGSpriteImage
+ \inqmlmodule QtQuick 2
+ \inherits Item
+ \brief The SpriteImage element draws a sprite animation
+
+*/
+/*!
+ \qmlproperty bool QtQuick2::SpriteImage::running
+
+ Whether the sprite is animating or not.
+
+ Default is true
+*/
+/*!
+ \qmlproperty bool QtQuick2::SpriteImage::interpolate
+
+ If true, interpolation will occur between sprite frames to make the
+ animation appear smoother.
+
+ Default is true.
+*/
+/*!
+ \qmlproperty list<Sprite> QtQuick2::SpriteImage::sprites
+
+ The sprite or sprites to draw. Sprites will be scaled to the size of this element.
+*/
+
+//TODO: Implicitly size element to size of first sprite?
QSGSpriteImage::QSGSpriteImage(QSGItem *parent) :
QSGItem(parent)
, m_node(0)
, m_spriteEngine(0)
, m_pleaseReset(false)
, m_running(true)
+ , m_interpolate(true)
{
setFlag(ItemHasContents);
connect(this, SIGNAL(runningChanged(bool)),
static QSGGeometry::Attribute SpriteImage_Attributes[] = {
QSGGeometry::Attribute::create(0, 2, GL_FLOAT), // tex
- QSGGeometry::Attribute::create(1, 4, GL_FLOAT) // animData
};
static QSGGeometry::AttributeSet SpriteImage_AttributeSet =
{
- 2, // Attribute Count
- (4 + 2) * sizeof(float),
+ 1, // Attribute Count
+ 2 * sizeof(float),
SpriteImage_Attributes
};
return 0;
}
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
m_material = new QSGSpriteMaterial();
QImage image = m_spriteEngine->assembledImage();
return 0;
m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
m_material->texture->setFiltering(QSGTexture::Linear);
- m_material->framecount = m_spriteEngine->maxFrames();
+ m_spriteEngine->start(0);
+ m_material->interpolate = m_interpolate ? 1.0 : 0.0;
+ m_material->frameCount = m_spriteEngine->spriteFrames();
+ m_material->frameDuration = m_spriteEngine->spriteDuration();
+ m_material->animT = 0;
+ m_material->animX = m_spriteEngine->spriteX();
+ m_material->animY = m_spriteEngine->spriteY();
+ m_material->animWidth = m_spriteEngine->spriteWidth();
+ m_material->animHeight = m_spriteEngine->spriteHeight();
+ m_material->sheetWidth = image.width();
+ m_material->sheetHeight = image.height();
+ m_material->elementWidth = width();
+ m_material->elementHeight = height();
int vCount = 4;
int iCount = 6;
g->setDrawingMode(GL_TRIANGLES);
SpriteVertices *p = (SpriteVertices *) g->vertexData();
- m_spriteEngine->start(0);
- p->v1.animT = p->v2.animT = p->v3.animT = p->v4.animT = 0;
- p->v1.animIdx = p->v2.animIdx = p->v3.animIdx = p->v4.animIdx = 0;
- p->v1.frameCount = p->v2.frameCount = p->v3.frameCount = p->v4.frameCount = m_spriteEngine->spriteFrames();
- p->v1.frameDuration = p->v2.frameDuration = p->v3.frameDuration = p->v4.frameDuration = m_spriteEngine->spriteDuration();
p->v1.tx = 0;
p->v1.ty = 0;
m_node = new QSGGeometryNode();
m_node->setGeometry(g);
m_node->setMaterial(m_material);
+ m_node->setFlag(QSGGeometryNode::OwnsMaterial);
return m_node;
}
uint timeInt = m_timestamp.elapsed();
qreal time = timeInt / 1000.;
m_material->timestamp = time;
- m_material->animcount = m_spriteEngine->spriteCount();
- m_material->height = height();
- m_material->width = width();
+ m_material->elementHeight = height();
+ m_material->elementWidth = width();
+ m_material->interpolate = m_interpolate;
//Advance State
SpriteVertices *p = (SpriteVertices *) m_node->geometry()->vertexData();
m_spriteEngine->updateSprites(timeInt);
- int curIdx = m_spriteEngine->spriteState();
- if(curIdx != p->v1.animIdx){
- p->v1.animIdx = p->v2.animIdx = p->v3.animIdx = p->v4.animIdx = curIdx;
- p->v1.animT = p->v2.animT = p->v3.animT = p->v4.animT = m_spriteEngine->spriteStart()/1000.0;
- p->v1.frameCount = p->v2.frameCount = p->v3.frameCount = p->v4.frameCount = m_spriteEngine->spriteFrames();
- p->v1.frameDuration = p->v2.frameDuration = p->v3.frameDuration = p->v4.frameDuration = m_spriteEngine->spriteDuration();
+ int curY = m_spriteEngine->spriteY();
+ if (curY != m_material->animY){
+ m_material->animT = m_spriteEngine->spriteStart()/1000.0;
+ m_material->frameCount = m_spriteEngine->spriteFrames();
+ m_material->frameDuration = m_spriteEngine->spriteDuration();
+ m_material->animX = m_spriteEngine->spriteX();
+ m_material->animY = m_spriteEngine->spriteY();
+ m_material->animWidth = m_spriteEngine->spriteWidth();
+ m_material->animHeight = m_spriteEngine->spriteHeight();
}
}
{
Q_OBJECT
Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
+ Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate NOTIFY interpolateChanged)
//###try to share similar spriteEngines for less overhead?
Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_CLASSINFO("DefaultProperty", "sprites")
return m_running;
}
-signals:
+ bool interpolate() const
+ {
+ return m_interpolate;
+ }
+signals:
void runningChanged(bool arg);
+ void interpolateChanged(bool arg);
public slots:
}
}
+void setInterpolate(bool arg)
+{
+ if (m_interpolate != arg) {
+ m_interpolate = arg;
+ emit interpolateChanged(arg);
+ }
+}
+
private slots:
void createEngine();
protected:
int m_maxFrames;
bool m_pleaseReset;
bool m_running;
+ bool m_interpolate;
};
QT_END_NAMESPACE
+++ /dev/null
-uniform sampler2D texture;
-uniform lowp float qt_Opacity;
-
-varying lowp vec4 fColor;
-
-void main() {
- gl_FragColor = (texture2D(texture, gl_PointCoord)) * fColor * qt_Opacity;
-}
-
+++ /dev/null
-attribute highp vec2 vPos;
-attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
-attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
-attribute lowp vec4 vColor;
-
-uniform highp mat4 qt_Matrix;
-uniform highp float timestamp;
-uniform highp float entry;
-
-varying lowp vec4 fColor;
-
-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);
-
- 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
- + vVec.xy * t * vData.y // apply speed vector..
- + 0.5 * vVec.zw * pow(t * vData.y, 2.);
-
- gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
-
- fColor = vColor * (fFade);
-}
+++ /dev/null
-uniform sampler2D texture;
-uniform lowp float qt_Opacity;
-
-varying highp vec2 fTex;
-varying lowp vec4 fColor;
-
-void main() {
- gl_FragColor = (texture2D(texture, fTex)) * fColor * qt_Opacity;
-}
+++ /dev/null
-attribute highp vec2 vPos;
-attribute highp vec2 vTex;
-attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
-attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
-attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector
-attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate
-attribute lowp vec4 vColor;
-
-uniform highp mat4 qt_Matrix;
-uniform highp float timestamp;
-uniform highp float entry;
-
-varying highp vec2 fTex;
-varying lowp vec4 fColor;
-
-void main() {
- fTex = vTex;
- 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);
-
- 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){
- highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;
- rotation += atan(curVel.y, curVel.x);
- }
- highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation));
- highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5);
- highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5);
- highp vec2 xRotatedDeform;
- xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y;
- xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y;
- highp vec2 yRotatedDeform;
- yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y;
- yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y;
- pos = vPos
- + xRotatedDeform
- + yRotatedDeform
- //- vec2(1,1) * currentSize * 0.5 // 'center'
- + vVec.xy * t * vData.y // apply speed
- + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration
-
- gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
-
- fColor = vColor * fFade;
-}
+++ /dev/null
-uniform sampler2D texture;
-uniform lowp float qt_Opacity;
-
-#ifdef SPRITE
-varying highp vec4 fTexS;
-#else
-#ifdef DEFORM //First non-pointsprite
-varying highp vec2 fTex;
-#endif
-#endif
-#ifdef COLOR
-varying lowp vec4 fColor;
-#else
-varying lowp float fFade;
-#endif
-#ifdef TABLE
-varying lowp vec2 tt;
-uniform sampler2D colortable;
-#endif
-
-void main() {
-#ifdef SPRITE
- gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), tt.y)
- * fColor
- * texture2D(colortable, tt)
- * qt_Opacity;
-#else
-#ifdef TABLE
- gl_FragColor = texture2D(texture, fTex)
- * fColor
- * texture2D(colortable, tt)
- * qt_Opacity;
-#else
-#ifdef DEFORM
- gl_FragColor = (texture2D(texture, fTex)) * fColor * qt_Opacity;
-#else
-#ifdef COLOR
- gl_FragColor = (texture2D(texture, gl_PointCoord)) * fColor * qt_Opacity;
-#else
- gl_FragColor = texture2D(texture, gl_PointCoord) * (fFade * qt_Opacity);
-#endif //COLOR
-#endif //DEFORM
-#endif //TABLE
-#endif //SPRITE
-}
+++ /dev/null
-attribute highp vec2 vPos;
-attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
-attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
-uniform highp float entry;
-#ifdef COLOR
-attribute lowp vec4 vColor;
-#endif
-#ifdef DEFORM
-attribute highp vec2 vTex;
-attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector
-attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate
-#endif
-#ifdef SPRITE
-attribute highp vec4 vAnimData;// interpolate(bool), duration, frameCount (this anim), timestamp (this anim)
-attribute highp vec4 vAnimPos;//sheet x,y, width/height of this anim
-uniform highp vec2 animSheetSize; //width/height of whole sheet
-#endif
-
-uniform highp mat4 qt_Matrix;
-uniform highp float timestamp;
-#ifdef TABLE
-varying lowp vec2 tt;//y is progress if Sprite mode
-uniform highp float sizetable[64];
-uniform highp float opacitytable[64];
-#endif
-#ifdef SPRITE
-varying highp vec4 fTexS;
-#else
-#ifdef DEFORM
-varying highp vec2 fTex;
-#endif
-#endif
-#ifdef COLOR
-varying lowp vec4 fColor;
-#else
-varying lowp float fFade;
-#endif
-
-
-void main() {
-
- highp float t = (timestamp - vData.x) / vData.y;
- if (t < 0. || t > 1.){
-#ifdef DEFORM //Not point sprites
- gl_Position = qt_Matrix * vec4(vPos.x, vPos.y, 0., 1.);
-#else
- gl_PointSize = 0.;
-#endif
- return;
- }
-#ifdef SPRITE
- //Calculate frame location in texture
- highp float frameIndex = mod((((timestamp - vAnimData.w)*1000.)/vAnimData.y),vAnimData.z);
- tt.y = mod((timestamp - vAnimData.w)*1000., vAnimData.y) / vAnimData.y;
-
- frameIndex = floor(frameIndex);
- fTexS.xy = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));
-
- //Next frame is also passed, for interpolation
- //### Should the next anim be precalculated to allow for interpolation there?
- if(vAnimData.x == 1.0 && frameIndex != vAnimData.z - 1.)//Can't do it for the last frame though, this anim may not loop
- frameIndex = mod(frameIndex+1., vAnimData.z);
- fTexS.zw = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));
-#else
-#ifdef DEFORM
- fTex = vTex;
-#endif
-#endif
- highp float currentSize = mix(vData.z, vData.w, t * t);
- lowp float fade = 1.;
- highp float fadeIn = min(t * 10., 1.);
- highp float fadeOut = 1. - clamp((t - 0.75) * 4.,0., 1.);
-
-#ifdef TABLE
- currentSize = currentSize * sizetable[int(floor(t*64.))];
- fade = fade * opacitytable[int(floor(t*64.))];
-#endif
-
- if (entry == 1.)
- fade = fade * fadeIn * fadeOut;
- else if(entry == 2.)
- currentSize = currentSize * fadeIn * fadeOut;
-
- if(currentSize <= 0)//Sizes too small look jittery as they move
- currentSize = 0;
- else if(currentSize < 3)
- currentSize = 3;
-
- highp vec2 pos;
-#ifdef DEFORM
- highp float rotation = vRotation.x + vRotation.y * t * vData.y;
- if(vRotation.z == 1.0){
- highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;
- rotation += atan(curVel.y, curVel.x);
- }
- highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation));
- highp vec4 deform = vDeformVec * currentSize * (vTex.xxyy - 0.5);
- highp vec4 rotatedDeform = deform.xxzz * trigCalcs.xyxy;
- rotatedDeform = rotatedDeform + (deform.yyww * trigCalcs.yxyx * vec4(-1.,1.,-1.,1.));
- /* The readable version:
- highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5);
- highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5);
- highp vec2 xRotatedDeform;
- xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y;
- xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y;
- highp vec2 yRotatedDeform;
- yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y;
- yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y;
- */
- pos = vPos
- + rotatedDeform.xy
- + rotatedDeform.zw
- + vVec.xy * t * vData.y // apply speed
- + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration
-#else
- pos = vPos
- + vVec.xy * t * vData.y // apply speed vector..
- + 0.5 * vVec.zw * pow(t * vData.y, 2.);
- gl_PointSize = currentSize;
-#endif
- gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
-
-#ifdef COLOR
- fColor = vColor * fade;
-#else
- fFade = fade;
-#endif
-#ifdef TABLE
- tt.x = t;
-#endif
-}
+++ /dev/null
-uniform sampler2D texture;
-uniform lowp float qt_Opacity;
-
-varying lowp float fFade;
-
-void main() {
- gl_FragColor = texture2D(texture, gl_PointCoord) * (fFade * qt_Opacity);
-}
+++ /dev/null
-attribute highp vec2 vPos;
-attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
-attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
-
-uniform highp mat4 qt_Matrix;
-uniform highp float timestamp;
-uniform highp float entry;
-
-varying lowp float fFade;
-
-void main() {
- highp float t = (timestamp - vData.x) / vData.y;
-
- 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
- + vVec.xy * t * vData.y // apply speed vector..
- + 0.5 * vVec.zw * pow(t * vData.y, 2.);
-
- gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
-
-}
+++ /dev/null
-uniform sampler2D texture;
-uniform sampler2D colortable;
-uniform sampler2D opacitytable;
-uniform lowp float qt_Opacity;
-
-varying highp vec2 fTexA;
-varying highp vec2 fTexB;
-varying lowp float progress;
-varying lowp vec4 fColor;
-varying lowp float tt;
-
-void main() {
- gl_FragColor = mix(texture2D(texture, fTexA), texture2D(texture, fTexB), progress)
- * fColor
- * texture2D(colortable, vec2(tt, 0.5))
- * (texture2D(opacitytable, vec2(tt, 0.5)).w * qt_Opacity);
-}
+++ /dev/null
-uniform sampler2D texture;
-
-varying highp vec2 fTexA;
-varying highp vec2 fTexB;
-varying lowp float progress;
-
-void main() {
- gl_FragColor = mix(texture2D(texture, fTexA), texture2D(texture, fTexB), progress);
-}
+++ /dev/null
-attribute highp vec2 vTex;
-attribute highp vec4 vAnimData;// idx, duration, frameCount (this anim), timestamp (this anim)
-
-uniform highp mat4 matrix;
-uniform highp float timestamp;
-uniform lowp float opacity;
-uniform highp float framecount; //maximum of all anims
-uniform highp float animcount;
-uniform highp float width;
-uniform highp float height;
-
-varying highp vec2 fTexA;
-varying highp vec2 fTexB;
-varying lowp float progress;
-
-
-void main() {
- //Calculate frame location in texture
- highp float frameIndex = mod((((timestamp - vAnimData.w)*1000.)/vAnimData.y),vAnimData.z);
- progress = mod((timestamp - vAnimData.w)*1000., vAnimData.y) / vAnimData.y;
-
- frameIndex = floor(frameIndex);
- highp vec2 frameTex;
- if(vTex.x == 0.)
- frameTex.x = (frameIndex/framecount);
- else
- frameTex.x = 1. * ((frameIndex + 1.)/framecount);
-
- if(vTex.y == 0.)
- frameTex.y = (vAnimData.x/animcount);
- else
- frameTex.y = 1. * ((vAnimData.x + 1.)/animcount);
-
- fTexA = frameTex;
- //Next frame is also passed, for interpolation
- if(frameIndex != vAnimData.z - 1.)//Can't do it for the last frame though, this anim may not loop
- frameIndex = mod(frameIndex+1., vAnimData.z);
-
- if(vTex.x == 0.)
- frameTex.x = (frameIndex/framecount);
- else
- frameTex.x = 1. * ((frameIndex + 1.)/framecount);
-
- if(vTex.y == 0.)
- frameTex.y = (vAnimData.x/animcount);
- else
- frameTex.y = 1. * ((vAnimData.x + 1.)/animcount);
- fTexB = frameTex;
-
-
- gl_Position = matrix * vec4(width * vTex.x, height * vTex.y, 0, 1);
-}
+++ /dev/null
-attribute highp vec2 vPos;
-attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
-attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
-#ifdef COLOR
-attribute lowp vec4 vColor;
-#endif
-#ifdef DEFORM
-attribute highp vec2 vTex;
-attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector
-attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate
-#endif
-#ifdef SPRITE
-attribute highp vec4 vAnimData;// idx, duration, frameCount (this anim), timestamp (this anim)
-uniform highp float framecount; //maximum of all anims
-uniform highp float animcount;
-#endif
-
-uniform highp mat4 qt_Matrix;
-uniform highp float timestamp;
-#ifdef TABLE
-varying lowp float tt;
-#endif
-#ifdef SPRITE
-varying lowp float progress;
-varying highp vec2 fTexA;
-varying highp vec2 fTexB;
-#elseif DEFORM
-varying highp vec2 fTex;
-#endif
-#ifdef COLOR
-varying lowp vec4 fColor;
-#endif
-
-
-void main() {
-
- highp float t = (timestamp - vData.x) / vData.y;
-#ifdef SPRITE
- //Calculate frame location in texture
- highp float frameIndex = mod((((timestamp - vAnimData.w)*1000.)/vAnimData.y),vAnimData.z);
- progress = mod((timestamp - vAnimData.w)*1000., vAnimData.y) / vAnimData.y;
-
- frameIndex = floor(frameIndex);
- highp vec2 frameTex = vTex;
- if(vTex.x == 0.)
- frameTex.x = (frameIndex/framecount);
- else
- frameTex.x = 1. * ((frameIndex + 1.)/framecount);
-
- if(vTex.y == 0.)
- frameTex.y = (vAnimData.x/animcount);
- else
- frameTex.y = 1. * ((vAnimData.x + 1.)/animcount);
-
- fTexA = frameTex;
- //Next frame is also passed, for interpolation
- //### Should the next anim be precalculated to allow for interpolation there?
- if(frameIndex != vAnimData.z - 1.)//Can't do it for the last frame though, this anim may not loop
- frameIndex = mod(frameIndex+1., vAnimData.z);
-
- if(vTex.x == 0.)
- frameTex.x = (frameIndex/framecount);
- else
- frameTex.x = 1. * ((frameIndex + 1.)/framecount);
-
- if(vTex.y == 0.)
- frameTex.y = (vAnimData.x/animcount);
- else
- frameTex.y = 1. * ((vAnimData.x + 1.)/animcount);
- fTexB = frameTex;
-#endif
-
- highp float currentSize = mix(vData.z, vData.w, t * t);
-
- if (t < 0. || t > 1.)
- currentSize = 0.;
-
- highp vec2 pos;
-#ifdef DEFORM
- highp float rotation = vRotation.x + vRotation.y * t * vData.y;
- if(vRotation.z == 1.0){
- highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;
- rotation += atan(curVel.y, curVel.x);
- }
- highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation));
- highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5);
- highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5);
- highp vec2 xRotatedDeform;
- xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y;
- xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y;
- highp vec2 yRotatedDeform;
- yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y;
- yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y;
- pos = vPos
- + xRotatedDeform
- + yRotatedDeform
- //- vec2(1,1) * currentSize * 0.5 // 'center'
- + vVec.xy * t * vData.y // apply speed
- + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration
-#else
- pos = vPos
- + vVec.xy * t * vData.y // apply speed vector..
- + 0.5 * vVec.zw * pow(t * vData.y, 2.);
-#endif
- gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
-
-#ifdef COLOR
- fColor = vColor;
-#endif
-#ifdef TABLE
- tt = t;
-#endif
-}
+++ /dev/null
-uniform sampler2D texture;
-uniform sampler2D colortable;
-uniform sampler2D opacitytable;
-uniform sampler2D sizetable;
-uniform lowp float qt_Opacity;
-
-varying highp vec2 fTex;
-varying lowp vec4 fColor;
-varying lowp float tt;
-
-void main() {
- highp vec2 tex = (((fTex - 0.5) / texture2D(sizetable, vec2(tt, 0.5)).w) + 0.5);
- lowp vec4 color;
- if(tex.x < 1.0 && tex.x > 0.0 && tex.y < 1.0 && tex.y > 0.0){//No CLAMP_TO_BORDER in ES2, so have to do it ourselves
- color = texture2D(texture, tex);
- }else{
- color = vec4(0.,0.,0.,0.);
- }
- gl_FragColor = color
- * fColor
- * texture2D(colortable, vec2(tt, 0.5))
- * (texture2D(opacitytable, vec2(tt, 0.5)).w * qt_Opacity);
-}
+++ /dev/null
-attribute highp vec2 vPos;
-attribute highp vec2 vTex;
-attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
-attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
-attribute lowp vec4 vColor;
-attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector
-attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate
-
-uniform highp mat4 qt_Matrix;
-uniform highp float timestamp;
-
-varying lowp float tt;
-varying highp vec2 fTex;
-varying lowp float progress;
-varying lowp vec4 fColor;
-
-
-void main() {
- fTex = vTex;
- 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);
- if (t < 0. || t > 1.)
- currentSize = 0.;
-
- highp vec2 pos;
- highp float rotation = vRotation.x + vRotation.y * t * vData.y;
- if(vRotation.z == 1.0){
- highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;
- rotation += atan(curVel.y, curVel.x);
- }
- highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation));
- highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5);
- highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5);
- highp vec2 xRotatedDeform;
- xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y;
- xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y;
- highp vec2 yRotatedDeform;
- yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y;
- yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y;
- pos = vPos
- + xRotatedDeform
- + yRotatedDeform
- //- vec2(1,1) * currentSize * 0.5 // 'center'
- + vVec.xy * t * vData.y // apply speed
- + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration
-
- gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
-
- fColor = vColor;
- tt = t;
-
-}
<RCC>
<qresource prefix="/">
- <file>defaultshaders/imagefragment.shader</file>
- <file>defaultshaders/imagevertex.shader</file>
- <file>defaultshaders/spriteimagefragment.shader</file>
- <file>defaultshaders/spriteimagevertex.shader</file>
- <file>defaultshaders/identitytable.png</file>
- <file>defaultshaders/defaultFadeInOut.png</file>
- <file>defaultshaders/noise.png</file>
+ <file>particleresources/noise.png</file>
</qresource>
</RCC>
//TODO: Make it larger on desktop? Requires fixing up shader code with the same define
#define UNIFORM_ARRAY_SIZE 64
+static const char vertexShaderCode[] =
+ "attribute highp vec2 vPos;\n"
+ "attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize\n"
+ "attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration\n"
+ "uniform highp float entry;\n"
+ "#ifdef COLOR\n"
+ "attribute lowp vec4 vColor;\n"
+ "#endif\n"
+ "#ifdef DEFORM\n"
+ "attribute highp vec2 vTex;\n"
+ "attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector\n"
+ "attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate\n"
+ "#endif\n"
+ "#ifdef SPRITE\n"
+ "attribute highp vec4 vAnimData;// interpolate(bool), duration, frameCount (this anim), timestamp (this anim)\n"
+ "attribute highp vec4 vAnimPos;//sheet x,y, width/height of this anim\n"
+ "uniform highp vec2 animSheetSize; //width/height of whole sheet\n"
+ "#endif\n"
+ "\n"
+ "uniform highp mat4 qt_Matrix;\n"
+ "uniform highp float timestamp;\n"
+ "#ifdef TABLE\n"
+ "varying lowp vec2 tt;//y is progress if Sprite mode\n"
+ "uniform highp float sizetable[64];\n"
+ "uniform highp float opacitytable[64];\n"
+ "#endif\n"
+ "#ifdef SPRITE\n"
+ "varying highp vec4 fTexS;\n"
+ "#else\n"
+ "#ifdef DEFORM\n"
+ "varying highp vec2 fTex;\n"
+ "#endif\n"
+ "#endif\n"
+ "#ifdef COLOR\n"
+ "varying lowp vec4 fColor;\n"
+ "#else\n"
+ "varying lowp float fFade;\n"
+ "#endif\n"
+ "\n"
+ "\n"
+ "void main() {\n"
+ "\n"
+ " highp float t = (timestamp - vData.x) / vData.y;\n"
+ " if (t < 0. || t > 1.){\n"
+ "#ifdef DEFORM //Not point sprites\n"
+ " gl_Position = qt_Matrix * vec4(vPos.x, vPos.y, 0., 1.);\n"
+ "#else\n"
+ " gl_PointSize = 0.;\n"
+ "#endif\n"
+ " return;\n"
+ " }\n"
+ "#ifdef SPRITE\n"
+ " //Calculate frame location in texture\n"
+ " highp float frameIndex = mod((((timestamp - vAnimData.w)*1000.)/vAnimData.y),vAnimData.z);\n"
+ " tt.y = mod((timestamp - vAnimData.w)*1000., vAnimData.y) / vAnimData.y;\n"
+ "\n"
+ " frameIndex = floor(frameIndex);\n"
+ " fTexS.xy = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));\n"
+ "\n"
+ " //Next frame is also passed, for interpolation\n"
+ " //### Should the next anim be precalculated to allow for interpolation there?\n"
+ " if (vAnimData.x == 1.0 && frameIndex != vAnimData.z - 1.)//Can't do it for the last frame though, this anim may not loop\n"
+ " frameIndex = mod(frameIndex+1., vAnimData.z);\n"
+ " fTexS.zw = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));\n"
+ "#else\n"
+ "#ifdef DEFORM\n"
+ " fTex = vTex;\n"
+ "#endif\n"
+ "#endif\n"
+ " highp float currentSize = mix(vData.z, vData.w, t * t);\n"
+ " lowp float fade = 1.;\n"
+ " highp float fadeIn = min(t * 10., 1.);\n"
+ " highp float fadeOut = 1. - clamp((t - 0.75) * 4.,0., 1.);\n"
+ "\n"
+ "#ifdef TABLE\n"
+ " currentSize = currentSize * sizetable[int(floor(t*64.))];\n"
+ " fade = fade * opacitytable[int(floor(t*64.))];\n"
+ "#endif\n"
+ "\n"
+ " if (entry == 1.)\n"
+ " fade = fade * fadeIn * fadeOut;\n"
+ " else if (entry == 2.)\n"
+ " currentSize = currentSize * fadeIn * fadeOut;\n"
+ "\n"
+ " if (currentSize <= 0)//Sizes too small look jittery as they move\n"
+ " currentSize = 0;\n"
+ " else if (currentSize < 3)\n"
+ " currentSize = 3;\n"
+ "\n"
+ " highp vec2 pos;\n"
+ "#ifdef DEFORM\n"
+ " highp float rotation = vRotation.x + vRotation.y * t * vData.y;\n"
+ " if (vRotation.z == 1.0){\n"
+ " highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;\n"
+ " rotation += atan(curVel.y, curVel.x);\n"
+ " }\n"
+ " highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation));\n"
+ " highp vec4 deform = vDeformVec * currentSize * (vTex.xxyy - 0.5);\n"
+ " highp vec4 rotatedDeform = deform.xxzz * trigCalcs.xyxy;\n"
+ " rotatedDeform = rotatedDeform + (deform.yyww * trigCalcs.yxyx * vec4(-1.,1.,-1.,1.));\n"
+ " /* The readable version:\n"
+ " highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5);\n"
+ " highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5);\n"
+ " highp vec2 xRotatedDeform;\n"
+ " xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y;\n"
+ " xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y;\n"
+ " highp vec2 yRotatedDeform;\n"
+ " yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y;\n"
+ " yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y;\n"
+ " */\n"
+ " pos = vPos\n"
+ " + rotatedDeform.xy\n"
+ " + rotatedDeform.zw\n"
+ " + vVec.xy * t * vData.y // apply speed\n"
+ " + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration\n"
+ "#else\n"
+ " pos = vPos\n"
+ " + vVec.xy * t * vData.y // apply speed vector..\n"
+ " + 0.5 * vVec.zw * pow(t * vData.y, 2.);\n"
+ " gl_PointSize = currentSize;\n"
+ "#endif\n"
+ " gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);\n"
+ "\n"
+ "#ifdef COLOR\n"
+ " fColor = vColor * fade;\n"
+ "#else\n"
+ " fFade = fade;\n"
+ "#endif\n"
+ "#ifdef TABLE\n"
+ " tt.x = t;\n"
+ "#endif\n"
+ "}\n";
+
+static const char fragmentShaderCode[] =
+ "uniform sampler2D texture;\n"
+ "uniform lowp float qt_Opacity;\n"
+ "\n"
+ "#ifdef SPRITE\n"
+ "varying highp vec4 fTexS;\n"
+ "#else\n"
+ "#ifdef DEFORM //First non-pointsprite\n"
+ "varying highp vec2 fTex;\n"
+ "#endif\n"
+ "#endif\n"
+ "#ifdef COLOR\n"
+ "varying lowp vec4 fColor;\n"
+ "#else\n"
+ "varying lowp float fFade;\n"
+ "#endif\n"
+ "#ifdef TABLE\n"
+ "varying lowp vec2 tt;\n"
+ "uniform sampler2D colortable;\n"
+ "#endif\n"
+ "\n"
+ "void main() {\n"
+ "#ifdef SPRITE\n"
+ " gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), tt.y)\n"
+ " * fColor\n"
+ " * texture2D(colortable, tt)\n"
+ " * qt_Opacity;\n"
+ "#else\n"
+ "#ifdef TABLE\n"
+ " gl_FragColor = texture2D(texture, fTex)\n"
+ " * fColor\n"
+ " * texture2D(colortable, tt)\n"
+ " * qt_Opacity;\n"
+ "#else\n"
+ "#ifdef DEFORM\n"
+ " gl_FragColor = (texture2D(texture, fTex)) * fColor * qt_Opacity;\n"
+ "#else\n"
+ "#ifdef COLOR\n"
+ " gl_FragColor = (texture2D(texture, gl_PointCoord)) * fColor * qt_Opacity;\n"
+ "#else\n"
+ " gl_FragColor = texture2D(texture, gl_PointCoord) * (fFade * qt_Opacity);\n"
+ "#endif //COLOR\n"
+ "#endif //DEFORM\n"
+ "#endif //TABLE\n"
+ "#endif //SPRITE\n"
+ "}\n";
+
const qreal CONV = 0.017453292519943295;
class ImageMaterialData
{
QSizeF animSheetSize;
};
-//TODO: Move shaders inline once they've stablilized
class TabledMaterialData : public ImageMaterialData {};
class TabledMaterial : public QSGSimpleMaterialShader<TabledMaterialData>
{
public:
TabledMaterial()
{
- QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader"));
- vf.open(QFile::ReadOnly);
m_vertex_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n")
- + vf.readAll();
+ + vertexShaderCode;
- QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader"));
- ff.open(QFile::ReadOnly);
m_fragment_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n")
- + ff.readAll();
+ + fragmentShaderCode;
Q_ASSERT(!m_vertex_code.isNull());
Q_ASSERT(!m_fragment_code.isNull());
public:
DeformableMaterial()
{
- QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader"));
- vf.open(QFile::ReadOnly);
m_vertex_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define DEFORM\n#define COLOR\n")
- + vf.readAll();
+ + vertexShaderCode;
- QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader"));
- ff.open(QFile::ReadOnly);
m_fragment_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define DEFORM\n#define COLOR\n")
- + ff.readAll();
+ + fragmentShaderCode;
Q_ASSERT(!m_vertex_code.isNull());
Q_ASSERT(!m_fragment_code.isNull());
public:
SpriteMaterial()
{
- QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader"));
- vf.open(QFile::ReadOnly);
m_vertex_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n")
- + vf.readAll();
+ + vertexShaderCode;
- QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader"));
- ff.open(QFile::ReadOnly);
m_fragment_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n")
- + ff.readAll();
+ + fragmentShaderCode;
Q_ASSERT(!m_vertex_code.isNull());
Q_ASSERT(!m_fragment_code.isNull());
public:
ColoredMaterial()
{
- QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader"));
- vf.open(QFile::ReadOnly);
m_vertex_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define COLOR\n")
- + vf.readAll();
+ + vertexShaderCode;
- QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader"));
- ff.open(QFile::ReadOnly);
m_fragment_code = QByteArray(SHADER_DEFINES)
+ QByteArray("#define COLOR\n")
- + ff.readAll();
+ + fragmentShaderCode;
Q_ASSERT(!m_vertex_code.isNull());
Q_ASSERT(!m_fragment_code.isNull());
public:
SimpleMaterial()
{
- QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader"));
- vf.open(QFile::ReadOnly);
m_vertex_code = QByteArray(SHADER_DEFINES)
- + vf.readAll();
+ + vertexShaderCode;
- QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader"));
- ff.open(QFile::ReadOnly);
m_fragment_code = QByteArray(SHADER_DEFINES)
- + ff.readAll();
+ + fragmentShaderCode;
Q_ASSERT(!m_vertex_code.isNull());
Q_ASSERT(!m_fragment_code.isNull());
\qmlproperty list<Sprite> QtQuick.Particles2::ImageParticle::sprites
The sprite or sprites used to draw this particle.
+
+ Note that the sprite image will be scaled to a square based on the size of
+ the particle being rendered.
*/
/*!
\qmlproperty url QtQuick.Particles2::ImageParticle::colorTable
colortable = QImage(m_colortable_name.toLocalFile());
sizetable = QImage(m_sizetable_name.toLocalFile());
opacitytable = QImage(m_opacitytable_name.toLocalFile());
- if (colortable.isNull())
- colortable = QImage(QStringLiteral(":defaultshaders/identitytable.png"));
+ if (colortable.isNull()){
+ colortable = QImage(1,1,QImage::Format_ARGB32);
+ colortable.fill(Qt::white);
+ }
Q_ASSERT(!colortable.isNull());
getState<ImageMaterialData>(m_material)->colorTable = QSGPlainTexture::fromImage(colortable);
fillUniformArrayFromImage(getState<ImageMaterialData>(m_material)->sizeTable, sizetable, UNIFORM_ARRAY_SIZE);
if (!m_noiseSource.isEmpty())
image = QImage(m_noiseSource.toLocalFile()).scaled(QSize(m_gridSize, m_gridSize));
if (image.isNull())
- image = QImage(QStringLiteral(":defaultshaders/noise.png")).scaled(QSize(m_gridSize, m_gridSize));
+ image = QImage(QStringLiteral(":particleresources/noise.png")).scaled(QSize(m_gridSize, m_gridSize));
for (int i=0; i<m_gridSize; i++)
for (int j=0; j<m_gridSize; j++)