Project

General

Profile

« Previous | Next » 

Revision dbeddd9d

Added by Leszek Koltunski almost 8 years ago

re-write the deform effect

View differences:

src/main/res/raw/main_vertex_shader.glsl
217 217
  
218 218
void deform(in int effect, inout vec4 v)
219 219
  {
220
  const float A = 0.5;
221
  const float B = 0.3;
222

  
220 223
  vec2 center = vUniforms[effect+1].yz;
221
  vec2 force = vUniforms[effect].xy;    // force = vec(MM')
222
  vec2 vert_vec, horz_vec; 
223
  vec2 signXY = sign(center-v.xy);
224
  vec2 time = (u_objD.xy+signXY*v.xy)/(u_objD.xy+signXY*center);
225
  vec2 factorV = vec2(0.5,0.5) + (center*v.xy)/(4.0*u_objD.xy*u_objD.xy);
226
  vec2 factorD = (u_objD.xy-signXY*center)/(2.0*u_objD.xy);
227
  vec2 vert_d = factorD.x*force;
228
  vec2 horz_d = factorD.y*force;
229
  float dot = dot(force,force);
230
  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).
231
                                                                                                // .y = the vector tangent to X(t) at Fb = 0.3*vec(BM')  (or vec(TM') if signXY.y=-1)
232
                                                                                                // the scalar: make the length of the speed vectors at Fl and Fr be 0 when force vector 'force' is zero
233
  vert_vec.x = ( force.x-vert_d.x-corr.x )*time.x*time.x + corr.x*time.x + vert_d.x;
234
  horz_vec.y = (-force.y+horz_d.y+corr.y )*time.y*time.y - corr.y*time.y - horz_d.y;
235
  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;
236
  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;
237
  
238
  v.xy += (factorV.y*vert_vec + factorV.x*horz_vec);
224
  vec2 force  = vUniforms[effect].xy;
225
  vec2 dist   = center-v.xy;
226
  vec2 aDist  = abs(dist.xy);
227
  vec2 maxdist= u_objD.xy + abs(center);
228
  vec2 aForce = abs(force);
229

  
230
  vec2 Aw = A*maxdist;
231
  vec2 quot = dist / maxdist;
232

  
233
  float mvXvert =-((B*dist.x*aForce.y)/(aForce.y + Aw.x))*(1.0-quot.y*quot.y);
234
  float mvYvert = force.y*( 1.0 - quot.x*quot.x*(Aw.x/(aForce.y+Aw.x)) ) * aForce.y/(aForce.y+aDist.y);
235

  
236
  float mvXhorz =-force.x*( 1.0 - quot.y*quot.y*(Aw.y/(aForce.x+Aw.y)) ) * aForce.x/(aForce.x+aDist.x);
237
  float mvYhorz =-((B*dist.y*aForce.x)/(aForce.x + Aw.y))*(1.0-quot.x*quot.x);
238

  
239
  v.x -= (mvXvert+mvXhorz);
240
  v.y -= (mvYvert+mvYhorz);
239 241
  }
240 242

  
241 243
//////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff