Project

General

Profile

Download (37.3 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / DistortedEffects.java @ d6e94c84

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library;
21

    
22
import android.opengl.GLES20;
23

    
24
import org.distorted.library.message.EffectListener;
25
import org.distorted.library.type.Data1D;
26
import org.distorted.library.type.Data2D;
27
import org.distorted.library.type.Data3D;
28
import org.distorted.library.type.Data4D;
29
import org.distorted.library.type.Data5D;
30
import org.distorted.library.type.Static3D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
/**
34
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
35
 * <p>
36
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
37
 */
38
public class DistortedEffects
39
  {
40
  private static long mNextID =0;
41
  private long mID;
42

    
43
  private EffectQueueMatrix      mM;
44
  private EffectQueueFragment    mF;
45
  private EffectQueueVertex      mV;
46
  private EffectQueuePostprocess mP;
47

    
48
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
    
52
  private void initializeEffectLists(DistortedEffects d, int flags)
53
    {
54
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
55
      {
56
      mM = d.mM;
57
      matrixCloned = true;
58
      }
59
    else
60
      {
61
      mM = new EffectQueueMatrix(mID);
62
      matrixCloned = false;
63
      }
64
    
65
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
66
      {
67
      mV = d.mV;
68
      vertexCloned = true;
69
      }
70
    else
71
      {
72
      mV = new EffectQueueVertex(mID);
73
      vertexCloned = false;
74
      }
75
    
76
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
77
      {
78
      mF = d.mF;
79
      fragmentCloned = true;
80
      }
81
    else
82
      {
83
      mF = new EffectQueueFragment(mID);
84
      fragmentCloned = false;
85
      }
86

    
87
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
88
      {
89
      mP = d.mP;
90
      postprocessCloned = true;
91
      }
92
    else
93
      {
94
      mP = new EffectQueuePostprocess(mID);
95
      postprocessCloned = false;
96
      }
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
   
101
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
102
    {
103
    mM.compute(currTime);
104
    mV.compute(currTime);
105
    mF.compute(currTime);
106
    mP.compute(currTime);
107

    
108
    float halfZ = halfInputW*mesh.zFactor;
109

    
110
    GLES20.glUseProgram(Distorted.mainProgramH);
111

    
112
    if( mP.mNumEffects==0 )
113
      {
114
      GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
115

    
116
      mM.send(df,halfInputW,halfInputH,halfZ);
117
      mV.send(halfInputW,halfInputH,halfZ);
118
      mF.send(halfInputW,halfInputH);
119

    
120
      mesh.draw();
121
      }
122
    else
123
      {
124
      DistortedFramebuffer fbo = null;
125
      // TODO : set this as output
126

    
127
      // render to the FBO just like above
128
      /*
129
      GLES20.glViewport(0, 0, fbo.mWidth, fbo.mHeight);
130

    
131
      mM.send(fbo,halfInputW,halfInputH,halfZ);
132
      mV.send(halfInputW,halfInputH,halfZ);
133
      mF.send(halfInputW,halfInputH);
134

    
135
      mesh.draw();
136
      */
137

    
138
      GLES20.glUseProgram(Distorted.postProgramH);
139

    
140
      // apply postprocess effects
141
      mP.postprocess(fbo,df);
142
      }
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
   
147
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
148
    {
149
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
150

    
151
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
152
    EffectQueueVertex.sendZero();
153
    EffectQueueFragment.sendZero();
154
    EffectQueuePostprocess.sendZero(2*halfInputW,2*halfInputH);
155

    
156
    mesh.draw();
157
    }
158
    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
   
161
  private void releasePriv()
162
    {
163
    if( !matrixCloned     ) mM.abortAll(false);
164
    if( !vertexCloned     ) mV.abortAll(false);
165
    if( !fragmentCloned   ) mF.abortAll(false);
166
    if( !postprocessCloned) mP.abortAll(false);
167

    
168
    mM = null;
169
    mV = null;
170
    mF = null;
171
    mP = null;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  static void onDestroy()
177
    {
178
    mNextID = 0;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
// PUBLIC API
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184
/**
185
 * Create empty effect queue.
186
 */
187
  public DistortedEffects()
188
    {
189
    mID = mNextID++;
190
    initializeEffectLists(this,0);
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
/**
195
 * Copy constructor.
196
 * <p>
197
 * Whatever we do not clone gets created just like in the default constructor.
198
 *
199
 * @param dc    Source object to create our object from
200
 * @param flags A bitmask of values specifying what to copy.
201
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
202
 */
203
  public DistortedEffects(DistortedEffects dc, int flags)
204
    {
205
    mID = mNextID++;
206
    initializeEffectLists(dc,flags);
207
    }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210
/**
211
 * Releases all resources. After this call, the queue should not be used anymore.
212
 */
213
  public synchronized void delete()
214
    {
215
    releasePriv();
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
/**
220
 * Returns unique ID of this instance.
221
 *
222
 * @return ID of the object.
223
 */
224
  public long getID()
225
      {
226
      return mID;
227
      }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
/**
231
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
232
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
233
 * 
234
 * @param el A class implementing the EffectListener interface that wants to get notifications.
235
 */
236
  public void registerForMessages(EffectListener el)
237
    {
238
    mV.registerForMessages(el);
239
    mF.registerForMessages(el);
240
    mM.registerForMessages(el);
241
    mP.registerForMessages(el);
242
    }
243

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245
/**
246
 * Removes the calling class from the list of Listeners.
247
 * 
248
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
249
 */
250
  public void deregisterForMessages(EffectListener el)
251
    {
252
    mV.deregisterForMessages(el);
253
    mF.deregisterForMessages(el);
254
    mM.deregisterForMessages(el);
255
    mP.deregisterForMessages(el);
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259
/**
260
 * Aborts all Effects.
261
 * @return Number of effects aborted.
262
 */
263
  public int abortAllEffects()
264
      {
265
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
266
      }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269
/**
270
 * Aborts all Effects of a given type, for example all MATRIX Effects.
271
 * 
272
 * @param type one of the constants defined in {@link EffectTypes}
273
 * @return Number of effects aborted.
274
 */
275
  public int abortEffects(EffectTypes type)
276
    {
277
    switch(type)
278
      {
279
      case MATRIX     : return mM.abortAll(true);
280
      case VERTEX     : return mV.abortAll(true);
281
      case FRAGMENT   : return mF.abortAll(true);
282
      case POSTPROCESS: return mP.abortAll(true);
283
      default         : return 0;
284
      }
285
    }
286
    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288
/**
289
 * Aborts a single Effect.
290
 * 
291
 * @param id ID of the Effect we want to abort.
292
 * @return number of Effects aborted. Always either 0 or 1.
293
 */
294
  public int abortEffect(long id)
295
    {
296
    int type = (int)(id&EffectTypes.MASK);
297

    
298
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
299
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
300
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
301
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
302

    
303
    return 0;
304
    }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307
/**
308
 * Abort all Effects of a given name, for example all rotations.
309
 * 
310
 * @param name one of the constants defined in {@link EffectNames}
311
 * @return number of Effects aborted.
312
 */
313
  public int abortEffects(EffectNames name)
314
    {
315
    switch(name.getType())
316
      {
317
      case MATRIX     : return mM.removeByType(name);
318
      case VERTEX     : return mV.removeByType(name);
319
      case FRAGMENT   : return mF.removeByType(name);
320
      case POSTPROCESS: return mP.removeByType(name);
321
      default         : return 0;
322
      }
323
    }
324
    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326
/**
327
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
328
 * 
329
 * @param id Effect ID we want to print info about
330
 * @return <code>true</code> if a single Effect of type effectType has been found.
331
 */
332
    
333
  public boolean printEffect(long id)
334
    {
335
    int type = (int)(id&EffectTypes.MASK);
336

    
337
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
338
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
339
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
340
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
341

    
342
    return false;
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
/**
347
 * Returns the maximum number of Matrix effects.
348
 *
349
 * @return The maximum number of Matrix effects
350
 */
351
  public static int getMaxMatrix()
352
    {
353
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357
/**
358
 * Returns the maximum number of Vertex effects.
359
 *
360
 * @return The maximum number of Vertex effects
361
 */
362
  public static int getMaxVertex()
363
    {
364
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
/**
369
 * Returns the maximum number of Fragment effects.
370
 *
371
 * @return The maximum number of Fragment effects
372
 */
373
  public static int getMaxFragment()
374
    {
375
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379
/**
380
 * Returns the maximum number of Postprocess effects.
381
 *
382
 * @return The maximum number of Postprocess effects
383
 */
384
  public static int getMaxPostprocess()
385
    {
386
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
387
    }
388

    
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390
/**
391
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
392
 * This can fail if:
393
 * <ul>
394
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
395
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
396
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
397
 *     time only decreasing the value of 'max' is permitted.
398
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
399
 * </ul>
400
 *
401
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
402
 *            than Byte.MAX_VALUE
403
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
404
 */
405
  public static boolean setMaxMatrix(int max)
406
    {
407
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
408
    }
409

    
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411
/**
412
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
413
 * This can fail if:
414
 * <ul>
415
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
416
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
417
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
418
 *     time only decreasing the value of 'max' is permitted.
419
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
420
 * </ul>
421
 *
422
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
423
 *            than Byte.MAX_VALUE
424
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
425
 */
426
  public static boolean setMaxVertex(int max)
427
    {
428
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
429
    }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432
/**
433
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
434
 * This can fail if:
435
 * <ul>
436
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
437
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
438
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
439
 *     time only decreasing the value of 'max' is permitted.
440
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
441
 * </ul>
442
 *
443
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
444
 *            than Byte.MAX_VALUE
445
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
446
 */
447
  public static boolean setMaxFragment(int max)
448
    {
449
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
450
    }
451

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
/**
454
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
455
 * This can fail if:
456
 * <ul>
457
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
458
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
459
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
460
 *     time only decreasing the value of 'max' is permitted.
461
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
462
 * </ul>
463
 *
464
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
465
 *            than Byte.MAX_VALUE
466
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
467
 */
468
  public static boolean setMaxPostprocess(int max)
469
    {
470
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////   
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475
// Individual effect functions.
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477
// Matrix-based effects
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479
/**
480
 * Moves the Object by a (possibly changing in time) vector.
481
 * 
482
 * @param vector 3-dimensional Data which at any given time will return a Static3D
483
 *               representing the current coordinates of the vector we want to move the Object with.
484
 * @return       ID of the effect added, or -1 if we failed to add one.
485
 */
486
  public long move(Data3D vector)
487
    {   
488
    return mM.add(EffectNames.MOVE,vector);
489
    }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492
/**
493
 * Scales the Object by (possibly changing in time) 3D scale factors.
494
 * 
495
 * @param scale 3-dimensional Data which at any given time returns a Static3D
496
 *              representing the current x- , y- and z- scale factors.
497
 * @return      ID of the effect added, or -1 if we failed to add one.
498
 */
499
  public long scale(Data3D scale)
500
    {   
501
    return mM.add(EffectNames.SCALE,scale);
502
    }
503

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505
/**
506
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
507
 *
508
 * @param scale The factor to scale all 3 dimensions with.
509
 * @return      ID of the effect added, or -1 if we failed to add one.
510
 */
511
  public long scale(float scale)
512
    {
513
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
514
    }
515

    
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
/**
518
 * Rotates the Object by 'angle' degrees around the center.
519
 * Static axis of rotation is given by the last parameter.
520
 *
521
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
522
 * @param axis   Axis of rotation
523
 * @param center Coordinates of the Point we are rotating around.
524
 * @return       ID of the effect added, or -1 if we failed to add one.
525
 */
526
  public long rotate(Data1D angle, Static3D axis, Data3D center )
527
    {   
528
    return mM.add(EffectNames.ROTATE, angle, axis, center);
529
    }
530

    
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532
/**
533
 * Rotates the Object by 'angle' degrees around the center.
534
 * Here both angle and axis can dynamically change.
535
 *
536
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
537
 * @param center    Coordinates of the Point we are rotating around.
538
 * @return          ID of the effect added, or -1 if we failed to add one.
539
 */
540
  public long rotate(Data4D angleaxis, Data3D center)
541
    {
542
    return mM.add(EffectNames.ROTATE, angleaxis, center);
543
    }
544

    
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546
/**
547
 * Rotates the Object by quaternion.
548
 *
549
 * @param quaternion The quaternion describing the rotation.
550
 * @param center     Coordinates of the Point we are rotating around.
551
 * @return           ID of the effect added, or -1 if we failed to add one.
552
 */
553
  public long quaternion(Data4D quaternion, Data3D center )
554
    {
555
    return mM.add(EffectNames.QUATERNION,quaternion,center);
556
    }
557

    
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559
/**
560
 * Shears the Object.
561
 *
562
 * @param shear   The 3-tuple of shear factors. The first controls level
563
 *                of shearing in the X-axis, second - Y-axis and the third -
564
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
565
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
566
 * @param center  Center of shearing, i.e. the point which stays unmoved.
567
 * @return        ID of the effect added, or -1 if we failed to add one.
568
 */
569
  public long shear(Data3D shear, Data3D center)
570
    {
571
    return mM.add(EffectNames.SHEAR, shear, center);
572
    }
573

    
574
///////////////////////////////////////////////////////////////////////////////////////////////////
575
// Fragment-based effects  
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577
/**
578
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
579
 *        
580
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
581
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
582
 *               Valid range: <0,1>
583
 * @param color  Color to mix. (1,0,0) is RED.
584
 * @param region Region this Effect is limited to.
585
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
586
 * @return       ID of the effect added, or -1 if we failed to add one.
587
 */
588
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
589
    {
590
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
591
    }
592

    
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594
/**
595
 * Makes the whole Object smoothly change all three of its RGB components.
596
 *
597
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
598
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
599
 *               Valid range: <0,1>
600
 * @param color  Color to mix. (1,0,0) is RED.
601
 * @return       ID of the effect added, or -1 if we failed to add one.
602
 */
603
  public long chroma(Data1D blend, Data3D color)
604
    {
605
    return mF.add(EffectNames.CHROMA, blend, color);
606
    }
607

    
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609
/**
610
 * Makes a certain sub-region of the Object smoothly change its transparency level.
611
 *        
612
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
613
 *               moment: pixel.a *= alpha.
614
 *               Valid range: <0,1>
615
 * @param region Region this Effect is limited to. 
616
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
617
 * @return       ID of the effect added, or -1 if we failed to add one. 
618
 */
619
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
620
    {
621
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
622
    }
623

    
624
///////////////////////////////////////////////////////////////////////////////////////////////////
625
/**
626
 * Makes the whole Object smoothly change its transparency level.
627
 *
628
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
629
 *               given moment: pixel.a *= alpha.
630
 *               Valid range: <0,1>
631
 * @return       ID of the effect added, or -1 if we failed to add one.
632
 */
633
  public long alpha(Data1D alpha)
634
    {
635
    return mF.add(EffectNames.ALPHA, alpha);
636
    }
637

    
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639
/**
640
 * Makes a certain sub-region of the Object smoothly change its brightness level.
641
 *        
642
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
643
 *                   at any given moment. Valid range: <0,infinity)
644
 * @param region     Region this Effect is limited to.
645
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
646
 * @return           ID of the effect added, or -1 if we failed to add one.
647
 */
648
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
649
    {
650
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
651
    }
652

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654
/**
655
 * Makes the whole Object smoothly change its brightness level.
656
 *
657
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
658
 *                   at any given moment. Valid range: <0,infinity)
659
 * @return           ID of the effect added, or -1 if we failed to add one.
660
 */
661
  public long brightness(Data1D brightness)
662
    {
663
    return mF.add(EffectNames.BRIGHTNESS, brightness);
664
    }
665

    
666
///////////////////////////////////////////////////////////////////////////////////////////////////
667
/**
668
 * Makes a certain sub-region of the Object smoothly change its contrast level.
669
 *        
670
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
671
 *                 at any given moment. Valid range: <0,infinity)
672
 * @param region   Region this Effect is limited to.
673
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
674
 * @return         ID of the effect added, or -1 if we failed to add one.
675
 */
676
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
677
    {
678
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
679
    }
680

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682
/**
683
 * Makes the whole Object smoothly change its contrast level.
684
 *
685
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
686
 *                 at any given moment. Valid range: <0,infinity)
687
 * @return         ID of the effect added, or -1 if we failed to add one.
688
 */
689
  public long contrast(Data1D contrast)
690
    {
691
    return mF.add(EffectNames.CONTRAST, contrast);
692
    }
693

    
694
///////////////////////////////////////////////////////////////////////////////////////////////////
695
/**
696
 * Makes a certain sub-region of the Object smoothly change its saturation level.
697
 *        
698
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
699
 *                   at any given moment. Valid range: <0,infinity)
700
 * @param region     Region this Effect is limited to.
701
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
702
 * @return           ID of the effect added, or -1 if we failed to add one.
703
 */
704
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
705
    {
706
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
707
    }
708

    
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710
/**
711
 * Makes the whole Object smoothly change its saturation level.
712
 *
713
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
714
 *                   at any given moment. Valid range: <0,infinity)
715
 * @return           ID of the effect added, or -1 if we failed to add one.
716
 */
717
  public long saturation(Data1D saturation)
718
    {
719
    return mF.add(EffectNames.SATURATION, saturation);
720
    }
721

    
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723
// Vertex-based effects  
724
///////////////////////////////////////////////////////////////////////////////////////////////////
725
/**
726
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
727
 *
728
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
729
 *               currently being dragged with.
730
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
731
 * @param region Region that masks the Effect.
732
 * @return       ID of the effect added, or -1 if we failed to add one.
733
 */
734
  public long distort(Data3D vector, Data3D center, Data4D region)
735
    {  
736
    return mV.add(EffectNames.DISTORT, vector, center, region);
737
    }
738

    
739
///////////////////////////////////////////////////////////////////////////////////////////////////
740
/**
741
 * Distort the whole Object by a (possibly changing in time) vector of force.
742
 *
743
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
744
 *               currently being dragged with.
745
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
746
 * @return       ID of the effect added, or -1 if we failed to add one.
747
 */
748
  public long distort(Data3D vector, Data3D center)
749
    {
750
    return mV.add(EffectNames.DISTORT, vector, center, null);
751
    }
752

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

    
768
///////////////////////////////////////////////////////////////////////////////////////////////////
769
/**
770
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
771
 * a (possibly changing in time) point on the Object.
772
 *     
773
 * @param vector Vector of force that deforms the shape of the whole Object.
774
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
775
 * @return       ID of the effect added, or -1 if we failed to add one.
776
 */
777
  public long deform(Data3D vector, Data3D center)
778
    {  
779
    return mV.add(EffectNames.DEFORM, vector, center, null);
780
    }
781

    
782
///////////////////////////////////////////////////////////////////////////////////////////////////  
783
/**
784
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
785
 * away from the center (degree<=1)
786
 *
787
 * @param sink   The current degree of the Effect.
788
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
789
 * @param region Region that masks the Effect.
790
 * @return       ID of the effect added, or -1 if we failed to add one.
791
 */
792
  public long sink(Data1D sink, Data3D center, Data4D region)
793
    {
794
    return mV.add(EffectNames.SINK, sink, center, region);
795
    }
796

    
797
///////////////////////////////////////////////////////////////////////////////////////////////////
798
/**
799
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
800
 * away from the center (degree<=1)
801
 *
802
 * @param sink   The current degree of the Effect.
803
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
804
 * @return       ID of the effect added, or -1 if we failed to add one.
805
 */
806
  public long sink(Data1D sink, Data3D center)
807
    {
808
    return mV.add(EffectNames.SINK, sink, center);
809
    }
810

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

    
826
///////////////////////////////////////////////////////////////////////////////////////////////////
827
/**
828
 * Pull all points around the center of the Effect towards a line passing through the center
829
 * (that's if degree>=1) or push them away from the line (degree<=1)
830
 *
831
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
832
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
833
 * @return       ID of the effect added, or -1 if we failed to add one.
834
 */
835
  public long pinch(Data2D pinch, Data3D center)
836
    {
837
    return mV.add(EffectNames.PINCH, pinch, center);
838
    }
839

    
840
///////////////////////////////////////////////////////////////////////////////////////////////////  
841
/**
842
 * Rotate part of the Object around the Center of the Effect by a certain angle.
843
 *
844
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
845
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
846
 * @param region Region that masks the Effect.
847
 * @return       ID of the effect added, or -1 if we failed to add one.
848
 */
849
  public long swirl(Data1D swirl, Data3D center, Data4D region)
850
    {    
851
    return mV.add(EffectNames.SWIRL, swirl, center, region);
852
    }
853

    
854
///////////////////////////////////////////////////////////////////////////////////////////////////
855
/**
856
 * Rotate the whole Object around the Center of the Effect by a certain angle.
857
 *
858
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
859
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
860
 * @return       ID of the effect added, or -1 if we failed to add one.
861
 */
862
  public long swirl(Data1D swirl, Data3D center)
863
    {
864
    return mV.add(EffectNames.SWIRL, swirl, center);
865
    }
866

    
867
///////////////////////////////////////////////////////////////////////////////////////////////////
868
/**
869
 * Directional, sinusoidal wave effect.
870
 *
871
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
872
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
873
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
874
 *               describe the 'direction' of the wave.
875
 *               <p>
876
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
877
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
878
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
879
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
880
 *               <p>
881
 *               <p>
882
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
883
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
884
 *               will be sine shapes.
885
 *               <p>
886
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
887
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
888
 *               YZ-plane with be sine shapes.
889
 *               <p>
890
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
891
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
892
 *               value if sin at this point.
893
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
894
 * @return       ID of the effect added, or -1 if we failed to add one.
895
 */
896
  public long wave(Data5D wave, Data3D center)
897
    {
898
    return mV.add(EffectNames.WAVE, wave, center, null);
899
    }
900

    
901
///////////////////////////////////////////////////////////////////////////////////////////////////
902
/**
903
 * Directional, sinusoidal wave effect.
904
 *
905
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
906
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
907
 * @param region Region that masks the Effect.
908
 * @return       ID of the effect added, or -1 if we failed to add one.
909
 */
910
  public long wave(Data5D wave, Data3D center, Data4D region)
911
    {
912
    return mV.add(EffectNames.WAVE, wave, center, region);
913
    }
914

    
915
///////////////////////////////////////////////////////////////////////////////////////////////////
916
// Postprocess-based effects
917
///////////////////////////////////////////////////////////////////////////////////////////////////
918
/**
919
 * Blur the object.
920
 *
921
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
922
 *               take into account 10 pixels in each direction.
923
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
924
 * @return ID of the effect added, or -1 if we failed to add one.
925
 */
926
  public long blur(Data1D radius, Data2D center)
927
    {
928
    return mP.add(EffectNames.BLUR, radius, center);
929
    }
930
  }
(2-2/16)