Project

General

Profile

« Previous | Next » 

Revision 4fde55a0

Added by Leszek Koltunski over 7 years ago

Beginnings of the WAVE effect.

View differences:

src/main/res/raw/main_vertex_shader.glsl
40 40

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

  
48 48
#if NUM_VERTEX>0
......
93 93
// where a = PS*PO/|PS| but we are really looking for d = |PX|/(|PX|+|PS|) = 1/(1+ (|PS|/|PX|) ) and
94 94
// |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.
95 95

  
96
float degree_region(in vec3 region, in vec2 PS)
96
float degree_region(in vec4 region, in vec2 PS)
97 97
  {
98 98
  vec2 PO  = PS + region.xy;
99 99
  float D = region.z*region.z-dot(PO,PO);      // D = |OX|^2 - |PO|^2
......
118 118
//////////////////////////////////////////////////////////////////////////////////////////////
119 119
// return min(degree_bitmap,degree_region). Just like degree_region, currently only supports circles.
120 120

  
121
float degree(in vec3 region, in vec2 S, in vec2 PS)
121
float degree(in vec4 region, in vec2 S, in vec2 PS)
122 122
  {
123 123
  vec2 PO  = PS + region.xy;
124 124
  float D = region.z*region.z-dot(PO,PO);      // D = |OX|^2 - |PO|^2
......
205 205
  
206 206
void deform(in int effect, inout vec4 v)
207 207
  {
208
  vec2 center = vUniforms[effect+2].yz;
208
  vec2 center = vUniforms[effect+1].zw;
209 209
  vec2 force = vUniforms[effect].xy;    // force = vec(MM')
210 210
  vec2 vert_vec, horz_vec; 
211 211
  vec2 signXY = sign(center-v.xy);
......
283 283
        
284 284
void distort(in int effect, inout vec4 v, inout vec4 n)
285 285
  {
286
  vec2 point = vUniforms[effect+2].yz;
287
  vec2 ps = point-v.xy;
288
  float d = degree(vUniforms[effect+1],point,ps);
286
  vec2 center = vUniforms[effect+1].zw;
287
  vec2 ps = center-v.xy;
288
  float d = degree(vUniforms[effect+2],center,ps);
289 289
  vec2 w = vec2(vUniforms[effect].x, -vUniforms[effect].y);
290 290
  float uz = vUniforms[effect].z;                                         // height of the bubble
291 291
  float denominator = dot(ps+(1.0-d)*w,ps);
......
312 312
 
313 313
void sink(in int effect,inout vec4 v)
314 314
  {
315
  vec2 point = vUniforms[effect+2].yz;
316
  vec2 ps = point-v.xy;
315
  vec2 center = vUniforms[effect+1].zw;
316
  vec2 ps = center-v.xy;
317 317
  float h = vUniforms[effect].x;
318
  float t = degree(vUniforms[effect+1],point,ps) * (1.0-h)/max(1.0,h);                                                                        
318
  float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h);
319 319
  
320 320
  v.xy += t*ps;           
321 321
  }
......
329 329

  
330 330
void swirl(in int effect, inout vec4 v)
331 331
  {
332
  vec2 S  = vUniforms[effect+2].yz;
333
  vec2 PS = S-v.xy;
334
  vec3 SO = vUniforms[effect+1];
332
  vec2 center  = vUniforms[effect+1].zw;
333
  vec2 PS = center-v.xy;
334
  vec4 SO = vUniforms[effect+2];
335 335
  float d1_circle = degree_region(SO,PS);
336
  float d1_bitmap = degree_bitmap(S,PS);
337
  float sinA = vUniforms[effect].y;                            // sin(A) precomputed in EffectListVertex.postprocess
338
  float cosA = vUniforms[effect].z;                            // cos(A) precomputed in EffectListVertex.postprocess
339
  vec2 PS2 = vec2( PS.x*cosA+PS.y*sinA,-PS.x*sinA+PS.y*cosA ); // vector PS rotated by A radians clockwise around S.
340
  vec3 SG = (1.0-d1_circle)*SO;                                // coordinates of the dilated circle P is going to get rotated around
341
  float d2 = max(0.0,degree(SG,S,PS2));                        // make it a max(0,deg) because otherwise when S=left edge of the
336
  float d1_bitmap = degree_bitmap(center,PS);
337
  float sinA = vUniforms[effect+1].x;                          // sin(A) precomputed in EffectListVertex.postprocess
338
  float cosA = vUniforms[effect+1].y;                          // cos(A) precomputed in EffectListVertex.postprocess
339
  vec2 PS2 = vec2( PS.x*cosA+PS.y*sinA,-PS.x*sinA+PS.y*cosA ); // vector PS rotated by A radians clockwise around center.
340
  vec4 SG = (1.0-d1_circle)*SO;                                // coordinates of the dilated circle P is going to get rotated around
341
  float d2 = max(0.0,degree(SG,center,PS2));                   // make it a max(0,deg) because otherwise when center=left edge of the
342 342
                                                               // bitmap some points end up with d2<0 and they disappear off view.
343
  v.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?
343
  v.xy += min(d1_circle,d1_bitmap)*(PS - PS2/(1.0-d2));        // if d2=1 (i.e P=center) we should have P unchanged. How to do it?
344
  }
345

  
346
//////////////////////////////////////////////////////////////////////////////////////////////
347
// WAVE EFFECT
348
//
349
// Directional sinusoidal wave effect.
350

  
351
void wave(in int effect, inout vec4 v)
352
  {
353
  vec2 center = vUniforms[effect+1].zw;
354
  vec2 ps = center-v.xy;
355
  float deg = degree_region(vUniforms[effect+2],ps);
356
  vec2 sincos = vUniforms[effect+1].xy;
357

  
358
  float amplitude = vUniforms[effect].x;
359
  float angle     = vUniforms[effect].y;
360
  float length    = vUniforms[effect].z;
361
  float d = dot( vec2(-ps.y,-ps.x),sincos );
362
  float num = length==0.0 ? 1.0 : d / length;
363
  float floornum = floor(num);
364
  float therest = num-floornum;
365
  float phi = mod(floornum,2.0) == 0.0 ? 1.0-therest:therest;
366

  
367
  v.xy += (phi*amplitude*deg*sincos);
344 368
  }
345 369

  
346 370
#endif
......
359 383
    else if( vType[i]==DEFORM ) deform (3*i,v);
360 384
    else if( vType[i]==SINK   ) sink   (3*i,v);
361 385
    else if( vType[i]==SWIRL  ) swirl  (3*i,v);
386
    else if( vType[i]==WAVE   ) wave   (3*i,v);
362 387
    }
363 388
 
364 389
  restrict(v.z);  

Also available in: Unified diff