Project

General

Profile

« Previous | Next » 

Revision 6ebdbbf1

Added by Leszek Koltunski over 7 years ago

DEFORM: add support for Regions

View differences:

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