Project

General

Profile

Download (20.4 KB) Statistics
| Branch: | Revision:

library / src / main / res / raw / main_vertex_shader.glsl @ cd174a64

1
//////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                          //
3
//                                                                                          //
4
// This file is part of Distorted.                                                          //
5
//                                                                                          //
6
// Distorted is free software: you can redistribute it and/or modify                        //
7
// it under the terms of the GNU General Public License as published by                     //
8
// the Free Software Foundation, either version 2 of the License, or                        //
9
// (at your option) any later version.                                                      //
10
//                                                                                          //
11
// Distorted is distributed in the hope that it will be useful,                             //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                           //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                            //
14
// GNU General Public License for more details.                                             //
15
//                                                                                          //
16
// You should have received a copy of the GNU General Public License                        // 
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18
//////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
uniform vec3 u_objD;                      // half of object width x half of object height X half the depth;
21
                                          // point (0,0,0) is the center of the object
22

    
23
uniform float u_Depth;                    // max absolute value of v.z ; beyond that the vertex would be culled by the near or far planes.
24
                                          // I read OpenGL ES has a built-in uniform variable gl_DepthRange.near = n, 
25
                                          // .far = f, .diff = f-n so maybe u_Depth is redundant
26
                                          // Update: this struct is only available in fragment shaders
27
                                
28
uniform mat4 u_MVPMatrix;                 // A constant representing the combined model/view/projection matrix.      		       
29
uniform mat4 u_MVMatrix;                  // A constant representing the combined model/view matrix.       		
30
		 
31
attribute vec3 a_Position;                // Per-vertex position information we will pass in.   				
32
attribute vec4 a_Color;                   // Per-vertex color information we will pass in. 				
33
attribute vec3 a_Normal;                  // Per-vertex normal information we will pass in.      
34
attribute vec2 a_TexCoordinate;           // Per-vertex texture coordinate information we will pass in. 		
35
		  
36
varying vec3 v_Position;                  //      		
37
varying vec4 v_Color;                     // Those will be passed into the fragment shader.          		
38
varying vec3 v_Normal;                    //  
39
varying vec2 v_TexCoordinate;             //  		
40

    
41
uniform int vNumEffects;                  // total number of vertex effects
42

    
43
#if NUM_VERTEX>0
44
uniform int vType[NUM_VERTEX];            // their types.
45
uniform vec3 vUniforms[3*NUM_VERTEX];     // i-th effect is 3 consecutive vec3's: [3*i], [3*i+1], [3*i+2]. 
46
                                          // The first 3 floats are the Interpolated values,
47
                                          // next 4 are the Region, next 2 are the Center.
48
#endif
49

    
50
#if NUM_VERTEX>0
51

    
52
//////////////////////////////////////////////////////////////////////////////////////////////
53
// HELPER FUNCTIONS
54
//////////////////////////////////////////////////////////////////////////////////////////////
55
// Let (v.x,v.y) be point P (the current vertex).
56
// Let vPoint[effect].xy be point S (the center of effect)
57
// Let vPoint[effect].xy + vRegion[effect].xy be point O (the center of the Region circle)
58
// Let X be the point where the halfline SP meets a) if region is non-null, the region circle b) otherwise, the edge of the bitmap.
59
//
60
// If P is inside the Region, this function returns |PX|/||SX|, aka the 'degree' of point P. Otherwise, it returns 0.
61
//
62
// We compute the point where half-line from S to P intersects the edge of the bitmap. If that's inside the circle, end. If not, we solve the
63
// the triangle with vertices at O, P and the point of intersection with the circle we are looking for X.
64
// We know the lengths |PO|, |OX| and the angle OPX , because cos(OPX) = cos(180-OPS) = -cos(OPS) = -PS*PO/(|PS|*|PO|)
65
// then from the law of cosines PX^2 + PO^2 - 2*PX*PO*cos(OPX) = OX^2 so
66
// PX = -a + sqrt(a^2 + OX^2 - PO^2) where a = PS*PO/|PS| but we are really looking for d = |PX|/(|PX|+|PS|) = 1/(1+ (|PS|/|PX|) ) and
67
// |PX|/|PS| = -b + sqrt(b^2 + (OX^2-PO^2)/PS^2) where b=PS*PO/|PS|^2 which can be computed with only one sqrt.
68
//
69
// the trick below is the if-less version of the
70
//
71
// t = dx<0.0 ? (u_objD.x-v.x) / (u_objD.x-ux) : (u_objD.x+v.x) / (u_objD.x+ux);
72
// h = dy<0.0 ? (u_objD.y-v.y) / (u_objD.y-uy) : (u_objD.y+v.y) / (u_objD.y+uy);
73
// d = min(t,h);
74
//
75
// float d = min(-ps.x/(sign(ps.x)*u_objD.x+p.x),-ps.y/(sign(ps.y)*u_objD.y+p.y))+1.0;
76
//
77
// We still have to avoid division by 0 when p.x = +- u_objD.x or p.y = +- u_objD.y (i.e on the edge of the Object)
78
// We do that by first multiplying the above 'float d' with sign(denominator1*denominator2)^2.
79
//
80
//////////////////////////////////////////////////////////////////////////////////////////////
81
// return degree of the point as defined by the bitmap rectangle
82

    
83
float degree_bitmap(in vec2 S, in vec2 PS)
84
  {
85
  vec2 A = sign(PS)*u_objD.xy + S;
86

    
87
  vec2 signA = sign(A);                           //
88
  vec2 signA_SQ = signA*signA;                    // div = PS/A if A!=0, 0 otherwise.
89
  vec2 div = signA_SQ*PS/(A+signA_SQ-vec2(1,1));  //
90

    
91
  return 1.0-max(div.x,div.y);
92
  }
93

    
94
//////////////////////////////////////////////////////////////////////////////////////////////
95
// return degree of the point as defined by the Region
96
// Currently only supports circles; .xy = vector from center of effect to the center of the circle, .z = radius
97

    
98
float degree_region(in vec3 region, in vec2 PS)
99
  {
100
  vec2 PO  = PS + region.xy;
101
  float D = region.z*region.z-dot(PO,PO);      // D = |OX|^2 - |PO|^2
102
  float ps_sq = dot(PS,PS);
103
  float one_over_ps_sq = 1.0/(ps_sq+1.0-sign(ps_sq));  // return 1.0 if ps_sq = 0.0
104
  float DOT  = dot(PS,PO)*one_over_ps_sq;
105

    
106
  return max(sign(D),0.0) / (1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT));  // if D<=0 (i.e p is outside the Region) return 0.
107
  }
108

    
109
//////////////////////////////////////////////////////////////////////////////////////////////
110
// return min(degree_bitmap,degree_region). Just like degree_region, currently only supports circles.
111

    
112
float degree(in vec3 region, in vec2 S, in vec2 PS)
113
  {
114
  vec2 PO  = PS + region.xy;
115
  float D = region.z*region.z-dot(PO,PO);      // D = |OX|^2 - |PO|^2
116
  vec2 A = sign(PS)*u_objD.xy + S;
117
  vec2 signA = sign(A);
118
  vec2 signA_SQ = signA*signA;
119
  vec2 div = signA_SQ*PS/(A+signA_SQ-vec2(1,1));
120
  float E = 1.0-max(div.x,div.y);
121

    
122
  float ps_sq = dot(PS,PS);
123
  float one_over_ps_sq = 1.0/(ps_sq+1.0-sign(ps_sq));  // return 1.0 if ps_sq = 0.0
124
  float DOT  = dot(PS,PO)*one_over_ps_sq;
125

    
126
  return max(sign(D),0.0) * min(1.0/(1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT)),E);  // if D<=0 (i.e p is outside the Region) return 0.
127
  }
128

    
129
//////////////////////////////////////////////////////////////////////////////////////////////
130
// Clamp v.z to (-u_Depth,u_Depth) with the following function:
131
// define h to be, say, 0.7; let H=u_Depth
132
//      if v.z < -hH then v.z = (-(1-h)^2 * H^2)/(v.z+(2h-1)H) -H   (function satisfying f(-hH)=-hH, f'(-hH)=1, lim f(x) = -H)
133
// else if v.z >  hH then v.z = (-(1-h)^2 * H^2)/(v.z-(2h-1)H) +H   (function satisfying f(+hH)=+hH, f'(+hH)=1, lim f(x) = +H)
134
// else v.z = v.z
135

    
136
void restrict(inout float v)
137
  {
138
  const float h = 0.7;
139
  float signV = 2.0*max(0.0,sign(v))-1.0;
140
  float c = ((1.0-h)*(h-1.0)*u_Depth*u_Depth)/(v-signV*(2.0*h-1.0)*u_Depth) +signV*u_Depth;
141
  float b = max(0.0,sign(abs(v)-h*u_Depth));
142

    
143
  v = b*c+(1.0-b)*v; // Avoid branching: if abs(v)>h*u_Depth, then v=c; otherwise v=v.
144
  }
145

    
146
//////////////////////////////////////////////////////////////////////////////////////////////
147
// DEFORM EFFECT
148
//
149
// Deform the whole shape of the Object by force V
150
// 
151
// If the point of application (Sx,Sy) is on the edge of the Object, then:
152
// a) ignore Vz
153
// b) change shape of the whole Object in the following way:
154
//    Suppose the upper-left corner of the Object rectangle is point L, upper-right - R, force vector V is applied to point M on the upper edge,
155
//    width of the Object = w, height = h, |LM| = Wl, |MR| = Wr, force vector V=(Vx,Vy). Also let H = h/(h+Vy)
156
//
157
//    Let now L' and R' be points such that vec(LL') = Wr/w * vec(V) and vec(RR') = Wl/w * vec(V)
158
//    now let Vl be a point on the line segment L --> M+vec(V) such that Vl(y) = L'(y)
159
//    and let Vr be a point on the line segment R --> M+vec(V) such that Vr(y) = R'(y)
160
//    
161
//    Now define points Fl and Fr, the points L and R will be moved to under force V, with Fl(y)=L'(y) and Fr(y)=R'(y) and |VrFr|/|VrR'| = |VlFl|/|VlL'| = H
162
//    Now notice that |VrR'| = |VlL'| = Wl*Wr / w   ( a little geometric puzzle! )
163
//
164
//    Then points L,R under force V move by vectors vec(Fl), vec(Fr) where
165
//    vec(Fl) = (Wr/w) * [ (Vx+Wl)-Wl*H, Vy ] = (Wr/w) * [ Wl*Vy / (h+Vy) + Vx, Vy ]
166
//    vec(Fr) = (Wl/w) * [ (Vx-Wr)+Wr*H, Vy ] = (Wl/w) * [-Wr*Vy / (h+Vy) + Vx, Vy ]
167
//
168
//    Lets now denote M+vec(V) = M'. The line segment LMR gets distorted to the curve Fl-M'-Fr. Let's now arbitrarilly decide that:
169
//    a) at point Fl the curve has to be parallel to line LM'
170
//    b) at point M' - to line LR
171
//    c) at point Fr - to line M'R
172
//
173
//    Now if Fl=(flx,fly) , M'=(mx,my) , Fr=(frx,fry); direction vector at Fl is (vx,vy) and at M' is (+c,0) where +c is some positive constant, then 
174
//    the parametric equations of the Fl--->M' section of the curve (which has to satisfy (X(0),Y(0)) = Fl, (X(1),Y(1))=M', (X'(0),Y'(0)) = (vx,vy), (X'(1),Y'(1)) = (+c,0)) is
175
//
176
//    X(t) = ( (mx-flx)-vx )t^2 + vx*t + flx                                  (*)
177
//    Y(t) = ( vy - 2(my-fly) )t^3 + ( 3(my-fly) -2vy )t^2 + vy*t + fly
178
//
179
//    Here we have to have X'(1) = 2(mx-flx)-vx which is positive <==> vx<2(mx-flx). We also have to have vy<2(my-fly) so that Y'(t)>0 (this is a must otherwise we have local loops!) 
180
//    Similarly for the Fr--->M' part of the curve we have the same equation except for the fact that this time we have to have X'(1)<0 so now we have to have vx>2(mx-flx).
181
//
182
//    If we are stretching the left or right edge of the bitmap then the only difference is that we have to have (X'(1),Y'(1)) = (0,+-c) with + or - c depending on which part of the curve
183
//    we are tracing. Then the parametric equation is
184
//
185
//    X(t) = ( vx - 2(mx-flx) )t^3 + ( 3(mx-flx) -2vx )t^2 + vx*t + flx
186
//    Y(t) = ( (my-fly)-vy )t^2 + vy*t + fly
187
//
188
//    If we are dragging the top edge:    
189
//
190
//    Now point (x,u_objD.x) on the top edge will move by vector (X(t),Y(t)) where those functions are given by (*) and
191
//    t =  x < dSx ? (u_objD.x+x)/(u_objD.x+dSx) : (u_objD.x-x)/(u_objD.x-dSx)    (this is 'vec2 time' below in the code)
192
//    Any point (x,y) will move by vector (a*X(t),a*Y(t)) where a is (y+u_objD.y)/(2*u_objD.y)
193
  
194
void deform(in int effect, inout vec4 v)
195
  {
196
  vec2 center = vUniforms[effect+2].yz;
197
  vec2 force = vUniforms[effect].xy;    // force = vec(MM')
198
  vec2 vert_vec, horz_vec; 
199
  vec2 signXY = sign(center-v.xy);
200
  vec2 time = (u_objD.xy+signXY*v.xy)/(u_objD.xy+signXY*center);
201
  vec2 factorV = vec2(0.5,0.5) + (center*v.xy)/(4.0*u_objD.xy*u_objD.xy);
202
  vec2 factorD = (u_objD.xy-signXY*center)/(2.0*u_objD.xy);
203
  vec2 vert_d = factorD.x*force;
204
  vec2 horz_d = factorD.y*force;
205
  float dot = dot(force,force);
206
  vec2 corr = 0.33 * (center+force+signXY*u_objD.xy) * dot / ( dot + (4.0*u_objD.x*u_objD.x) ); // .x = the vector tangent to X(t) at Fl = 0.3*vec(LM')  (or vec(RM') if signXY.x=-1).
207
                                                                                                // .y = the vector tangent to X(t) at Fb = 0.3*vec(BM')  (or vec(TM') if signXY.y=-1)
208
                                                                                                // the scalar: make the length of the speed vectors at Fl and Fr be 0 when force vector 'force' is zero
209
  vert_vec.x = ( force.x-vert_d.x-corr.x )*time.x*time.x + corr.x*time.x + vert_d.x;
210
  horz_vec.y = (-force.y+horz_d.y+corr.y )*time.y*time.y - corr.y*time.y - horz_d.y;
211
  vert_vec.y = (-3.0*vert_d.y+2.0*force.y )*time.x*time.x*time.x + (-3.0*force.y+5.0*vert_d.y )*time.x*time.x - vert_d.y*time.x - vert_d.y;
212
  horz_vec.x = ( 3.0*horz_d.x-2.0*force.x )*time.y*time.y*time.y + ( 3.0*force.x-5.0*horz_d.x )*time.y*time.y + horz_d.x*time.y + horz_d.x;
213
  
214
  v.xy += (factorV.y*vert_vec + factorV.x*horz_vec);
215
  }
216

    
217
//////////////////////////////////////////////////////////////////////////////////////////////
218
// DISTORT EFFECT
219
//
220
// Point (Px,Py) gets moved by vector (Wx,Wy,Wz) where Wx/Wy = Vx/Vy i.e. Wx=aVx and Wy=aVy where 
221
// a=Py/Sy (N --> when (Px,Py) is above (Sx,Sy)) or a=Px/Sx (W) or a=(w-Px)/(w-Sx) (E) or a=(h-Py)/(h-Sy) (S) 
222
// It remains to be computed which of the N,W,E or S case we have: answer: a = min[ Px/Sx , Py/Sy , (w-Px)/(w-Sx) , (h-Py)/(h-Sy) ]
223
// Computations above are valid for screen (0,0)x(w,h) but here we have (-w/2,-h/2)x(w/2,h/2)
224
//  
225
// the vertical part
226
// Let |(v.x,v.y),(ux,uy)| = |PS|, ux-v.x=dx,uy-v.y=dy, f(x) (0<=x<=|SX|) be the shape of the side of the bubble.
227
// H(v.x,v.y) = |PS|>|SX| ? 0 : f(|PX|)
228
// N(v.x,v.y) = |PS|>|SX| ? (0,0,1) : ( -(dx/|PS|)sin(beta), -(dy/|PS|)sin(beta), cos(beta) ) where tan(beta) is f'(|PX|) 
229
// ( i.e. normalize( dx, dy, -|PS|/f'(|PX|))         
230
//
231
// Now we also have to take into account the effect horizontal move by V=(u_dVx[i],u_dVy[i]) will have on the normal vector.
232
// Solution: 
233
// 1. Decompose the V into two subcomponents, one parallel to SX and another perpendicular.
234
// 2. Convince yourself (draw!) that the perpendicular component has no effect on normals.
235
// 3. The parallel component changes the length of |SX| by the factor of a=(|SX|-|Vpar|)/|SX| (where the length can be negative depending on the direction)   
236
// 4. that in turn leaves the x and y parts of the normal unchanged and multiplies the z component by a!
237
//
238
// |Vpar| = (u_dVx[i]*dx - u_dVy[i]*dy) / sqrt(ps_sq) = (Vx*dx-Vy*dy)/ sqrt(ps_sq)  (-Vy because y is inverted)
239
// a =  (|SX| - |Vpar|)/|SX| = 1 - |Vpar|/((sqrt(ps_sq)/(1-d)) = 1 - (1-d)*|Vpar|/sqrt(ps_sq) = 1-(1-d)*(Vx*dx-Vy*dy)/ps_sq 
240
//
241
// Side of the bubble
242
// 
243
// choose from one of the three bubble shapes: the cone, the thin bubble and the thick bubble          
244
// Case 1: 
245
// f(t) = t, i.e. f(x) = uz * x/|SX|   (a cone)
246
// -|PS|/f'(|PX|) = -|PS|*|SX|/uz but since ps_sq=|PS|^2 and d=|PX|/|SX| then |PS|*|SX| = ps_sq/(1-d)
247
// so finally -|PS|/f'(|PX|) = -ps_sq/(uz*(1-d))
248
//                    
249
// Case 2: 
250
// f(t) = 3t^2 - 2t^3 --> f(0)=0, f'(0)=0, f'(1)=0, f(1)=1 (the bell curve)
251
// here we have t = x/|SX| which makes f'(|PX|) = 6*uz*|PS|*|PX|/|SX|^3.
252
// so -|PS|/f'(|PX|) = (-|SX|^3)/(6uz|PX|) =  (-|SX|^2) / (6*uz*d) but
253
// d = |PX|/|SX| and ps_sq = |PS|^2 so |SX|^2 = ps_sq/(1-d)^2
254
// so finally -|PS|/f'(|PX|) = -ps_sq/ (6uz*d*(1-d)^2)
255
//                  
256
// Case 3:
257
// f(t) = 3t^4-8t^3+6t^2 would be better as this safisfies f(0)=0, f'(0)=0, f'(1)=0, f(1)=1 and f(0.5)=0.7 and f'(t)= t(t-1)^2 >=0 for t>=0
258
// so this produces a fuller, thicker bubble!
259
// then -|PS|/f'(|PX|) = (-|PS|*|SX)) / (12uz*d*(d-1)^2) but |PS|*|SX| = ps_sq/(1-d) (see above!) 
260
// so finally -|PS|/f'(|PX|) = -ps_sq/ (12uz*d*(1-d)^3)  
261
//
262
// Now, new requirement: we have to be able to add up normal vectors, i.e. distort already distorted surfaces.
263
// If a surface is given by z = f(x,y), then the normal vector at (x0,y0) is given by (df/dx (x0,y0), df/dy (x0,y0), 1 ).
264
// so if we have two surfaces defined by f1(x,y) and f2(x,y) with their normals expressed as (f1x,f1y,1) and (f2x,f2y,1) 
265
// then the normal to g = f1+f2 is simply given by (f1x+f2x,f1y+f2y,1), i.e. if the third component is 1, then we can simply
266
// add up the first and second components.
267
//
268
// Thus we actually want to compute N(v.x,v.y) = a*(-(dx/|PS|)*f'(|PX|), -(dy/|PS|)*f'(|PX|), 1) and keep adding the first two components. 
269
// (a is the horizontal part)
270
        
271
void distort(in int effect, inout vec4 v, inout vec4 n)
272
  {
273
  vec2 point = vUniforms[effect+2].yz;
274
  vec2 ps = point-v.xy;
275
  float d = degree(vUniforms[effect+1],point,ps);
276
  vec2 w = vec2(vUniforms[effect].x, -vUniforms[effect].y);
277
  float dt = dot(ps,ps);
278
  float uz = vUniforms[effect].z; // height of the bubble
279
     
280
  //v.z += uz*d;                                                                                // cone
281
  //b = -(uz*(1.0-d)) / (dt + (1.0-d)*dot(w,ps) + (sign(dt)-1.0) );                             //
282
        
283
  //v.z += uz*d*d*(3.0-2.0*d);                                                                  // thin bubble
284
  //b = -(6.0*uz*d*(1.0-d)*(1.0-d)) / (dt + (1.0-d)*dot(w,ps) + (sign(dt)-1.0) );               //
285
        
286
  v.z += uz*d*d*(3.0*d*d -8.0*d +6.0);                                                          // thick bubble
287
  float b = -(12.0*uz*d*(1.0-d)*(1.0-d)*(1.0-d)) / (dt + (1.0-d)*dot(w,ps) + (sign(dt)-1.0) );  // the last part - (sign-1) is to avoid b being a NaN when ps=(0,0)
288
                
289
  v.xy += d*w;
290
  n.xy += b*ps;
291
  }
292
 
293
//////////////////////////////////////////////////////////////////////////////////////////////
294
// SINK EFFECT
295
//
296
// Pull P=(v.x,v.y) towards S=vPoint[effect] with P' = P + (1-h)d(S-P)
297
// when h>1 we are pushing points away from S: P' = P + (1/h-1)d(S-P)
298
 
299
void sink(in int effect,inout vec4 v)
300
  {
301
  vec2 point = vUniforms[effect+2].yz;
302
  vec2 ps = point-v.xy;
303
  float h = vUniforms[effect].x;
304
  float t = degree(vUniforms[effect+1],point,ps) * (1.0-h)/max(1.0,h);                                                                        
305
  
306
  v.xy += t*ps;           
307
  }
308

    
309
//////////////////////////////////////////////////////////////////////////////////////////////
310
// SWIRL EFFECT
311
//
312
// Let d be the degree of the current vertex V with respect to center of the effect S and Region vRegion.
313
// This effect rotates the current vertex V by vInterpolated.x radians clockwise around the circle dilated 
314
// by (1-d) around the center of the effect S.
315

    
316
void swirl(in int effect, inout vec4 P)
317
  {
318
  vec2 S  = vUniforms[effect+2].yz;
319
  vec2 PS = S-P.xy;
320
  vec3 SO = vUniforms[effect+1];
321
  float d1_circle = degree_region(SO,PS);
322
  float d1_bitmap = degree_bitmap(S,PS);
323
  float sinA = vUniforms[effect].y;                            // sin(A) precomputed in EffectListVertex.postprocess                                         
324
  float cosA = vUniforms[effect].z;                            // cos(A) precomputed in EffectListVertex.postprocess  
325
  vec2 PS2 = vec2( PS.x*cosA+PS.y*sinA,-PS.x*sinA+PS.y*cosA ); // vector PS rotated by A radians clockwise around S.                               
326
  vec3 SG = (1.0-d1_circle)*SO;                                // coordinates of the dilated circle P is going to get rotated around
327
  float d2 = max(0.0,degree(SG,S,PS2));                        // make it a max(0,deg) because when S=left edge of the bitmap, otherwise
328
                                                               // some points end up with d2<0 and they disappear off view.
329
  P.xy += min(d1_circle,d1_bitmap)*(PS - PS2/(1.0-d2));        // if d2=1 (i.e P=S) we should have P unchanged. How to do it?
330
  }
331

    
332
#endif
333

    
334
//////////////////////////////////////////////////////////////////////////////////////////////
335
  		  
336
void main()                                                 	
337
  {              
338
  vec4 v = vec4( 2.0*u_objD*a_Position,1.0 );
339
  vec4 n = vec4(a_Normal,0.0);
340

    
341
#if NUM_VERTEX>0
342
  for(int i=0; i<vNumEffects; i++)
343
    {
344
         if( vType[i]==DISTORT) distort(3*i,v,n);
345
    else if( vType[i]==DEFORM ) deform (3*i,v);
346
    else if( vType[i]==SINK   ) sink   (3*i,v);
347
    else if( vType[i]==SWIRL  ) swirl  (3*i,v);
348
    }
349
 
350
  restrict(v.z);  
351
#endif
352
   
353
  v_Position      = vec3(u_MVMatrix*v);           
354
  v_Color         = a_Color;              
355
  v_TexCoordinate = a_TexCoordinate;                                         
356
  v_Normal        = normalize(vec3(u_MVMatrix*n));
357
  gl_Position     = u_MVPMatrix*v;      
358
  }                               
(2-2/2)