Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 8fa96e69

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
import android.opengl.Matrix;
24

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

    
34
import java.nio.ByteBuffer;
35
import java.nio.ByteOrder;
36
import java.nio.FloatBuffer;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
/**
40
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
41
 * <p>
42
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
43
 */
44
public class DistortedEffects
45
  {
46
  private static final int POSITION_DATA_SIZE= 3; // Main Program: size of the position data in elements
47
  private static final int NORMAL_DATA_SIZE  = 3; // Main Program: size of the normal data in elements
48
  private static final int TEX_DATA_SIZE     = 2; // Main Program: size of the texture coordinate data in elements.
49

    
50
  private static DistortedProgram mProgram;
51

    
52
  private static float[] mMVPMatrix = new float[16];
53
  private static float[] mTmpMatrix = new float[16];
54

    
55
  private static long mNextID =0;
56
  private long mID;
57

    
58
  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1);
59

    
60
  private EffectQueueMatrix      mM;
61
  private EffectQueueFragment    mF;
62
  private EffectQueueVertex      mV;
63
  private EffectQueuePostprocess mP;
64

    
65
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  static void setProgram(DistortedProgram p)
70
    {
71
    mProgram = p;
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  private void initializeEffectLists(DistortedEffects d, int flags)
77
    {
78
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
79
      {
80
      mM = d.mM;
81
      matrixCloned = true;
82
      }
83
    else
84
      {
85
      mM = new EffectQueueMatrix(mID);
86
      matrixCloned = false;
87
      }
88
    
89
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
90
      {
91
      mV = d.mV;
92
      vertexCloned = true;
93
      }
94
    else
95
      {
96
      mV = new EffectQueueVertex(mID);
97
      vertexCloned = false;
98
      }
99
    
100
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
101
      {
102
      mF = d.mF;
103
      fragmentCloned = true;
104
      }
105
    else
106
      {
107
      mF = new EffectQueueFragment(mID);
108
      fragmentCloned = false;
109
      }
110

    
111
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
112
      {
113
      mP = d.mP;
114
      postprocessCloned = true;
115
      }
116
    else
117
      {
118
      mP = new EffectQueuePostprocess(mID);
119
      postprocessCloned = false;
120
      }
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
   
125
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
126
    {
127
    mM.compute(currTime);
128
    mV.compute(currTime);
129
    mF.compute(currTime);
130
    mP.compute(currTime);
131

    
132
    float halfZ = halfInputW*mesh.zFactor;
133
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
134

    
135
    if( mP.mNumEffects==0 )
136
      {
137
      mProgram.useProgram();
138
      df.setAsOutput();
139
      mM.send(df,halfInputW,halfInputH,halfZ);
140
      mV.send(halfInputW,halfInputH,halfZ);
141
      mF.send(halfInputW,halfInputH);
142
      GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
143
      GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
144
      GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
145
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
146
      }
147
    else
148
      {
149
      if( mV.mNumEffects>0 || mF.mNumEffects>0 )
150
        {
151
        mProgram.useProgram();
152
        mBufferFBO.resizeFast(df.mWidth, df.mHeight);
153
        mBufferFBO.setAsOutput();
154
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
155
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
156
        mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
157
        mV.send(halfInputW,halfInputH,halfZ);
158
        mF.send(halfInputW,halfInputH);
159
        GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
160
        GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
161
        GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
162
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
163

    
164
        Matrix.setIdentityM(mTmpMatrix, 0);
165
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
166
        Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
167

    
168
        mBufferFBO.setAsInput();
169
        mP.render(df.mWidth, df.mHeight, mMVPMatrix, df);
170
        }
171
      else
172
        {
173
        mM.constructMatrices(df,halfInputW,halfInputH);
174
        mP.render(2*halfInputW, 2*halfInputH, mM.getMVP(), df);
175
        }
176
      }
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
   
181
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
182
    {
183
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
184

    
185
    Matrix.setIdentityM(mTmpMatrix, 0);
186
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
187
    Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
188

    
189
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
190
    EffectQueueVertex.sendZero();
191
    EffectQueueFragment.sendZero();
192
    EffectQueuePostprocess.sendZero(df.mWidth, df.mHeight, mMVPMatrix);
193

    
194
    GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
195
    GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
196
    GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
197
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
198
    }
199
    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201
   
202
  private void releasePriv()
203
    {
204
    if( !matrixCloned     ) mM.abortAll(false);
205
    if( !vertexCloned     ) mV.abortAll(false);
206
    if( !fragmentCloned   ) mF.abortAll(false);
207
    if( !postprocessCloned) mP.abortAll(false);
208

    
209
    mM = null;
210
    mV = null;
211
    mF = null;
212
    mP = null;
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  static void onDestroy()
218
    {
219
    mNextID = 0;
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
// PUBLIC API
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225
/**
226
 * Create empty effect queue.
227
 */
228
  public DistortedEffects()
229
    {
230
    mID = mNextID++;
231
    initializeEffectLists(this,0);
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235
/**
236
 * Copy constructor.
237
 * <p>
238
 * Whatever we do not clone gets created just like in the default constructor.
239
 *
240
 * @param dc    Source object to create our object from
241
 * @param flags A bitmask of values specifying what to copy.
242
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
243
 */
244
  public DistortedEffects(DistortedEffects dc, int flags)
245
    {
246
    mID = mNextID++;
247
    initializeEffectLists(dc,flags);
248
    }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251
/**
252
 * Releases all resources. After this call, the queue should not be used anymore.
253
 */
254
  public synchronized void delete()
255
    {
256
    releasePriv();
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
/**
261
 * Returns unique ID of this instance.
262
 *
263
 * @return ID of the object.
264
 */
265
  public long getID()
266
      {
267
      return mID;
268
      }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271
/**
272
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
273
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
274
 * 
275
 * @param el A class implementing the EffectListener interface that wants to get notifications.
276
 */
277
  public void registerForMessages(EffectListener el)
278
    {
279
    mV.registerForMessages(el);
280
    mF.registerForMessages(el);
281
    mM.registerForMessages(el);
282
    mP.registerForMessages(el);
283
    }
284

    
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286
/**
287
 * Removes the calling class from the list of Listeners.
288
 * 
289
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
290
 */
291
  public void deregisterForMessages(EffectListener el)
292
    {
293
    mV.deregisterForMessages(el);
294
    mF.deregisterForMessages(el);
295
    mM.deregisterForMessages(el);
296
    mP.deregisterForMessages(el);
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
/**
301
 * Aborts all Effects.
302
 * @return Number of effects aborted.
303
 */
304
  public int abortAllEffects()
305
      {
306
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
307
      }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310
/**
311
 * Aborts all Effects of a given type, for example all MATRIX Effects.
312
 * 
313
 * @param type one of the constants defined in {@link EffectTypes}
314
 * @return Number of effects aborted.
315
 */
316
  public int abortEffects(EffectTypes type)
317
    {
318
    switch(type)
319
      {
320
      case MATRIX     : return mM.abortAll(true);
321
      case VERTEX     : return mV.abortAll(true);
322
      case FRAGMENT   : return mF.abortAll(true);
323
      case POSTPROCESS: return mP.abortAll(true);
324
      default         : return 0;
325
      }
326
    }
327
    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
/**
330
 * Aborts a single Effect.
331
 * 
332
 * @param id ID of the Effect we want to abort.
333
 * @return number of Effects aborted. Always either 0 or 1.
334
 */
335
  public int abortEffect(long id)
336
    {
337
    int type = (int)(id&EffectTypes.MASK);
338

    
339
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
340
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
341
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
342
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
343

    
344
    return 0;
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348
/**
349
 * Abort all Effects of a given name, for example all rotations.
350
 * 
351
 * @param name one of the constants defined in {@link EffectNames}
352
 * @return number of Effects aborted.
353
 */
354
  public int abortEffects(EffectNames name)
355
    {
356
    switch(name.getType())
357
      {
358
      case MATRIX     : return mM.removeByType(name);
359
      case VERTEX     : return mV.removeByType(name);
360
      case FRAGMENT   : return mF.removeByType(name);
361
      case POSTPROCESS: return mP.removeByType(name);
362
      default         : return 0;
363
      }
364
    }
365
    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367
/**
368
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
369
 * 
370
 * @param id Effect ID we want to print info about
371
 * @return <code>true</code> if a single Effect of type effectType has been found.
372
 */
373
    
374
  public boolean printEffect(long id)
375
    {
376
    int type = (int)(id&EffectTypes.MASK);
377

    
378
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
379
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
380
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
381
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
382

    
383
    return false;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387
/**
388
 * Returns the maximum number of Matrix effects.
389
 *
390
 * @return The maximum number of Matrix effects
391
 */
392
  public static int getMaxMatrix()
393
    {
394
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398
/**
399
 * Returns the maximum number of Vertex effects.
400
 *
401
 * @return The maximum number of Vertex effects
402
 */
403
  public static int getMaxVertex()
404
    {
405
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
406
    }
407

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409
/**
410
 * Returns the maximum number of Fragment effects.
411
 *
412
 * @return The maximum number of Fragment effects
413
 */
414
  public static int getMaxFragment()
415
    {
416
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
/**
421
 * Returns the maximum number of Postprocess effects.
422
 *
423
 * @return The maximum number of Postprocess effects
424
 */
425
  public static int getMaxPostprocess()
426
    {
427
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
428
    }
429

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

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

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473
/**
474
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
475
 * This can fail if:
476
 * <ul>
477
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
478
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
479
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
480
 *     time only decreasing the value of 'max' is permitted.
481
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
482
 * </ul>
483
 *
484
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
485
 *            than Byte.MAX_VALUE
486
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
487
 */
488
  public static boolean setMaxFragment(int max)
489
    {
490
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494
/**
495
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
496
 * This can fail if:
497
 * <ul>
498
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
499
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
500
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
501
 *     time only decreasing the value of 'max' is permitted.
502
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
503
 * </ul>
504
 *
505
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
506
 *            than Byte.MAX_VALUE
507
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
508
 */
509
  public static boolean setMaxPostprocess(int max)
510
    {
511
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
512
    }
513

    
514
///////////////////////////////////////////////////////////////////////////////////////////////////   
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516
// Individual effect functions.
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518
// Matrix-based effects
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520
/**
521
 * Moves the Object by a (possibly changing in time) vector.
522
 * 
523
 * @param vector 3-dimensional Data which at any given time will return a Static3D
524
 *               representing the current coordinates of the vector we want to move the Object with.
525
 * @return       ID of the effect added, or -1 if we failed to add one.
526
 */
527
  public long move(Data3D vector)
528
    {   
529
    return mM.add(EffectNames.MOVE,vector);
530
    }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
/**
534
 * Scales the Object by (possibly changing in time) 3D scale factors.
535
 * 
536
 * @param scale 3-dimensional Data which at any given time returns a Static3D
537
 *              representing the current x- , y- and z- scale factors.
538
 * @return      ID of the effect added, or -1 if we failed to add one.
539
 */
540
  public long scale(Data3D scale)
541
    {   
542
    return mM.add(EffectNames.SCALE,scale);
543
    }
544

    
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546
/**
547
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
548
 *
549
 * @param scale The factor to scale all 3 dimensions with.
550
 * @return      ID of the effect added, or -1 if we failed to add one.
551
 */
552
  public long scale(float scale)
553
    {
554
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
555
    }
556

    
557
///////////////////////////////////////////////////////////////////////////////////////////////////
558
/**
559
 * Rotates the Object by 'angle' degrees around the center.
560
 * Static axis of rotation is given by the last parameter.
561
 *
562
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
563
 * @param axis   Axis of rotation
564
 * @param center Coordinates of the Point we are rotating around.
565
 * @return       ID of the effect added, or -1 if we failed to add one.
566
 */
567
  public long rotate(Data1D angle, Static3D axis, Data3D center )
568
    {   
569
    return mM.add(EffectNames.ROTATE, angle, axis, center);
570
    }
571

    
572
///////////////////////////////////////////////////////////////////////////////////////////////////
573
/**
574
 * Rotates the Object by 'angle' degrees around the center.
575
 * Here both angle and axis can dynamically change.
576
 *
577
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
578
 * @param center    Coordinates of the Point we are rotating around.
579
 * @return          ID of the effect added, or -1 if we failed to add one.
580
 */
581
  public long rotate(Data4D angleaxis, Data3D center)
582
    {
583
    return mM.add(EffectNames.ROTATE, angleaxis, center);
584
    }
585

    
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587
/**
588
 * Rotates the Object by quaternion.
589
 *
590
 * @param quaternion The quaternion describing the rotation.
591
 * @param center     Coordinates of the Point we are rotating around.
592
 * @return           ID of the effect added, or -1 if we failed to add one.
593
 */
594
  public long quaternion(Data4D quaternion, Data3D center )
595
    {
596
    return mM.add(EffectNames.QUATERNION,quaternion,center);
597
    }
598

    
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600
/**
601
 * Shears the Object.
602
 *
603
 * @param shear   The 3-tuple of shear factors. The first controls level
604
 *                of shearing in the X-axis, second - Y-axis and the third -
605
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
606
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
607
 * @param center  Center of shearing, i.e. the point which stays unmoved.
608
 * @return        ID of the effect added, or -1 if we failed to add one.
609
 */
610
  public long shear(Data3D shear, Data3D center)
611
    {
612
    return mM.add(EffectNames.SHEAR, shear, center);
613
    }
614

    
615
///////////////////////////////////////////////////////////////////////////////////////////////////
616
// Fragment-based effects  
617
///////////////////////////////////////////////////////////////////////////////////////////////////
618
/**
619
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
620
 *        
621
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
622
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
623
 *               Valid range: <0,1>
624
 * @param color  Color to mix. (1,0,0) is RED.
625
 * @param region Region this Effect is limited to.
626
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
627
 * @return       ID of the effect added, or -1 if we failed to add one.
628
 */
629
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
630
    {
631
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
632
    }
633

    
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635
/**
636
 * Makes the whole Object smoothly change all three of its RGB components.
637
 *
638
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
639
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
640
 *               Valid range: <0,1>
641
 * @param color  Color to mix. (1,0,0) is RED.
642
 * @return       ID of the effect added, or -1 if we failed to add one.
643
 */
644
  public long chroma(Data1D blend, Data3D color)
645
    {
646
    return mF.add(EffectNames.CHROMA, blend, color);
647
    }
648

    
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650
/**
651
 * Makes a certain sub-region of the Object smoothly change its transparency level.
652
 *        
653
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
654
 *               moment: pixel.a *= alpha.
655
 *               Valid range: <0,1>
656
 * @param region Region this Effect is limited to. 
657
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
658
 * @return       ID of the effect added, or -1 if we failed to add one. 
659
 */
660
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
661
    {
662
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
663
    }
664

    
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666
/**
667
 * Makes the whole Object smoothly change its transparency level.
668
 *
669
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
670
 *               given moment: pixel.a *= alpha.
671
 *               Valid range: <0,1>
672
 * @return       ID of the effect added, or -1 if we failed to add one.
673
 */
674
  public long alpha(Data1D alpha)
675
    {
676
    return mF.add(EffectNames.ALPHA, alpha);
677
    }
678

    
679
///////////////////////////////////////////////////////////////////////////////////////////////////
680
/**
681
 * Makes a certain sub-region of the Object smoothly change its brightness level.
682
 *        
683
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
684
 *                   at any given moment. Valid range: <0,infinity)
685
 * @param region     Region this Effect is limited to.
686
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
687
 * @return           ID of the effect added, or -1 if we failed to add one.
688
 */
689
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
690
    {
691
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
692
    }
693

    
694
///////////////////////////////////////////////////////////////////////////////////////////////////
695
/**
696
 * Makes the whole Object smoothly change its brightness level.
697
 *
698
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
699
 *                   at any given moment. Valid range: <0,infinity)
700
 * @return           ID of the effect added, or -1 if we failed to add one.
701
 */
702
  public long brightness(Data1D brightness)
703
    {
704
    return mF.add(EffectNames.BRIGHTNESS, brightness);
705
    }
706

    
707
///////////////////////////////////////////////////////////////////////////////////////////////////
708
/**
709
 * Makes a certain sub-region of the Object smoothly change its contrast level.
710
 *        
711
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
712
 *                 at any given moment. Valid range: <0,infinity)
713
 * @param region   Region this Effect is limited to.
714
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
715
 * @return         ID of the effect added, or -1 if we failed to add one.
716
 */
717
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
718
    {
719
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
720
    }
721

    
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723
/**
724
 * Makes the whole Object smoothly change its contrast level.
725
 *
726
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
727
 *                 at any given moment. Valid range: <0,infinity)
728
 * @return         ID of the effect added, or -1 if we failed to add one.
729
 */
730
  public long contrast(Data1D contrast)
731
    {
732
    return mF.add(EffectNames.CONTRAST, contrast);
733
    }
734

    
735
///////////////////////////////////////////////////////////////////////////////////////////////////
736
/**
737
 * Makes a certain sub-region of the Object smoothly change its saturation level.
738
 *        
739
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
740
 *                   at any given moment. Valid range: <0,infinity)
741
 * @param region     Region this Effect is limited to.
742
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
743
 * @return           ID of the effect added, or -1 if we failed to add one.
744
 */
745
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
746
    {
747
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
748
    }
749

    
750
///////////////////////////////////////////////////////////////////////////////////////////////////
751
/**
752
 * Makes the whole Object smoothly change its saturation level.
753
 *
754
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
755
 *                   at any given moment. Valid range: <0,infinity)
756
 * @return           ID of the effect added, or -1 if we failed to add one.
757
 */
758
  public long saturation(Data1D saturation)
759
    {
760
    return mF.add(EffectNames.SATURATION, saturation);
761
    }
762

    
763
///////////////////////////////////////////////////////////////////////////////////////////////////
764
// Vertex-based effects  
765
///////////////////////////////////////////////////////////////////////////////////////////////////
766
/**
767
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
768
 *
769
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
770
 *               currently being dragged with.
771
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
772
 * @param region Region that masks the Effect.
773
 * @return       ID of the effect added, or -1 if we failed to add one.
774
 */
775
  public long distort(Data3D vector, Data3D center, Data4D region)
776
    {  
777
    return mV.add(EffectNames.DISTORT, vector, center, region);
778
    }
779

    
780
///////////////////////////////////////////////////////////////////////////////////////////////////
781
/**
782
 * Distort the whole Object by a (possibly changing in time) vector of force.
783
 *
784
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
785
 *               currently being dragged with.
786
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
787
 * @return       ID of the effect added, or -1 if we failed to add one.
788
 */
789
  public long distort(Data3D vector, Data3D center)
790
    {
791
    return mV.add(EffectNames.DISTORT, vector, center, null);
792
    }
793

    
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795
/**
796
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
797
 * a (possibly changing in time) point on the Object.
798
 *
799
 * @param vector Vector of force that deforms the shape of the whole Object.
800
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
801
 * @param region Region that masks the Effect.
802
 * @return       ID of the effect added, or -1 if we failed to add one.
803
 */
804
  public long deform(Data3D vector, Data3D center, Data4D region)
805
    {
806
    return mV.add(EffectNames.DEFORM, vector, center, region);
807
    }
808

    
809
///////////////////////////////////////////////////////////////////////////////////////////////////
810
/**
811
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
812
 * a (possibly changing in time) point on the Object.
813
 *     
814
 * @param vector Vector of force that deforms the shape of the whole Object.
815
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
816
 * @return       ID of the effect added, or -1 if we failed to add one.
817
 */
818
  public long deform(Data3D vector, Data3D center)
819
    {  
820
    return mV.add(EffectNames.DEFORM, vector, center, null);
821
    }
822

    
823
///////////////////////////////////////////////////////////////////////////////////////////////////  
824
/**
825
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
826
 * away from the center (degree<=1)
827
 *
828
 * @param sink   The current degree of the Effect.
829
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
830
 * @param region Region that masks the Effect.
831
 * @return       ID of the effect added, or -1 if we failed to add one.
832
 */
833
  public long sink(Data1D sink, Data3D center, Data4D region)
834
    {
835
    return mV.add(EffectNames.SINK, sink, center, region);
836
    }
837

    
838
///////////////////////////////////////////////////////////////////////////////////////////////////
839
/**
840
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
841
 * away from the center (degree<=1)
842
 *
843
 * @param sink   The current degree of the Effect.
844
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
845
 * @return       ID of the effect added, or -1 if we failed to add one.
846
 */
847
  public long sink(Data1D sink, Data3D center)
848
    {
849
    return mV.add(EffectNames.SINK, sink, center);
850
    }
851

    
852
///////////////////////////////////////////////////////////////////////////////////////////////////
853
/**
854
 * Pull all points around the center of the Effect towards a line passing through the center
855
 * (that's if degree>=1) or push them away from the line (degree<=1)
856
 *
857
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
858
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
859
 * @param region Region that masks the Effect.
860
 * @return       ID of the effect added, or -1 if we failed to add one.
861
 */
862
  public long pinch(Data2D pinch, Data3D center, Data4D region)
863
    {
864
    return mV.add(EffectNames.PINCH, pinch, center, region);
865
    }
866

    
867
///////////////////////////////////////////////////////////////////////////////////////////////////
868
/**
869
 * Pull all points around the center of the Effect towards a line passing through the center
870
 * (that's if degree>=1) or push them away from the line (degree<=1)
871
 *
872
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
873
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
874
 * @return       ID of the effect added, or -1 if we failed to add one.
875
 */
876
  public long pinch(Data2D pinch, Data3D center)
877
    {
878
    return mV.add(EffectNames.PINCH, pinch, center);
879
    }
880

    
881
///////////////////////////////////////////////////////////////////////////////////////////////////  
882
/**
883
 * Rotate part of the Object around the Center of the Effect by a certain angle.
884
 *
885
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
886
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
887
 * @param region Region that masks the Effect.
888
 * @return       ID of the effect added, or -1 if we failed to add one.
889
 */
890
  public long swirl(Data1D swirl, Data3D center, Data4D region)
891
    {    
892
    return mV.add(EffectNames.SWIRL, swirl, center, region);
893
    }
894

    
895
///////////////////////////////////////////////////////////////////////////////////////////////////
896
/**
897
 * Rotate the whole Object around the Center of the Effect by a certain angle.
898
 *
899
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
900
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
901
 * @return       ID of the effect added, or -1 if we failed to add one.
902
 */
903
  public long swirl(Data1D swirl, Data3D center)
904
    {
905
    return mV.add(EffectNames.SWIRL, swirl, center);
906
    }
907

    
908
///////////////////////////////////////////////////////////////////////////////////////////////////
909
/**
910
 * Directional, sinusoidal wave effect.
911
 *
912
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
913
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
914
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
915
 *               describe the 'direction' of the wave.
916
 *               <p>
917
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
918
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
919
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
920
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
921
 *               <p>
922
 *               <p>
923
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
924
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
925
 *               will be sine shapes.
926
 *               <p>
927
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
928
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
929
 *               YZ-plane with be sine shapes.
930
 *               <p>
931
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
932
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
933
 *               value if sin at this point.
934
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
935
 * @return       ID of the effect added, or -1 if we failed to add one.
936
 */
937
  public long wave(Data5D wave, Data3D center)
938
    {
939
    return mV.add(EffectNames.WAVE, wave, center, null);
940
    }
941

    
942
///////////////////////////////////////////////////////////////////////////////////////////////////
943
/**
944
 * Directional, sinusoidal wave effect.
945
 *
946
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
947
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
948
 * @param region Region that masks the Effect.
949
 * @return       ID of the effect added, or -1 if we failed to add one.
950
 */
951
  public long wave(Data5D wave, Data3D center, Data4D region)
952
    {
953
    return mV.add(EffectNames.WAVE, wave, center, region);
954
    }
955

    
956
///////////////////////////////////////////////////////////////////////////////////////////////////
957
// Postprocess-based effects
958
///////////////////////////////////////////////////////////////////////////////////////////////////
959
/**
960
 * Blur the object.
961
 *
962
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
963
 *               take into account 10 pixels in each direction.
964
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
965
 * @return ID of the effect added, or -1 if we failed to add one.
966
 */
967
  public long blur(Data1D radius, Data2D center)
968
    {
969
    return mP.add(EffectNames.BLUR, radius, center);
970
    }
971
  }
(2-2/16)