Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 50642a86

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.content.res.Resources;
23
import android.opengl.GLES30;
24
import android.opengl.Matrix;
25

    
26
import org.distorted.library.message.EffectListener;
27
import org.distorted.library.program.DistortedProgram;
28
import org.distorted.library.program.FragmentCompilationException;
29
import org.distorted.library.program.FragmentUniformsException;
30
import org.distorted.library.program.LinkingException;
31
import org.distorted.library.program.VertexCompilationException;
32
import org.distorted.library.program.VertexUniformsException;
33
import org.distorted.library.type.Data1D;
34
import org.distorted.library.type.Data2D;
35
import org.distorted.library.type.Data3D;
36
import org.distorted.library.type.Data4D;
37
import org.distorted.library.type.Data5D;
38
import org.distorted.library.type.Static3D;
39

    
40
import java.io.InputStream;
41
import java.nio.ByteBuffer;
42
import java.nio.ByteOrder;
43
import java.nio.FloatBuffer;
44

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

    
57
  /// MAIN PROGRAM ///
58
  private static DistortedProgram mMainProgram;
59
  private static int mMainTextureH;
60
  private static boolean[] mEffectEnabled = new boolean[EffectNames.size()];
61

    
62
  static
63
    {
64
    int len = EffectNames.size();
65

    
66
    for(int i=0; i<len; i++)
67
      {
68
      mEffectEnabled[i] = false;
69
      }
70
    }
71

    
72
  /// BLIT PROGRAM ///
73
  private static DistortedProgram mBlitProgram;
74
  private static int mBlitTextureH;
75
  private static int mBlitDepthH;
76
  private static final FloatBuffer mQuadPositions;
77

    
78
  static
79
    {
80
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
81
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
82
    mQuadPositions.put(positionData).position(0);
83
    }
84

    
85
  /// DEBUG ONLY /////
86
  private static DistortedProgram mDebugProgram;
87

    
88
  private static int mDebugObjDH;
89
  private static int mDebugMVPMatrixH;
90
  /// END DEBUG //////
91

    
92
  private static float[] mMVPMatrix = new float[16];
93
  private static float[] mTmpMatrix = new float[16];
94

    
95
  private static long mNextID =0;
96
  private long mID;
97

    
98
  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(true,DistortedSurface.TYPE_SYST,1,1);
99

    
100
  private EffectQueueMatrix      mM;
101
  private EffectQueueFragment    mF;
102
  private EffectQueueVertex      mV;
103
  private EffectQueuePostprocess mP;
104

    
105
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  static void createProgram(Resources resources)
110
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
111
    {
112
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
113
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
114

    
115
    String mainVertHeader= ("#version 100\n");
116
    String mainFragHeader= ("#version 100\n");
117

    
118
    EffectNames name;
119
    EffectTypes type;
120
    boolean foundF = false;
121
    boolean foundV = false;
122

    
123
    for(int i=0; i<mEffectEnabled.length; i++)
124
      {
125
      if( mEffectEnabled[i] )
126
        {
127
        name = EffectNames.getName(i);
128
        type = EffectNames.getType(i);
129

    
130
        if( type == EffectTypes.VERTEX )
131
          {
132
          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
133
          foundV = true;
134
          }
135
        else if( type == EffectTypes.FRAGMENT )
136
          {
137
          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
138
          foundF = true;
139
          }
140
        }
141
      }
142

    
143
    mainVertHeader += ("#define NUM_VERTEX "   + ( foundV ? getMaxVertex()   : 0 ) + "\n");
144
    mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
145

    
146
    //android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
147
    //android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
148

    
149
    mMainProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader);
150

    
151
    int mainProgramH = mMainProgram.getProgramHandle();
152
    EffectQueueFragment.getUniforms(mainProgramH);
153
    EffectQueueVertex.getUniforms(mainProgramH);
154
    EffectQueueMatrix.getUniforms(mainProgramH);
155
    mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
156

    
157
    // BLIT PROGRAM ////////////////////////////////////
158
    final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
159
    final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
160

    
161
    String blitVertHeader= ("#version 100\n#define NUM_VERTEX 0\n"  );
162
    String blitFragHeader= ("#version 100\n#define NUM_FRAGMENT 0\n");
163

    
164
    mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader);
165

    
166
    int blitProgramH = mBlitProgram.getProgramHandle();
167
    mBlitTextureH  = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
168
    mBlitDepthH    = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
169

    
170
    // DEBUG ONLY //////////////////////////////////////
171
    final InputStream debugVertexStream   = resources.openRawResource(R.raw.test_vertex_shader);
172
    final InputStream debugFragmentStream = resources.openRawResource(R.raw.test_fragment_shader);
173

    
174
    mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, "#version 100\n", "#version 100\n");
175

    
176
    int debugProgramH = mDebugProgram.getProgramHandle();
177
    mDebugObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
178
    mDebugMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
179
    // END DEBUG  //////////////////////////////////////
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  private void initializeEffectLists(DistortedEffects d, int flags)
185
    {
186
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
187
      {
188
      mM = d.mM;
189
      matrixCloned = true;
190
      }
191
    else
192
      {
193
      mM = new EffectQueueMatrix(mID);
194
      matrixCloned = false;
195
      }
196
    
197
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
198
      {
199
      mV = d.mV;
200
      vertexCloned = true;
201
      }
202
    else
203
      {
204
      mV = new EffectQueueVertex(mID);
205
      vertexCloned = false;
206
      }
207
    
208
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
209
      {
210
      mF = d.mF;
211
      fragmentCloned = true;
212
      }
213
    else
214
      {
215
      mF = new EffectQueueFragment(mID);
216
      fragmentCloned = false;
217
      }
218

    
219
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
220
      {
221
      mP = d.mP;
222
      postprocessCloned = true;
223
      }
224
    else
225
      {
226
      mP = new EffectQueuePostprocess(mID);
227
      postprocessCloned = false;
228
      }
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232
// DEBUG ONLY
233

    
234
  @SuppressWarnings("unused")
235
  private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices)
236
    {
237
    int len  = vertices.length/3;
238
    int minx = Integer.MAX_VALUE;
239
    int maxx = Integer.MIN_VALUE;
240
    int miny = Integer.MAX_VALUE;
241
    int maxy = Integer.MIN_VALUE;
242
    int wx,wy;
243

    
244
    float x,y,z, X,Y,W, ndcX,ndcY;
245

    
246
    for(int i=0; i<len; i++)
247
      {
248
      x = 2*halfX*vertices[3*i  ];
249
      y = 2*halfY*vertices[3*i+1];
250
      z = 2*halfZ*vertices[3*i+2];
251

    
252
      X = mvp[ 0]*x + mvp[ 4]*y + mvp[ 8]*z + mvp[12];
253
      Y = mvp[ 1]*x + mvp[ 5]*y + mvp[ 9]*z + mvp[13];
254
      W = mvp[ 3]*x + mvp[ 7]*y + mvp[11]*z + mvp[15];
255

    
256
      ndcX = X/W;
257
      ndcY = Y/W;
258

    
259
      wx = (int)(surface.mWidth *(ndcX+1)/2);
260
      wy = (int)(surface.mHeight*(ndcY+1)/2);
261

    
262
      if( wx<minx ) minx = wx;
263
      if( wx>maxx ) maxx = wx;
264
      if( wy<miny ) miny = wy;
265
      if( wy>maxy ) maxy = wy;
266
      }
267

    
268
    mDebugProgram.useProgram();
269
    surface.setAsOutput();
270

    
271
    Matrix.setIdentityM( mTmpMatrix, 0);
272
    Matrix.translateM  ( mTmpMatrix, 0, minx-surface.mWidth/2, maxy-surface.mHeight/2, -surface.mDistance);
273
    Matrix.scaleM      ( mTmpMatrix, 0, (float)(maxx-minx)/(2*halfX), (float)(maxy-miny)/(2*halfY), 1.0f);
274
    Matrix.translateM  ( mTmpMatrix, 0, halfX,-halfY, 0);
275
    Matrix.multiplyMM  ( mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
276

    
277
    GLES30.glUniform2f(mDebugObjDH, 2*halfX, 2*halfY);
278
    GLES30.glUniformMatrix4fv(mDebugMVPMatrixH, 1, false, mMVPMatrix , 0);
279

    
280
    GLES30.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
281
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
282
    }
283

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

    
286
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
287
    {
288
    mM.compute(currTime);
289
    mV.compute(currTime);
290
    mF.compute(currTime);
291
    mP.compute(currTime);
292

    
293
    float halfZ = halfW*mesh.zFactor;
294
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);
295

    
296
    if( mP.mNumEffects==0 )
297
      {
298
      mMainProgram.useProgram();
299
      GLES30.glUniform1i(mMainTextureH, 0);
300
      surface.setAsOutput();
301
      mM.send(surface,halfW,halfH,halfZ);
302
      mV.send(halfW,halfH,halfZ);
303
      mF.send(halfW,halfH);
304
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
305
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
306
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
307
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
308
      }
309
    else
310
      {
311
      if( mV.mNumEffects==0 && mF.mNumEffects==0 && (mesh instanceof MeshFlat) && mM.canUseShortcut() )
312
        {
313
        mM.constructMatrices(surface,halfW,halfH);
314
        mP.render(2*halfW, 2*halfH, mM.getMVP(), surface);
315
        }
316
      else
317
        {
318
        mMainProgram.useProgram();
319
        GLES30.glUniform1i(mMainTextureH, 0);
320
        mBufferFBO.resizeFast(surface.mWidth, surface.mHeight);
321
        mBufferFBO.setAsOutput();
322
        GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
323
        GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
324
        mM.send(mBufferFBO,halfW,halfH,halfZ);
325
        mV.send(halfW,halfH,halfZ);
326
        mF.send(halfW,halfH);
327
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
328
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
329
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
330
        GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
331

    
332
        Matrix.setIdentityM(mTmpMatrix, 0);
333
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -surface.mDistance);
334
        Matrix.multiplyMM(mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
335

    
336
        mBufferFBO.setAsInput();
337
        mP.render(surface.mWidth, surface.mHeight, mMVPMatrix, surface);
338
        }
339
      }
340

    
341
    /// DEBUG ONLY //////
342
    // displayBoundingRect(halfInputW, halfInputH, halfZ, df, mM.getMVP(), mesh.getBoundingVertices() );
343
    /// END DEBUG ///////
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
   
348
  static void blitPriv(DistortedOutputSurface projection)
349
    {
350
    mBlitProgram.useProgram();
351

    
352
    GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight);
353
    GLES30.glUniform1i(mBlitTextureH, 0);
354
    GLES30.glUniform1f( mBlitDepthH , 1.0f-projection.mNear);
355
    GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
356
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
357
    }
358
    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
   
361
  private void releasePriv()
362
    {
363
    if( !matrixCloned     ) mM.abortAll(false);
364
    if( !vertexCloned     ) mV.abortAll(false);
365
    if( !fragmentCloned   ) mF.abortAll(false);
366
    if( !postprocessCloned) mP.abortAll(false);
367

    
368
    mM = null;
369
    mV = null;
370
    mF = null;
371
    mP = null;
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  static void onDestroy()
377
    {
378
    mNextID = 0;
379

    
380
    int len = EffectNames.size();
381

    
382
    for(int i=0; i<len; i++)
383
      {
384
      mEffectEnabled[i] = false;
385
      }
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
// PUBLIC API
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
/**
392
 * Create empty effect queue.
393
 */
394
  public DistortedEffects()
395
    {
396
    mID = ++mNextID;
397
    initializeEffectLists(this,0);
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401
/**
402
 * Copy constructor.
403
 * <p>
404
 * Whatever we do not clone gets created just like in the default constructor.
405
 *
406
 * @param dc    Source object to create our object from
407
 * @param flags A bitmask of values specifying what to copy.
408
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
409
 */
410
  public DistortedEffects(DistortedEffects dc, int flags)
411
    {
412
    mID = ++mNextID;
413
    initializeEffectLists(dc,flags);
414
    }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417
/**
418
 * Releases all resources. After this call, the queue should not be used anymore.
419
 */
420
  public synchronized void delete()
421
    {
422
    releasePriv();
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426
/**
427
 * Returns unique ID of this instance.
428
 *
429
 * @return ID of the object.
430
 */
431
  public long getID()
432
      {
433
      return mID;
434
      }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437
/**
438
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
439
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
440
 * 
441
 * @param el A class implementing the EffectListener interface that wants to get notifications.
442
 */
443
  public void registerForMessages(EffectListener el)
444
    {
445
    mV.registerForMessages(el);
446
    mF.registerForMessages(el);
447
    mM.registerForMessages(el);
448
    mP.registerForMessages(el);
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452
/**
453
 * Removes the calling class from the list of Listeners.
454
 * 
455
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
456
 */
457
  public void deregisterForMessages(EffectListener el)
458
    {
459
    mV.deregisterForMessages(el);
460
    mF.deregisterForMessages(el);
461
    mM.deregisterForMessages(el);
462
    mP.deregisterForMessages(el);
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466
/**
467
 * Aborts all Effects.
468
 * @return Number of effects aborted.
469
 */
470
  public int abortAllEffects()
471
      {
472
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
473
      }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476
/**
477
 * Aborts all Effects of a given type, for example all MATRIX Effects.
478
 * 
479
 * @param type one of the constants defined in {@link EffectTypes}
480
 * @return Number of effects aborted.
481
 */
482
  public int abortEffects(EffectTypes type)
483
    {
484
    switch(type)
485
      {
486
      case MATRIX     : return mM.abortAll(true);
487
      case VERTEX     : return mV.abortAll(true);
488
      case FRAGMENT   : return mF.abortAll(true);
489
      case POSTPROCESS: return mP.abortAll(true);
490
      default         : return 0;
491
      }
492
    }
493
    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495
/**
496
 * Aborts a single Effect.
497
 * 
498
 * @param id ID of the Effect we want to abort.
499
 * @return number of Effects aborted. Always either 0 or 1.
500
 */
501
  public int abortEffect(long id)
502
    {
503
    int type = (int)(id&EffectTypes.MASK);
504

    
505
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
506
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
507
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
508
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
509

    
510
    return 0;
511
    }
512

    
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514
/**
515
 * Abort all Effects of a given name, for example all rotations.
516
 * 
517
 * @param name one of the constants defined in {@link EffectNames}
518
 * @return number of Effects aborted.
519
 */
520
  public int abortEffects(EffectNames name)
521
    {
522
    switch(name.getType())
523
      {
524
      case MATRIX     : return mM.removeByType(name);
525
      case VERTEX     : return mV.removeByType(name);
526
      case FRAGMENT   : return mF.removeByType(name);
527
      case POSTPROCESS: return mP.removeByType(name);
528
      default         : return 0;
529
      }
530
    }
531
    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
/**
534
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
535
 * 
536
 * @param id Effect ID we want to print info about
537
 * @return <code>true</code> if a single Effect of type effectType has been found.
538
 */
539
    
540
  public boolean printEffect(long id)
541
    {
542
    int type = (int)(id&EffectTypes.MASK);
543

    
544
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
545
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
546
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
547
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
548

    
549
    return false;
550
    }
551

    
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553
/**
554
 * Enables a given Effect.
555
 * <p>
556
 * By default, all effects are disabled. One has to explicitly enable each effect one intends to use.
557
 * This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
558
 * The point: by enabling only the effects we need, we can optimize the shaders.
559
 *
560
 * @param name Name of the Effect to enable.
561
 */
562
  public static void enableEffect(EffectNames name)
563
    {
564
    mEffectEnabled[name.ordinal()] = true;
565
    }
566

    
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568
/**
569
 * Returns the maximum number of Matrix effects.
570
 *
571
 * @return The maximum number of Matrix effects
572
 */
573
  public static int getMaxMatrix()
574
    {
575
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
576
    }
577

    
578
///////////////////////////////////////////////////////////////////////////////////////////////////
579
/**
580
 * Returns the maximum number of Vertex effects.
581
 *
582
 * @return The maximum number of Vertex effects
583
 */
584
  public static int getMaxVertex()
585
    {
586
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
587
    }
588

    
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590
/**
591
 * Returns the maximum number of Fragment effects.
592
 *
593
 * @return The maximum number of Fragment effects
594
 */
595
  public static int getMaxFragment()
596
    {
597
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
598
    }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601
/**
602
 * Returns the maximum number of Postprocess effects.
603
 *
604
 * @return The maximum number of Postprocess effects
605
 */
606
  public static int getMaxPostprocess()
607
    {
608
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
609
    }
610

    
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612
/**
613
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
614
 * This can fail if:
615
 * <ul>
616
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
617
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
618
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
619
 *     time only decreasing the value of 'max' is permitted.
620
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
621
 * </ul>
622
 *
623
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
624
 *            than Byte.MAX_VALUE
625
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
626
 */
627
  public static boolean setMaxMatrix(int max)
628
    {
629
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
630
    }
631

    
632
///////////////////////////////////////////////////////////////////////////////////////////////////
633
/**
634
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
635
 * This can fail if:
636
 * <ul>
637
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
638
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
639
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
640
 *     time only decreasing the value of 'max' is permitted.
641
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
642
 * </ul>
643
 *
644
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
645
 *            than Byte.MAX_VALUE
646
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
647
 */
648
  public static boolean setMaxVertex(int max)
649
    {
650
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
651
    }
652

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654
/**
655
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
656
 * This can fail if:
657
 * <ul>
658
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
659
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
660
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
661
 *     time only decreasing the value of 'max' is permitted.
662
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
663
 * </ul>
664
 *
665
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
666
 *            than Byte.MAX_VALUE
667
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
668
 */
669
  public static boolean setMaxFragment(int max)
670
    {
671
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
672
    }
673

    
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675
/**
676
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
677
 * This can fail if:
678
 * <ul>
679
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
680
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
681
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
682
 *     time only decreasing the value of 'max' is permitted.
683
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
684
 * </ul>
685
 *
686
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
687
 *            than Byte.MAX_VALUE
688
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
689
 */
690
  public static boolean setMaxPostprocess(int max)
691
    {
692
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
693
    }
694

    
695
///////////////////////////////////////////////////////////////////////////////////////////////////   
696
///////////////////////////////////////////////////////////////////////////////////////////////////
697
// Individual effect functions.
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699
// Matrix-based effects
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701
/**
702
 * Moves the Object by a (possibly changing in time) vector.
703
 * 
704
 * @param vector 3-dimensional Data which at any given time will return a Static3D
705
 *               representing the current coordinates of the vector we want to move the Object with.
706
 * @return       ID of the effect added, or -1 if we failed to add one.
707
 */
708
  public long move(Data3D vector)
709
    {   
710
    return mM.add(EffectNames.MOVE,vector);
711
    }
712

    
713
///////////////////////////////////////////////////////////////////////////////////////////////////
714
/**
715
 * Scales the Object by (possibly changing in time) 3D scale factors.
716
 * 
717
 * @param scale 3-dimensional Data which at any given time returns a Static3D
718
 *              representing the current x- , y- and z- scale factors.
719
 * @return      ID of the effect added, or -1 if we failed to add one.
720
 */
721
  public long scale(Data3D scale)
722
    {   
723
    return mM.add(EffectNames.SCALE,scale);
724
    }
725

    
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727
/**
728
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
729
 *
730
 * @param scale The factor to scale all 3 dimensions with.
731
 * @return      ID of the effect added, or -1 if we failed to add one.
732
 */
733
  public long scale(float scale)
734
    {
735
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
736
    }
737

    
738
///////////////////////////////////////////////////////////////////////////////////////////////////
739
/**
740
 * Rotates the Object by 'angle' degrees around the center.
741
 * Static axis of rotation is given by the last parameter.
742
 *
743
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
744
 * @param axis   Axis of rotation
745
 * @param center Coordinates of the Point we are rotating around.
746
 * @return       ID of the effect added, or -1 if we failed to add one.
747
 */
748
  public long rotate(Data1D angle, Static3D axis, Data3D center )
749
    {   
750
    return mM.add(EffectNames.ROTATE, angle, axis, center);
751
    }
752

    
753
///////////////////////////////////////////////////////////////////////////////////////////////////
754
/**
755
 * Rotates the Object by 'angle' degrees around the center.
756
 * Here both angle and axis can dynamically change.
757
 *
758
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
759
 * @param center    Coordinates of the Point we are rotating around.
760
 * @return          ID of the effect added, or -1 if we failed to add one.
761
 */
762
  public long rotate(Data4D angleaxis, Data3D center)
763
    {
764
    return mM.add(EffectNames.ROTATE, angleaxis, center);
765
    }
766

    
767
///////////////////////////////////////////////////////////////////////////////////////////////////
768
/**
769
 * Rotates the Object by quaternion.
770
 *
771
 * @param quaternion The quaternion describing the rotation.
772
 * @param center     Coordinates of the Point we are rotating around.
773
 * @return           ID of the effect added, or -1 if we failed to add one.
774
 */
775
  public long quaternion(Data4D quaternion, Data3D center )
776
    {
777
    return mM.add(EffectNames.QUATERNION,quaternion,center);
778
    }
779

    
780
///////////////////////////////////////////////////////////////////////////////////////////////////
781
/**
782
 * Shears the Object.
783
 *
784
 * @param shear   The 3-tuple of shear factors. The first controls level
785
 *                of shearing in the X-axis, second - Y-axis and the third -
786
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
787
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
788
 * @param center  Center of shearing, i.e. the point which stays unmoved.
789
 * @return        ID of the effect added, or -1 if we failed to add one.
790
 */
791
  public long shear(Data3D shear, Data3D center)
792
    {
793
    return mM.add(EffectNames.SHEAR, shear, center);
794
    }
795

    
796
///////////////////////////////////////////////////////////////////////////////////////////////////
797
// Fragment-based effects  
798
///////////////////////////////////////////////////////////////////////////////////////////////////
799
/**
800
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
801
 *        
802
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
803
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
804
 *               Valid range: <0,1>
805
 * @param color  Color to mix. (1,0,0) is RED.
806
 * @param region Region this Effect is limited to.
807
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
808
 * @return       ID of the effect added, or -1 if we failed to add one.
809
 */
810
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
811
    {
812
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
813
    }
814

    
815
///////////////////////////////////////////////////////////////////////////////////////////////////
816
/**
817
 * Makes the whole Object smoothly change all three of its RGB components.
818
 *
819
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
820
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
821
 *               Valid range: <0,1>
822
 * @param color  Color to mix. (1,0,0) is RED.
823
 * @return       ID of the effect added, or -1 if we failed to add one.
824
 */
825
  public long chroma(Data1D blend, Data3D color)
826
    {
827
    return mF.add(EffectNames.CHROMA, blend, color);
828
    }
829

    
830
///////////////////////////////////////////////////////////////////////////////////////////////////
831
/**
832
 * Makes a certain sub-region of the Object smoothly change its transparency level.
833
 *        
834
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
835
 *               moment: pixel.a *= alpha.
836
 *               Valid range: <0,1>
837
 * @param region Region this Effect is limited to. 
838
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
839
 * @return       ID of the effect added, or -1 if we failed to add one. 
840
 */
841
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
842
    {
843
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
844
    }
845

    
846
///////////////////////////////////////////////////////////////////////////////////////////////////
847
/**
848
 * Makes the whole Object smoothly change its transparency level.
849
 *
850
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
851
 *               given moment: pixel.a *= alpha.
852
 *               Valid range: <0,1>
853
 * @return       ID of the effect added, or -1 if we failed to add one.
854
 */
855
  public long alpha(Data1D alpha)
856
    {
857
    return mF.add(EffectNames.ALPHA, alpha);
858
    }
859

    
860
///////////////////////////////////////////////////////////////////////////////////////////////////
861
/**
862
 * Makes a certain sub-region of the Object smoothly change its brightness level.
863
 *        
864
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
865
 *                   at any given moment. Valid range: <0,infinity)
866
 * @param region     Region this Effect is limited to.
867
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
868
 * @return           ID of the effect added, or -1 if we failed to add one.
869
 */
870
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
871
    {
872
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
873
    }
874

    
875
///////////////////////////////////////////////////////////////////////////////////////////////////
876
/**
877
 * Makes the whole Object smoothly change its brightness level.
878
 *
879
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
880
 *                   at any given moment. Valid range: <0,infinity)
881
 * @return           ID of the effect added, or -1 if we failed to add one.
882
 */
883
  public long brightness(Data1D brightness)
884
    {
885
    return mF.add(EffectNames.BRIGHTNESS, brightness);
886
    }
887

    
888
///////////////////////////////////////////////////////////////////////////////////////////////////
889
/**
890
 * Makes a certain sub-region of the Object smoothly change its contrast level.
891
 *        
892
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
893
 *                 at any given moment. Valid range: <0,infinity)
894
 * @param region   Region this Effect is limited to.
895
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
896
 * @return         ID of the effect added, or -1 if we failed to add one.
897
 */
898
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
899
    {
900
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
901
    }
902

    
903
///////////////////////////////////////////////////////////////////////////////////////////////////
904
/**
905
 * Makes the whole Object smoothly change its contrast level.
906
 *
907
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
908
 *                 at any given moment. Valid range: <0,infinity)
909
 * @return         ID of the effect added, or -1 if we failed to add one.
910
 */
911
  public long contrast(Data1D contrast)
912
    {
913
    return mF.add(EffectNames.CONTRAST, contrast);
914
    }
915

    
916
///////////////////////////////////////////////////////////////////////////////////////////////////
917
/**
918
 * Makes a certain sub-region of the Object smoothly change its saturation level.
919
 *        
920
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
921
 *                   at any given moment. Valid range: <0,infinity)
922
 * @param region     Region this Effect is limited to.
923
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
924
 * @return           ID of the effect added, or -1 if we failed to add one.
925
 */
926
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
927
    {
928
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
929
    }
930

    
931
///////////////////////////////////////////////////////////////////////////////////////////////////
932
/**
933
 * Makes the whole Object smoothly change its saturation level.
934
 *
935
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
936
 *                   at any given moment. Valid range: <0,infinity)
937
 * @return           ID of the effect added, or -1 if we failed to add one.
938
 */
939
  public long saturation(Data1D saturation)
940
    {
941
    return mF.add(EffectNames.SATURATION, saturation);
942
    }
943

    
944
///////////////////////////////////////////////////////////////////////////////////////////////////
945
// Vertex-based effects  
946
///////////////////////////////////////////////////////////////////////////////////////////////////
947
/**
948
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
949
 *
950
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
951
 *               currently being dragged with.
952
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
953
 * @param region Region that masks the Effect.
954
 * @return       ID of the effect added, or -1 if we failed to add one.
955
 */
956
  public long distort(Data3D vector, Data3D center, Data4D region)
957
    {  
958
    return mV.add(EffectNames.DISTORT, vector, center, region);
959
    }
960

    
961
///////////////////////////////////////////////////////////////////////////////////////////////////
962
/**
963
 * Distort the whole Object by a (possibly changing in time) vector of force.
964
 *
965
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
966
 *               currently being dragged with.
967
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
968
 * @return       ID of the effect added, or -1 if we failed to add one.
969
 */
970
  public long distort(Data3D vector, Data3D center)
971
    {
972
    return mV.add(EffectNames.DISTORT, vector, center, null);
973
    }
974

    
975
///////////////////////////////////////////////////////////////////////////////////////////////////
976
/**
977
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
978
 * a (possibly changing in time) point on the Object.
979
 *
980
 * @param vector Vector of force that deforms the shape of the whole Object.
981
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
982
 * @param region Region that masks the Effect.
983
 * @return       ID of the effect added, or -1 if we failed to add one.
984
 */
985
  public long deform(Data3D vector, Data3D center, Data4D region)
986
    {
987
    return mV.add(EffectNames.DEFORM, vector, center, region);
988
    }
989

    
990
///////////////////////////////////////////////////////////////////////////////////////////////////
991
/**
992
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
993
 * a (possibly changing in time) point on the Object.
994
 *     
995
 * @param vector Vector of force that deforms the shape of the whole Object.
996
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
997
 * @return       ID of the effect added, or -1 if we failed to add one.
998
 */
999
  public long deform(Data3D vector, Data3D center)
1000
    {  
1001
    return mV.add(EffectNames.DEFORM, vector, center, null);
1002
    }
1003

    
1004
///////////////////////////////////////////////////////////////////////////////////////////////////  
1005
/**
1006
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
1007
 * away from the center (degree<=1)
1008
 *
1009
 * @param sink   The current degree of the Effect.
1010
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1011
 * @param region Region that masks the Effect.
1012
 * @return       ID of the effect added, or -1 if we failed to add one.
1013
 */
1014
  public long sink(Data1D sink, Data3D center, Data4D region)
1015
    {
1016
    return mV.add(EffectNames.SINK, sink, center, region);
1017
    }
1018

    
1019
///////////////////////////////////////////////////////////////////////////////////////////////////
1020
/**
1021
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
1022
 * away from the center (degree<=1)
1023
 *
1024
 * @param sink   The current degree of the Effect.
1025
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1026
 * @return       ID of the effect added, or -1 if we failed to add one.
1027
 */
1028
  public long sink(Data1D sink, Data3D center)
1029
    {
1030
    return mV.add(EffectNames.SINK, sink, center);
1031
    }
1032

    
1033
///////////////////////////////////////////////////////////////////////////////////////////////////
1034
/**
1035
 * Pull all points around the center of the Effect towards a line passing through the center
1036
 * (that's if degree>=1) or push them away from the line (degree<=1)
1037
 *
1038
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1039
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1040
 * @param region Region that masks the Effect.
1041
 * @return       ID of the effect added, or -1 if we failed to add one.
1042
 */
1043
  public long pinch(Data2D pinch, Data3D center, Data4D region)
1044
    {
1045
    return mV.add(EffectNames.PINCH, pinch, center, region);
1046
    }
1047

    
1048
///////////////////////////////////////////////////////////////////////////////////////////////////
1049
/**
1050
 * Pull all points around the center of the Effect towards a line passing through the center
1051
 * (that's if degree>=1) or push them away from the line (degree<=1)
1052
 *
1053
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1054
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1055
 * @return       ID of the effect added, or -1 if we failed to add one.
1056
 */
1057
  public long pinch(Data2D pinch, Data3D center)
1058
    {
1059
    return mV.add(EffectNames.PINCH, pinch, center);
1060
    }
1061

    
1062
///////////////////////////////////////////////////////////////////////////////////////////////////  
1063
/**
1064
 * Rotate part of the Object around the Center of the Effect by a certain angle.
1065
 *
1066
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1067
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1068
 * @param region Region that masks the Effect.
1069
 * @return       ID of the effect added, or -1 if we failed to add one.
1070
 */
1071
  public long swirl(Data1D swirl, Data3D center, Data4D region)
1072
    {    
1073
    return mV.add(EffectNames.SWIRL, swirl, center, region);
1074
    }
1075

    
1076
///////////////////////////////////////////////////////////////////////////////////////////////////
1077
/**
1078
 * Rotate the whole Object around the Center of the Effect by a certain angle.
1079
 *
1080
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1081
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1082
 * @return       ID of the effect added, or -1 if we failed to add one.
1083
 */
1084
  public long swirl(Data1D swirl, Data3D center)
1085
    {
1086
    return mV.add(EffectNames.SWIRL, swirl, center);
1087
    }
1088

    
1089
///////////////////////////////////////////////////////////////////////////////////////////////////
1090
/**
1091
 * Directional, sinusoidal wave effect.
1092
 *
1093
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
1094
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
1095
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
1096
 *               describe the 'direction' of the wave.
1097
 *               <p>
1098
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
1099
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
1100
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
1101
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
1102
 *               <p>
1103
 *               <p>
1104
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
1105
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
1106
 *               will be sine shapes.
1107
 *               <p>
1108
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
1109
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
1110
 *               YZ-plane with be sine shapes.
1111
 *               <p>
1112
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
1113
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
1114
 *               value if sin at this point.
1115
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1116
 * @return       ID of the effect added, or -1 if we failed to add one.
1117
 */
1118
  public long wave(Data5D wave, Data3D center)
1119
    {
1120
    return mV.add(EffectNames.WAVE, wave, center, null);
1121
    }
1122

    
1123
///////////////////////////////////////////////////////////////////////////////////////////////////
1124
/**
1125
 * Directional, sinusoidal wave effect.
1126
 *
1127
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
1128
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1129
 * @param region Region that masks the Effect.
1130
 * @return       ID of the effect added, or -1 if we failed to add one.
1131
 */
1132
  public long wave(Data5D wave, Data3D center, Data4D region)
1133
    {
1134
    return mV.add(EffectNames.WAVE, wave, center, region);
1135
    }
1136

    
1137
///////////////////////////////////////////////////////////////////////////////////////////////////
1138
// Postprocess-based effects
1139
///////////////////////////////////////////////////////////////////////////////////////////////////
1140
/**
1141
 * Blur the object.
1142
 *
1143
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
1144
 *               take into account 10 pixels in each direction.
1145
 * @return ID of the effect added, or -1 if we failed to add one.
1146
 */
1147
  public long blur(Data1D radius)
1148
    {
1149
    return mP.add(EffectNames.BLUR, radius);
1150
    }
1151
  }
(4-4/23)