Project

General

Profile

« Previous | Next » 

Revision 6ebdbbf1

Added by Leszek Koltunski over 7 years ago

DEFORM: add support for Regions

View differences:

src/main/java/org/distorted/library/DistortedObject.java
746 746
    return mV.add(EffectNames.DISTORT, vector, center, null);
747 747
    }
748 748

  
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750
/**
751
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
752
 * a (possibly changing in time) point on the Object.
753
 *
754
 * @param vector Vector of force that deforms the shape of the whole Object.
755
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
756
 * @param region Region that masks the Effect.
757
 * @return       ID of the effect added, or -1 if we failed to add one.
758
 */
759
  public long deform(Data3D vector, Data3D center, Data4D region)
760
    {
761
    return mV.add(EffectNames.DEFORM, vector, center, region);
762
    }
763

  
749 764
///////////////////////////////////////////////////////////////////////////////////////////////////
750 765
/**
751 766
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
src/main/java/org/distorted/library/EffectNames.java
111 111
   * <p>
112 112
   * Unity: (forceX,forceY) = (0,0)
113 113
   */
114
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      , 3, false, true ),
114
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      , 3, true, true ),
115 115
 /**
116 116
   * Pull (or push away) all points around a center point to (from) it.
117 117
   * <p>
src/main/res/raw/main_vertex_shader.glsl
202 202
//
203 203
// Constants:
204 204
// a) A : valid values: (0,infinity). 'Bendiness' if the surface - the higher A is, the more the surface
205
//        bends. A<=0 destroys the system,
205
//        bends. A<=0 destroys the system.
206 206
// b) B : valid values: <-1,1>. The amount side edges get 'sucked' inwards when we pull the middle of the
207 207
//        top edge up. B=0 --> not at all, B=1: a looot. B=-0.5: the edges will actually be pushed outwards
208 208
//        quite a bit. One can also set it to <-1 or >1, but it will look a bit ridiculous.
......
214 214

  
215 215
void deform(in int effect, inout vec4 v)
216 216
  {
217
  const vec2 one = vec2(1.0,1.0);
217
  const vec2 ONE = vec2(1.0,1.0);
218 218

  
219 219
  const float A = 0.5;
220 220
  const float B = 0.2;
221 221
  const float C = 5.0;
222 222

  
223 223
  vec2 center = vUniforms[effect+1].yz;
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);
224
  vec2 ps     = center-v.xy;
225
  vec2 aPS    = abs(ps);
226
  vec2 maxps  = u_objD.xy + abs(center);
227
  vec2 force  = vUniforms[effect].xy * degree_region(vUniforms[effect+2],ps);
228 228
  vec2 aForce = abs(force);
229 229

  
230
  vec2 Aw = A*maxdist;
231
  vec2 quot = dist / maxdist;
230
  vec2 Aw = A*maxps;
231
  vec2 quot = ps / maxps;
232 232
  quot = quot*quot;                          // ( (x/W)^2 , (y/H)^2 ) where x,y are distances from V to center
233 233

  
234 234
  float denomV = 1.0 / (aForce.y + Aw.x);
235 235
  float denomH = 1.0 / (aForce.x + Aw.y);
236 236

  
237
  vec2 vertCorr= one - aDist / ( aForce+C*aDist + (one-sign(aForce)) );
237
  vec2 vertCorr= ONE - aPS / ( aForce+C*aPS + (ONE-sign(aForce)) );
238 238

  
239
  float mvXvert = -B * dist.x * aForce.y * (1.0-quot.y) * denomV;    // impact the vertical   component of the force vector has on horizontal movement
240
  float mvYhorz = -B * dist.y * aForce.x * (1.0-quot.x) * denomH;    // impact the horizontal component of the force vector has on vertical   movement
239
  float mvXvert = -B * ps.x * aForce.y * (1.0-quot.y) * denomV;      // impact the vertical   component of the force vector has on horizontal movement
240
  float mvYhorz = -B * ps.y * aForce.x * (1.0-quot.x) * denomH;      // impact the horizontal component of the force vector has on vertical   movement
241 241
  float mvYvert =  force.y * (1.0-quot.x*Aw.x*denomV) * vertCorr.y;  // impact the vertical   component of the force vector has on vertical   movement
242 242
  float mvXhorz = -force.x * (1.0-quot.y*Aw.y*denomH) * vertCorr.x;  // impact the horizontal component of the force vector has on horizontal movement
243 243

  

Also available in: Unified diff