1#version 120 2 3#if defined(DEFORM) 4attribute highp vec4 vPosTex; 5#else 6attribute highp vec2 vPos; 7#endif 8 9attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize 10attribute highp vec4 vVec; // x,y = constant velocity, z,w = acceleration 11uniform highp float entry; 12 13#if defined(COLOR) 14attribute highp vec4 vColor; 15#endif 16 17#if defined(DEFORM) 18attribute highp vec4 vDeformVec; // x,y x unit vector; z,w = y unit vector 19attribute highp vec3 vRotation; // x = radians of rotation, y = rotation velocity, z = bool autoRotate 20#endif 21 22#if defined(SPRITE) 23attribute highp vec3 vAnimData; // w,h(premultiplied of anim), interpolation progress 24attribute highp vec4 vAnimPos; // x,y, x,y (two frames for interpolation) 25#endif 26 27uniform highp mat4 qt_Matrix; 28uniform highp float timestamp; 29 30#if defined(TABLE) 31varying lowp vec2 tt;//y is progress if Sprite mode 32uniform highp float sizetable[64]; 33uniform highp float opacitytable[64]; 34#endif 35 36#if defined(SPRITE) 37varying highp vec4 fTexS; 38#elif defined(DEFORM) 39varying highp vec2 fTex; 40#endif 41 42#if defined(COLOR) 43varying lowp vec4 fColor; 44#else 45varying lowp float fFade; 46#endif 47 48 49void main() 50{ 51 highp float t = (timestamp - vData.x) / vData.y; 52 if (t < 0. || t > 1.) { 53#if defined(DEFORM) 54 gl_Position = qt_Matrix * vec4(vPosTex.x, vPosTex.y, 0., 1.); 55#else 56 gl_PointSize = 0.; 57#endif 58 } else { 59#if defined(SPRITE) 60 tt.y = vAnimData.z; 61 62 // Calculate frame location in texture 63 fTexS.xy = vAnimPos.xy + vPosTex.zw * vAnimData.xy; 64 65 // Next frame is also passed, for interpolation 66 fTexS.zw = vAnimPos.zw + vPosTex.zw * vAnimData.xy; 67 68#elif defined(DEFORM) 69 fTex = vPosTex.zw; 70#endif 71 highp float currentSize = mix(vData.z, vData.w, t * t); 72 lowp float fade = 1.; 73 highp float fadeIn = min(t * 10., 1.); 74 highp float fadeOut = 1. - clamp((t - 0.75) * 4.,0., 1.); 75 76#if defined(TABLE) 77 currentSize = currentSize * sizetable[int(floor(t*64.))]; 78 fade = fade * opacitytable[int(floor(t*64.))]; 79#endif 80 81 if (entry == 1.) 82 fade = fade * fadeIn * fadeOut; 83 else if (entry == 2.) 84 currentSize = currentSize * fadeIn * fadeOut; 85 86 if (currentSize <= 0.) { 87#if defined(DEFORM) 88 gl_Position = qt_Matrix * vec4(vPosTex.x, vPosTex.y, 0., 1.); 89#else 90 gl_PointSize = 0.; 91#endif 92 } else { 93 if (currentSize < 3.) // Sizes too small look jittery as they move 94 currentSize = 3.; 95 96 highp vec2 pos; 97#if defined(DEFORM) 98 highp float rotation = vRotation.x + vRotation.y * t * vData.y; 99 if (vRotation.z == 1.0){ 100 highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy; 101 if (length(curVel) > 0.) 102 rotation += atan(curVel.y, curVel.x); 103 } 104 highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation)); 105 highp vec4 deform = vDeformVec * currentSize * (vPosTex.zzww - 0.5); 106 highp vec4 rotatedDeform = deform.xxzz * trigCalcs.xyxy; 107 rotatedDeform = rotatedDeform + (deform.yyww * trigCalcs.yxyx * vec4(-1.,1.,-1.,1.)); 108 /* The readable version: 109 highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5); 110 highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5); 111 highp vec2 xRotatedDeform; 112 xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y; 113 xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y; 114 highp vec2 yRotatedDeform; 115 yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y; 116 yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y; 117 */ 118 pos = vPosTex.xy 119 + rotatedDeform.xy 120 + rotatedDeform.zw 121 + vVec.xy * t * vData.y // apply velocity 122 + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration 123#else 124 pos = vPos 125 + vVec.xy * t * vData.y // apply velocity vector.. 126 + 0.5 * vVec.zw * pow(t * vData.y, 2.); 127 gl_PointSize = currentSize; 128#endif 129 gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1); 130 131#if defined(COLOR) 132 fColor = vColor * fade; 133#else 134 fFade = fade; 135#endif 136#if defined(TABLE) 137 tt.x = t; 138#endif 139 } 140 } 141} 142