Project

General

Profile

« Previous | Next » 

Revision 81a0b906

Added by Leszek Koltunski about 7 years ago

Preparation for shader optimization

View differences:

src/main/res/raw/main_vertex_shader.glsl
45 45
uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
46 46
                                     // The first vec4 is the Interpolated values,
47 47
                                     // next is half cache half Center, the third -  the Region.
48
#endif
49

  
50
#if NUM_VERTEX>0
51 48

  
52 49
//////////////////////////////////////////////////////////////////////////////////////////////
53 50
// HELPER FUNCTIONS
......
214 211
//        along the force line is.
215 212
//        0<=C<1 looks completely ridiculous and C<0 destroys the system.
216 213

  
214
#ifdef DEFORM
217 215
void deform(in int effect, inout vec3 v, inout vec3 n)
218 216
  {
219 217
  const vec2 ONE = vec2(1.0,1.0);
......
253 251

  
254 252
  n.xy += n.z*b*ps;
255 253
  }
254
#endif
256 255

  
257 256
//////////////////////////////////////////////////////////////////////////////////////////////
258 257
// DISTORT EFFECT
......
309 308
// Thus we actually want to compute N(v.x,v.y) = a*(-(dx/|PS|)*f'(|PX|), -(dy/|PS|)*f'(|PX|), 1) and keep adding
310 309
// the first two components. (a is the horizontal part)
311 310

  
311
#ifdef DISTORT
312 312
void distort(in int effect, inout vec3 v, inout vec3 n)
313 313
  {
314 314
  vec2 center = vUniforms[effect+1].yz;
......
330 330
  v.xy += d*force.xy;
331 331
  n.xy += n.z*b*ps;
332 332
  }
333
#endif
333 334

  
334 335
//////////////////////////////////////////////////////////////////////////////////////////////
335 336
// SINK EFFECT
......
337 338
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P)
338 339
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P)
339 340

  
341
#ifdef SINK
340 342
void sink(in int effect,inout vec3 v)
341 343
  {
342 344
  vec2 center = vUniforms[effect+1].yz;
......
346 348

  
347 349
  v.xy += t*ps;
348 350
  }
351
#endif
349 352

  
350 353
//////////////////////////////////////////////////////////////////////////////////////////////
351 354
// PINCH EFFECT
......
356 359
// with P' = P + (1-h)*dist(line to P)
357 360
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P)
358 361

  
362
#ifdef PINCH
359 363
void pinch(in int effect,inout vec3 v)
360 364
  {
361 365
  vec2 center = vUniforms[effect+1].yz;
......
367 371

  
368 372
  v.xy += t*dot(ps,dir)*dir;
369 373
  }
374
#endif
370 375

  
371 376
//////////////////////////////////////////////////////////////////////////////////////////////
372 377
// SWIRL EFFECT
......
375 380
// This effect rotates the current vertex V by vInterpolated.x radians clockwise around the circle dilated
376 381
// by (1-d) around the center of the effect S.
377 382

  
383
#ifdef SWIRL
378 384
void swirl(in int effect, inout vec3 v)
379 385
  {
380 386
  vec2 center  = vUniforms[effect+1].yz;
......
393 399
                                                               // bitmap some points end up with d2<0 and they disappear off view.
394 400
  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?
395 401
  }
402
#endif
396 403

  
397 404
//////////////////////////////////////////////////////////////////////////////////////////////
398 405
// WAVE EFFECT
......
460 467
//
461 468
// Generally speaking I'd keep to amplitude < length, as the opposite case has some other problems as well.
462 469

  
470
#ifdef WAVE
463 471
void wave(in int effect, inout vec3 v, inout vec3 n)
464 472
  {
465 473
  vec2 center     = vUniforms[effect+1].yz;
......
522 530
      }
523 531
    }
524 532
  }
525

  
526 533
#endif
527 534

  
535
#endif  // NUM_VERTEX>0
536

  
528 537
//////////////////////////////////////////////////////////////////////////////////////////////
529 538

  
530 539
void main()
......
537 546

  
538 547
  for(int i=0; i<vNumEffects; i++)
539 548
    {
540
         if( vType[i]==DISTORT) distort(j,v,n);
541
    else if( vType[i]==DEFORM ) deform (j,v,n);
542
    else if( vType[i]==SINK   ) sink   (j,v);
543
    else if( vType[i]==PINCH  ) pinch  (j,v);
544
    else if( vType[i]==SWIRL  ) swirl  (j,v);
545
    else if( vType[i]==WAVE   ) wave   (j,v,n);
549
#ifdef DISTORT
550
    if( vType[i]==DISTORT) distort(j,v,n); else
551
#endif
552
#ifdef DEFORM
553
    if( vType[i]==DEFORM ) deform (j,v,n); else
554
#endif
555
#ifdef SINK
556
    if( vType[i]==SINK   ) sink   (j,v);   else
557
#endif
558
#ifdef PINCH
559
    if( vType[i]==PINCH  ) pinch  (j,v);   else
560
#endif
561
#ifdef SWIRL
562
    if( vType[i]==SWIRL  ) swirl  (j,v);   else
563
#endif
564
#ifdef WAVE
565
    if( vType[i]==WAVE   ) wave   (j,v,n); else
566
#endif
567
    {}
546 568

  
547 569
    j+=3;
548 570
    }

Also available in: Unified diff