Convert shaders in dali-demo to use shader compilation tool
[platform/core/uifw/dali-demo.git] / examples / sparkle / shaders / sparkle-effect.vert
1 precision highp float;
2
3 attribute vec2  aTexCoord;
4 uniform   mat4  uMvpMatrix;
5 varying   vec2  vTexCoord;
6
7 attribute vec2  aParticlePath0;
8 attribute vec2  aParticlePath1;
9 attribute vec2  aParticlePath2;
10 attribute vec2  aParticlePath3;
11 attribute vec2  aParticlePath4;
12 attribute vec2  aParticlePath5;
13
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;
23 uniform float uScale;
24 uniform float uBreak;
25
26 varying lowp vec4 vColor;
27
28 void main()
29 {
30   // we store the particle index inside texCoord attribute
31   float idx = abs(aTexCoord.y)-1.0;
32
33   // early out if the particle is invisible
34   if(uOpacity[int(idx)]<1e-5)
35   {
36     gl_Position = vec4(0.0);
37     vColor = vec4(0.0);
38     return;
39   }
40
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);
45
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
49   {
50     p0 = aParticlePath0;
51     p1 = aParticlePath1;
52     p2 = aParticlePath2;
53     p3 = aParticlePath3;
54   }
55   else
56   {
57     p0 = aParticlePath3;
58     p1 = aParticlePath4;
59     p2 = aParticlePath5;
60     p3 = aParticlePath0;
61   }
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;
64
65   vec2 referencePoint = mix(p0,p3,0.5);
66   float maxAnimationCount = float(MAXIMUM_ANIMATION_COUNT);
67
68   for( float i=uTapIndices.x; i<uTapIndices.y; i+=1.0 )
69   {
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] ) ;
73   }
74
75   position = mix( position, vec2( 250.0,250.0 ),uBreak*(1.0-uOpacity[int(idx)]) ) ;
76
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,
80                                    0.0, 1.0 );
81
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)];
86
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;
91
92   vTexCoord = clamp(aTexCoord, 0.0, 1.0);
93 }