Project

General

Profile

« Previous | Next » 

Revision 82ee855a

Added by Leszek Koltunski about 8 years ago

New vertex effect 'PINCH'

View differences:

src/main/java/org/distorted/library/DistortedObject.java
789 789
    return mV.add(EffectNames.SINK, sink, center);
790 790
    }
791 791

  
792
///////////////////////////////////////////////////////////////////////////////////////////////////
793
/**
794
 * Pull all points around the center of the Effect towards a line passing through the center
795
 * (that's if degree>=1) or push them away from the line (degree<=1)
796
 *
797
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
798
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
799
 * @param region Region that masks the Effect.
800
 * @return       ID of the effect added, or -1 if we failed to add one.
801
 */
802
  public long pinch(Data2D pinch, Data3D center, Data4D region)
803
    {
804
    return mV.add(EffectNames.PINCH, pinch, center, region);
805
    }
806

  
807
///////////////////////////////////////////////////////////////////////////////////////////////////
808
/**
809
 * Pull all points around the center of the Effect towards a line passing through the center
810
 * (that's if degree>=1) or push them away from the line (degree<=1)
811
 *
812
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
813
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
814
 * @return       ID of the effect added, or -1 if we failed to add one.
815
 */
816
  public long pinch(Data2D pinch, Data3D center)
817
    {
818
    return mV.add(EffectNames.PINCH, pinch, center);
819
    }
820

  
792 821
///////////////////////////////////////////////////////////////////////////////////////////////////  
793 822
/**
794 823
 * Rotate part of the Object around the Center of the Effect by a certain angle.
src/main/java/org/distorted/library/EffectNames.java
41 41
 */
42 42
public enum EffectNames
43 43
  {
44
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
44
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////// DIM // REGION // CENTER
45 45

  
46 46
  /////////////////////////////////////////////////////////////////////////////////
47 47
  // MATRIX EFFECTS.
......
96 96
   * Apply a 3D vector of force to area around a point on the surface of the Object.
97 97
   * <p>
98 98
   * Uniforms: (forceX ,forceY ,forceZ  ,UNUSED  ,
99
   *            UNUSED , UNUSED,centerX ,centerY ,
99
   *            UNUSED , centerX ,centerY , centerZ,
100 100
   *            regionX,regionY,regionRX,regionRY)
101 101
   * <p>
102 102
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
......
106 106
   * Deform the whole Object by applying a 2D vector of force to a center point.
107 107
   * <p>
108 108
   * Uniforms: (forceX,forceY,UNUSED,UNUSED,
109
   *            UNUSED,UNUSED,centerX,centerY,
109
   *            UNUSED,centerX,centerY,centerZ,
110 110
   *            UNUSED,UNUSED,UNUSED,UNUSED)
111 111
   * <p>
112 112
   * Unity: (forceX,forceY) = (0,0)
......
116 116
   * Pull (or push away) all points around a center point to (from) it.
117 117
   * <p>
118 118
   * Uniforms: (sinkFactor,UNUSED,UNUSED,UNUSED,
119
   *            UNUSED,UNUSED,centerX,centerY,
119
   *            UNUSED,centerX,centerY,centerZ,
120 120
   *            regionX,regionY,regionRX,regionRY)
121 121
   * <p>
122 122
   * Unity: sinkFactor = 1
123 123
   */
124 124
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           , 1, true, true ),
125
  /**
126
   * Pull (or push away) all points around a line to (from) it.
127
   * <p>
128
   * Uniforms: (pinchFactor,lineAngle,UNUSED,UNUSED,
129
   *            UNUSED,centerX,centerY,centerZ,
130
   *            regionX,regionY,regionRX,regionRY)
131
   * <p>
132
   * Unity: sinkFactor = 1
133
   */
134
  PINCH            ( EffectTypes.VERTEX  ,   new float[] {1.0f}           , 2, true, true ),
125 135
 /**
126 136
   * Smoothly rotate a limited area around a center point.
127 137
   * <p>
128 138
   * Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED,
129
   *            UNUSED, UNUSED,centerX,centerY,
139
   *            UNUSED, centerX,centerY,centerZ,
130 140
   *            regionX,regionY,regionRX,regionRY)
131 141
   * <p>
132 142
   * Unity: swirlAngle = 0
......
137 147
   * parameters. Details: {@link DistortedObject#wave(Data5D,Data2D)}
138 148
   * <p>
139 149
   * Uniforms: (amplitude,length,phase,angleAlpha,
140
   *            angleBeta, UNUSED,centerX,centerY,
150
   *            angleBeta, centerX,centerY,centerZ,
141 151
   *            regionX,regionY,regionRX,regionRY)
142 152
   * <p>
143 153
   * Unity: amplitude  = 0
src/main/java/org/distorted/library/EffectQueueVertex.java
23 23

  
24 24
import org.distorted.library.message.EffectMessage;
25 25
import org.distorted.library.type.Data1D;
26
import org.distorted.library.type.Data2D;
26 27
import org.distorted.library.type.Data3D;
27 28
import org.distorted.library.type.Data4D;
28 29
import org.distorted.library.type.Data5D;
29 30
import org.distorted.library.type.Dynamic1D;
31
import org.distorted.library.type.Dynamic2D;
30 32
import org.distorted.library.type.Dynamic3D;
31 33
import org.distorted.library.type.Dynamic4D;
32 34
import org.distorted.library.type.Dynamic5D;
33 35
import org.distorted.library.type.Static1D;
36
import org.distorted.library.type.Static2D;
34 37
import org.distorted.library.type.Static3D;
35 38
import org.distorted.library.type.Static4D;
36 39
import org.distorted.library.type.Static5D;
......
161 164
// Do various post-processing on already computed effects.
162 165
// 1) here unlike in the fragment queue, we don't have to multiply the points by ModelView matrix because that gets done in the shader.
163 166
// 2) in case of SWIRL, switch the angles from degrees to radians
164
// 3) likewise in case of WAVE
167
// 3) likewise in case of WAVE and PINCH
165 168
// 4) In case of DISTORT, invert the Y-axis
166 169
  
167 170
  private void postprocess(int effect)
......
170 173
      {
171 174
      mUniforms[NUM_UNIFORMS*effect  ] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect  ]/180);
172 175
      }
176
    if( mName[effect]==EffectNames.PINCH.ordinal() )
177
      {
178
      mUniforms[NUM_UNIFORMS*effect+1] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+1]/180);
179
      }
173 180
    if( mName[effect]==EffectNames.WAVE.ordinal() )
174 181
      {
175 182
      mUniforms[NUM_UNIFORMS*effect+2] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+2]/180);
......
292 299
    return -1;
293 300
    }
294 301

  
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303
// pinch
304

  
305
  synchronized long add(EffectNames eln, Data2D data, Data3D center, Data4D region)
306
    {
307
    if( mMax[INDEX]>mNumEffects )
308
      {
309
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
310

  
311
      if( data instanceof Dynamic2D)
312
        {
313
        mInter[0][mNumEffects] = (Dynamic2D)data;
314
        }
315
      else if( data instanceof Static2D)
316
        {
317
        mInter[0][mNumEffects] = null;
318
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static2D)data).getX();
319
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static2D)data).getY();
320
        }
321

  
322
      return addPriv(eln,center,region);
323
      }
324

  
325
    return -1;
326
    }
327

  
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
// pinch
330

  
331
  synchronized long add(EffectNames eln, Data2D data, Data3D center)
332
    {
333
    if( mMax[INDEX]>mNumEffects )
334
      {
335
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
336

  
337
      if( data instanceof Dynamic2D)
338
        {
339
        mInter[0][mNumEffects] = (Dynamic2D)data;
340
        }
341
      else if( data instanceof Static2D)
342
        {
343
        mInter[0][mNumEffects] = null;
344
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static2D)data).getX();
345
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static2D)data).getY();
346
        }
347

  
348
      return addPriv(eln,center,null);
349
      }
350

  
351
    return -1;
352
    }
353

  
295 354
///////////////////////////////////////////////////////////////////////////////////////////////////
296 355
  
297 356
  private long addPriv(EffectNames eln, Data3D center, Data4D region)
src/main/res/raw/main_vertex_shader.glsl
309 309
//////////////////////////////////////////////////////////////////////////////////////////////
310 310
// SINK EFFECT
311 311
//
312
// Pull P=(v.x,v.y) towards S=vPoint[effect] with P' = P + (1-h)d(S-P)
313
// when h>1 we are pushing points away from S: P' = P + (1/h-1)d(S-P)
312
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P)
313
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P)
314 314
 
315 315
void sink(in int effect,inout vec4 v)
316 316
  {
......
322 322
  v.xy += t*ps;           
323 323
  }
324 324

  
325
//////////////////////////////////////////////////////////////////////////////////////////////
326
// PINCH EFFECT
327
//
328
// Pull P=(v.x,v.y) towards the line that
329
// a) passes through the center of the effect
330
// b) forms angle defined in the 2nd interpolated value with the X-axis
331
// with P' = P + (1-h)*dist(line to P)
332
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P)
333

  
334
void pinch(in int effect,inout vec4 v)
335
  {
336
  vec2 center = vUniforms[effect+1].yz;
337
  vec2 ps = center-v.xy;
338
  float h = vUniforms[effect].x;
339
  float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h);
340
  float angle = vUniforms[effect].y;
341
  vec2 dir = vec2(sin(angle),-cos(angle));
342

  
343
  v.xy += t*dot(ps,dir)*dir;
344
  }
345

  
325 346
//////////////////////////////////////////////////////////////////////////////////////////////
326 347
// SWIRL EFFECT
327 348
//
......
492 513
         if( vType[i]==DISTORT) distort(3*i,v,n);
493 514
    else if( vType[i]==DEFORM ) deform (3*i,v);
494 515
    else if( vType[i]==SINK   ) sink   (3*i,v);
516
    else if( vType[i]==PINCH  ) pinch  (3*i,v);
495 517
    else if( vType[i]==SWIRL  ) swirl  (3*i,v);
496 518
    else if( vType[i]==WAVE   ) wave   (3*i,v,n);
497 519
    }

Also available in: Unified diff