3 attribute vec2 aTexCoord;
4 uniform mat4 uMvpMatrix;
5 varying vec2 vTexCoord;
7 attribute vec2 aParticlePath0;
8 attribute vec2 aParticlePath1;
9 attribute vec2 aParticlePath2;
10 attribute vec2 aParticlePath3;
11 attribute vec2 aParticlePath4;
12 attribute vec2 aParticlePath5;
14 uniform float uPercentage;
15 uniform float uPercentageMarked;
16 uniform vec3 uParticleColors[NUM_COLOR];
17 uniform float uOpacity[NUM_PARTICLE];
18 uniform vec2 uTapIndices;
19 uniform float uTapOffset[MAXIMUM_ANIMATION_COUNT];
20 uniform vec2 uTapPoint[MAXIMUM_ANIMATION_COUNT];
21 uniform float uAcceleration;
22 uniform float uRadius;
26 varying lowp vec4 vColor;
30 // we store the particle index inside texCoord attribute
31 float idx = abs(aTexCoord.y)-1.0;
33 // early out if the particle is invisible
34 if(uOpacity[int(idx)]<1e-5)
36 gl_Position = vec4(0.0);
41 // As the movement along the b-curve has nonuniform speed with a uniform increasing parameter 'uPercentage'
42 // we give different particles the different 'percentage' to make them looks more random
43 float increment = idx / float(NUM_PARTICLE)*5.0;
44 float percentage = mod(uPercentage +uAcceleration+increment, 1.0);
46 vec2 p0; vec2 p1; vec2 p2; vec2 p3;
47 // calculate the particle position by using the cubic b-curve equation
48 if(percentage<0.5) // particle on the first b-curve
62 float t = mod( percentage*2.0, 1.0);
63 vec2 position = (1.0-t)*(1.0-t)*(1.0-t)*p0 + 3.0*(1.0-t)*(1.0-t)*t*p1+3.0*(1.0-t)*t*t*p2 + t*t*t*p3;
65 vec2 referencePoint = mix(p0,p3,0.5);
66 float maxAnimationCount = float(MAXIMUM_ANIMATION_COUNT);
68 for( float i=uTapIndices.x; i<uTapIndices.y; i+=1.0 )
70 int id = int( mod(i+0.5,maxAnimationCount ) );
71 vec2 edgePoint = normalize(referencePoint-uTapPoint[id])*uRadius+vec2(uRadius);
72 position = mix( position, edgePoint, uTapOffset[id] ) ;
75 position = mix( position, vec2( 250.0,250.0 ),uBreak*(1.0-uOpacity[int(idx)]) ) ;
77 // vertex position on the mesh: (sign(aTexCoord.x), sign(aTexCoord.y))*PARTICLE_HALF_SIZE
78 gl_Position = uMvpMatrix * vec4( position.x+sign(aTexCoord.x)*PARTICLE_HALF_SIZE/uScale,
79 position.y+sign(aTexCoord.y)*PARTICLE_HALF_SIZE/uScale,
82 // we store the color index inside texCoord attribute
83 float colorIndex = abs(aTexCoord.x);
84 vColor.rgb = uParticleColors[int(colorIndex)-1];
85 vColor.a = fract(colorIndex) * uOpacity[int(idx)];
87 // produce a 'seemingly' random fade in/out
88 percentage = mod(uPercentage+increment+0.15, 1.0);
89 float ramdomOpacity = (min(percentage, 0.25)-0.15+0.9-max(percentage,0.9))*10.0;
90 vColor.a *=ramdomOpacity;
92 vTexCoord = clamp(aTexCoord, 0.0, 1.0);