Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 2b942cd0

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6a06a912 Leszek Koltunski
package org.distorted.library;
21
22
import android.opengl.GLES20;
23
24 e458a4ba Leszek Koltunski
import org.distorted.library.message.EffectListener;
25 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data1D;
26 f2fe7e28 Leszek Koltunski
import org.distorted.library.type.Data2D;
27 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data3D;
28
import org.distorted.library.type.Data4D;
29 350cc2f5 Leszek Koltunski
import org.distorted.library.type.Data5D;
30 568b29d8 Leszek Koltunski
import org.distorted.library.type.Static3D;
31 a4835695 Leszek Koltunski
32 c638c1b0 Leszek Koltunski
import java.nio.ByteBuffer;
33
import java.nio.ByteOrder;
34
import java.nio.FloatBuffer;
35
36 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
37 b329f352 Leszek Koltunski
/**
38 4e2382f3 Leszek Koltunski
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
39 b73dcaa7 Leszek Koltunski
 * <p>
40 26df012c Leszek Koltunski
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
41 b329f352 Leszek Koltunski
 */
42 421c2728 Leszek Koltunski
public class DistortedEffects
43 d425545a Leszek Koltunski
  {
44 c638c1b0 Leszek Koltunski
  private static final int BYTES_PER_FLOAT   = 4; //
45
  private static final int POSITION_DATA_SIZE= 2; // Size of the position data in elements
46
  private static final int TEX_DATA_SIZE     = 2; // Size of the texture coordinate data in elements.
47
  private static final FloatBuffer mQuadPositions, mQuadTexture;
48
49 8e34674e Leszek Koltunski
  private static long mNextID =0;
50 4e2382f3 Leszek Koltunski
  private long mID;
51 8e34674e Leszek Koltunski
52 86eb00a9 Leszek Koltunski
  private static DistortedFramebuffer mBufferFBO;
53
54 d6e94c84 Leszek Koltunski
  private EffectQueueMatrix      mM;
55
  private EffectQueueFragment    mF;
56
  private EffectQueueVertex      mV;
57
  private EffectQueuePostprocess mP;
58 3d590d8d Leszek Koltunski
59 d6e94c84 Leszek Koltunski
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
60 985ea9c5 Leszek Koltunski
61 c638c1b0 Leszek Koltunski
  static
62
    {
63
    int dataLength = 4;
64
65
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
66
    float[] textureData = {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
67
68
    mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
69
    mQuadPositions.put(positionData).position(0);
70
    mQuadTexture   = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
71
    mQuadTexture.put(textureData).position(0);
72 86eb00a9 Leszek Koltunski
73
    mBufferFBO = new DistortedFramebuffer(1,1);
74 c638c1b0 Leszek Koltunski
    }
75
76 9361b337 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
77 6a06a912 Leszek Koltunski
    
78 421c2728 Leszek Koltunski
  private void initializeEffectLists(DistortedEffects d, int flags)
79 d425545a Leszek Koltunski
    {
80 015642fb Leszek Koltunski
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
81 6a06a912 Leszek Koltunski
      {
82 d425545a Leszek Koltunski
      mM = d.mM;
83
      matrixCloned = true;
84
      }
85
    else
86
      {
87 4e2382f3 Leszek Koltunski
      mM = new EffectQueueMatrix(mID);
88 d425545a Leszek Koltunski
      matrixCloned = false;
89
      }
90 6a06a912 Leszek Koltunski
    
91 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
92
      {
93
      mV = d.mV;
94
      vertexCloned = true;
95
      }
96
    else
97
      {
98 4e2382f3 Leszek Koltunski
      mV = new EffectQueueVertex(mID);
99 d425545a Leszek Koltunski
      vertexCloned = false;
100
      }
101 6a06a912 Leszek Koltunski
    
102 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
103
      {
104
      mF = d.mF;
105
      fragmentCloned = true;
106 6a06a912 Leszek Koltunski
      }
107 d425545a Leszek Koltunski
    else
108
      {
109 4e2382f3 Leszek Koltunski
      mF = new EffectQueueFragment(mID);
110 d425545a Leszek Koltunski
      fragmentCloned = false;
111
      }
112 d6e94c84 Leszek Koltunski
113
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
114
      {
115
      mP = d.mP;
116
      postprocessCloned = true;
117
      }
118
    else
119
      {
120
      mP = new EffectQueuePostprocess(mID);
121
      postprocessCloned = false;
122
      }
123 d425545a Leszek Koltunski
    }
124 6a06a912 Leszek Koltunski
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
   
127 05403bba Leszek Koltunski
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
128 d425545a Leszek Koltunski
    {
129
    mM.compute(currTime);
130
    mV.compute(currTime);
131
    mF.compute(currTime);
132 d6e94c84 Leszek Koltunski
    mP.compute(currTime);
133 a56bc359 Leszek Koltunski
134 d6e94c84 Leszek Koltunski
    float halfZ = halfInputW*mesh.zFactor;
135
136
    GLES20.glUseProgram(Distorted.mainProgramH);
137 86eb00a9 Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
138 d6e94c84 Leszek Koltunski
139
    if( mP.mNumEffects==0 )
140
      {
141
      mM.send(df,halfInputW,halfInputH,halfZ);
142
      mV.send(halfInputW,halfInputH,halfZ);
143
      mF.send(halfInputW,halfInputH);
144
145
      mesh.draw();
146
      }
147
    else
148
      {
149 2b942cd0 Leszek Koltunski
      if( mV.mNumEffects>0 || mP.mNumEffects>0 )
150
        {
151
        mBufferFBO.resizeFast(df.mWidth, df.mHeight);
152
        mBufferFBO.setAsOutput();
153
154
        mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
155
        mV.send(halfInputW,halfInputH,halfZ);
156
        mF.send(halfInputW,halfInputH);
157
158
        mesh.draw();
159
160
        GLES20.glUseProgram(Distorted.postProgramH);
161
        GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
162
        mBufferFBO.setAsInput();
163
        df.setAsOutput();
164
        mP.send(df);
165
166
        GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
167
        GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
168
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
169
        }
170
      else
171
        {
172
        GLES20.glUseProgram(Distorted.postProgramH);
173
        GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
174
        mP.send(df);
175
176
        GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
177
        GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
178
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
179
        }
180 d6e94c84 Leszek Koltunski
      }
181 d425545a Leszek Koltunski
    }
182 6a06a912 Leszek Koltunski
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184
   
185 d6e94c84 Leszek Koltunski
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
186 d425545a Leszek Koltunski
    {
187 ed13a5de Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
188 0a046359 Leszek Koltunski
189 d6e94c84 Leszek Koltunski
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
190
    EffectQueueVertex.sendZero();
191
    EffectQueueFragment.sendZero();
192 2b942cd0 Leszek Koltunski
    EffectQueuePostprocess.sendZero(df);
193 a56bc359 Leszek Koltunski
194 05403bba Leszek Koltunski
    mesh.draw();
195 d425545a Leszek Koltunski
    }
196 6a06a912 Leszek Koltunski
    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
   
199 8e34674e Leszek Koltunski
  private void releasePriv()
200 d425545a Leszek Koltunski
    {
201 d6e94c84 Leszek Koltunski
    if( !matrixCloned     ) mM.abortAll(false);
202
    if( !vertexCloned     ) mV.abortAll(false);
203
    if( !fragmentCloned   ) mF.abortAll(false);
204
    if( !postprocessCloned) mP.abortAll(false);
205 d425545a Leszek Koltunski
206 4e2382f3 Leszek Koltunski
    mM = null;
207
    mV = null;
208
    mF = null;
209 d6e94c84 Leszek Koltunski
    mP = null;
210 8e34674e Leszek Koltunski
    }
211
212 1942537e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
213
214 7b8086eb Leszek Koltunski
  static void onDestroy()
215 1942537e Leszek Koltunski
    {
216
    mNextID = 0;
217
    }
218
219 8e34674e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
220
// PUBLIC API
221 ada90d33 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
222 d425545a Leszek Koltunski
/**
223 4e2382f3 Leszek Koltunski
 * Create empty effect queue.
224 d425545a Leszek Koltunski
 */
225 421c2728 Leszek Koltunski
  public DistortedEffects()
226 d425545a Leszek Koltunski
    {
227 4e2382f3 Leszek Koltunski
    mID = mNextID++;
228
    initializeEffectLists(this,0);
229 d425545a Leszek Koltunski
    }
230 ada90d33 Leszek Koltunski
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232 d425545a Leszek Koltunski
/**
233 4e2382f3 Leszek Koltunski
 * Copy constructor.
234 d425545a Leszek Koltunski
 * <p>
235
 * Whatever we do not clone gets created just like in the default constructor.
236
 *
237
 * @param dc    Source object to create our object from
238
 * @param flags A bitmask of values specifying what to copy.
239 e6ab30eb Leszek Koltunski
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
240 d425545a Leszek Koltunski
 */
241 421c2728 Leszek Koltunski
  public DistortedEffects(DistortedEffects dc, int flags)
242 d425545a Leszek Koltunski
    {
243 8e34674e Leszek Koltunski
    mID = mNextID++;
244 4e2382f3 Leszek Koltunski
    initializeEffectLists(dc,flags);
245 d425545a Leszek Koltunski
    }
246 ada90d33 Leszek Koltunski
247 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
248
/**
249 07305c87 Leszek Koltunski
 * Releases all resources. After this call, the queue should not be used anymore.
250 6a06a912 Leszek Koltunski
 */
251 8e34674e Leszek Koltunski
  public synchronized void delete()
252 d425545a Leszek Koltunski
    {
253
    releasePriv();
254
    }
255 6a06a912 Leszek Koltunski
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257
/**
258 4e2382f3 Leszek Koltunski
 * Returns unique ID of this instance.
259
 *
260
 * @return ID of the object.
261 6a06a912 Leszek Koltunski
 */
262 4e2382f3 Leszek Koltunski
  public long getID()
263 d425545a Leszek Koltunski
      {
264 4e2382f3 Leszek Koltunski
      return mID;
265 d425545a Leszek Koltunski
      }
266 4e2382f3 Leszek Koltunski
267 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
268
/**
269
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
270 07305c87 Leszek Koltunski
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
271 6a06a912 Leszek Koltunski
 * 
272
 * @param el A class implementing the EffectListener interface that wants to get notifications.
273
 */
274 3fc994b2 Leszek Koltunski
  public void registerForMessages(EffectListener el)
275 d425545a Leszek Koltunski
    {
276 3fc994b2 Leszek Koltunski
    mV.registerForMessages(el);
277
    mF.registerForMessages(el);
278
    mM.registerForMessages(el);
279 d6e94c84 Leszek Koltunski
    mP.registerForMessages(el);
280 d425545a Leszek Koltunski
    }
281 6a06a912 Leszek Koltunski
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283
/**
284
 * Removes the calling class from the list of Listeners.
285
 * 
286
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
287
 */
288 3fc994b2 Leszek Koltunski
  public void deregisterForMessages(EffectListener el)
289 d425545a Leszek Koltunski
    {
290 3fc994b2 Leszek Koltunski
    mV.deregisterForMessages(el);
291
    mF.deregisterForMessages(el);
292
    mM.deregisterForMessages(el);
293 d6e94c84 Leszek Koltunski
    mP.deregisterForMessages(el);
294 d425545a Leszek Koltunski
    }
295 6a06a912 Leszek Koltunski
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297
/**
298 d07f2950 Leszek Koltunski
 * Aborts all Effects.
299
 * @return Number of effects aborted.
300 6a06a912 Leszek Koltunski
 */
301 d425545a Leszek Koltunski
  public int abortAllEffects()
302 6a06a912 Leszek Koltunski
      {
303 d6e94c84 Leszek Koltunski
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
304 6a06a912 Leszek Koltunski
      }
305
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307
/**
308 d07f2950 Leszek Koltunski
 * Aborts all Effects of a given type, for example all MATRIX Effects.
309 6a06a912 Leszek Koltunski
 * 
310 d07f2950 Leszek Koltunski
 * @param type one of the constants defined in {@link EffectTypes}
311
 * @return Number of effects aborted.
312 6a06a912 Leszek Koltunski
 */
313 d425545a Leszek Koltunski
  public int abortEffects(EffectTypes type)
314
    {
315
    switch(type)
316 6a06a912 Leszek Koltunski
      {
317 d6e94c84 Leszek Koltunski
      case MATRIX     : return mM.abortAll(true);
318
      case VERTEX     : return mV.abortAll(true);
319
      case FRAGMENT   : return mF.abortAll(true);
320
      case POSTPROCESS: return mP.abortAll(true);
321
      default         : return 0;
322 6a06a912 Leszek Koltunski
      }
323 d425545a Leszek Koltunski
    }
324 6a06a912 Leszek Koltunski
    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326
/**
327
 * Aborts a single Effect.
328
 * 
329
 * @param id ID of the Effect we want to abort.
330 476bbc81 Leszek Koltunski
 * @return number of Effects aborted. Always either 0 or 1.
331 6a06a912 Leszek Koltunski
 */
332 d425545a Leszek Koltunski
  public int abortEffect(long id)
333
    {
334
    int type = (int)(id&EffectTypes.MASK);
335 1e438fc7 Leszek Koltunski
336 d6e94c84 Leszek Koltunski
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
337
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
338
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
339
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
340 1e438fc7 Leszek Koltunski
341 d425545a Leszek Koltunski
    return 0;
342
    }
343 6a06a912 Leszek Koltunski
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345
/**
346 e8c81a8e Leszek Koltunski
 * Abort all Effects of a given name, for example all rotations.
347 6a06a912 Leszek Koltunski
 * 
348 d07f2950 Leszek Koltunski
 * @param name one of the constants defined in {@link EffectNames}
349 476bbc81 Leszek Koltunski
 * @return number of Effects aborted.
350 6a06a912 Leszek Koltunski
 */
351 d425545a Leszek Koltunski
  public int abortEffects(EffectNames name)
352
    {
353
    switch(name.getType())
354 6a06a912 Leszek Koltunski
      {
355 d6e94c84 Leszek Koltunski
      case MATRIX     : return mM.removeByType(name);
356
      case VERTEX     : return mV.removeByType(name);
357
      case FRAGMENT   : return mF.removeByType(name);
358
      case POSTPROCESS: return mP.removeByType(name);
359
      default         : return 0;
360 6a06a912 Leszek Koltunski
      }
361 d425545a Leszek Koltunski
    }
362 6a06a912 Leszek Koltunski
    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364
/**
365
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
366
 * 
367
 * @param id Effect ID we want to print info about
368
 * @return <code>true</code> if a single Effect of type effectType has been found.
369
 */
370
    
371 d425545a Leszek Koltunski
  public boolean printEffect(long id)
372
    {
373
    int type = (int)(id&EffectTypes.MASK);
374 1e438fc7 Leszek Koltunski
375 d6e94c84 Leszek Koltunski
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
376
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
377
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
378
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
379 1e438fc7 Leszek Koltunski
380 d425545a Leszek Koltunski
    return false;
381
    }
382 432442f9 Leszek Koltunski
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384
/**
385
 * Returns the maximum number of Matrix effects.
386
 *
387
 * @return The maximum number of Matrix effects
388
 */
389
  public static int getMaxMatrix()
390
    {
391
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
392
    }
393
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395
/**
396
 * Returns the maximum number of Vertex effects.
397
 *
398
 * @return The maximum number of Vertex effects
399
 */
400
  public static int getMaxVertex()
401
    {
402
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
403
    }
404
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406
/**
407
 * Returns the maximum number of Fragment effects.
408
 *
409
 * @return The maximum number of Fragment effects
410
 */
411
  public static int getMaxFragment()
412
    {
413
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
414
    }
415
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417
/**
418
 * Returns the maximum number of Postprocess effects.
419
 *
420
 * @return The maximum number of Postprocess effects
421
 */
422
  public static int getMaxPostprocess()
423
    {
424
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
425
    }
426
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
/**
429
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
430
 * This can fail if:
431
 * <ul>
432
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
433
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
434
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
435
 *     time only decreasing the value of 'max' is permitted.
436
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
437
 * </ul>
438
 *
439
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
440
 *            than Byte.MAX_VALUE
441
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
442
 */
443
  public static boolean setMaxMatrix(int max)
444
    {
445
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
446
    }
447
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449
/**
450
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
451
 * This can fail if:
452
 * <ul>
453
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
454
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
455
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
456
 *     time only decreasing the value of 'max' is permitted.
457
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
458
 * </ul>
459
 *
460
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
461
 *            than Byte.MAX_VALUE
462
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
463
 */
464
  public static boolean setMaxVertex(int max)
465
    {
466
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
467
    }
468
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470
/**
471
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
472
 * This can fail if:
473
 * <ul>
474
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
475
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
476
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
477
 *     time only decreasing the value of 'max' is permitted.
478
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
479
 * </ul>
480
 *
481
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
482
 *            than Byte.MAX_VALUE
483
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
484
 */
485
  public static boolean setMaxFragment(int max)
486
    {
487
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
488
    }
489
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491
/**
492
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
493
 * This can fail if:
494
 * <ul>
495
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
496
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
497
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
498
 *     time only decreasing the value of 'max' is permitted.
499
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
500
 * </ul>
501
 *
502
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
503
 *            than Byte.MAX_VALUE
504
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
505
 */
506
  public static boolean setMaxPostprocess(int max)
507
    {
508
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
509
    }
510
511 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////   
512
///////////////////////////////////////////////////////////////////////////////////////////////////
513
// Individual effect functions.
514
///////////////////////////////////////////////////////////////////////////////////////////////////
515
// Matrix-based effects
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
/**
518 e8c81a8e Leszek Koltunski
 * Moves the Object by a (possibly changing in time) vector.
519 6a06a912 Leszek Koltunski
 * 
520 568b29d8 Leszek Koltunski
 * @param vector 3-dimensional Data which at any given time will return a Static3D
521 e0a16874 Leszek Koltunski
 *               representing the current coordinates of the vector we want to move the Object with.
522
 * @return       ID of the effect added, or -1 if we failed to add one.
523 6a06a912 Leszek Koltunski
 */
524 568b29d8 Leszek Koltunski
  public long move(Data3D vector)
525 6a06a912 Leszek Koltunski
    {   
526 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.MOVE,vector);
527 6a06a912 Leszek Koltunski
    }
528
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530
/**
531 e8c81a8e Leszek Koltunski
 * Scales the Object by (possibly changing in time) 3D scale factors.
532 6a06a912 Leszek Koltunski
 * 
533 d1e740c5 Leszek Koltunski
 * @param scale 3-dimensional Data which at any given time returns a Static3D
534 e0a16874 Leszek Koltunski
 *              representing the current x- , y- and z- scale factors.
535
 * @return      ID of the effect added, or -1 if we failed to add one.
536 6a06a912 Leszek Koltunski
 */
537 568b29d8 Leszek Koltunski
  public long scale(Data3D scale)
538 6a06a912 Leszek Koltunski
    {   
539 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.SCALE,scale);
540 6a06a912 Leszek Koltunski
    }
541
542 2fce34f4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
543
/**
544 e8c81a8e Leszek Koltunski
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
545 2fce34f4 Leszek Koltunski
 *
546
 * @param scale The factor to scale all 3 dimensions with.
547
 * @return      ID of the effect added, or -1 if we failed to add one.
548
 */
549 d425545a Leszek Koltunski
  public long scale(float scale)
550
    {
551
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
552
    }
553 2fce34f4 Leszek Koltunski
554 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
555
/**
556 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
557
 * Static axis of rotation is given by the last parameter.
558
 *
559 9351ad55 Leszek Koltunski
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
560 568b29d8 Leszek Koltunski
 * @param axis   Axis of rotation
561 0df17fad Leszek Koltunski
 * @param center Coordinates of the Point we are rotating around.
562 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
563
 */
564 0df17fad Leszek Koltunski
  public long rotate(Data1D angle, Static3D axis, Data3D center )
565 6a06a912 Leszek Koltunski
    {   
566 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angle, axis, center);
567 6a06a912 Leszek Koltunski
    }
568
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570
/**
571 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
572 2fce34f4 Leszek Koltunski
 * Here both angle and axis can dynamically change.
573 568b29d8 Leszek Koltunski
 *
574
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
575 0df17fad Leszek Koltunski
 * @param center    Coordinates of the Point we are rotating around.
576 568b29d8 Leszek Koltunski
 * @return          ID of the effect added, or -1 if we failed to add one.
577 e0a16874 Leszek Koltunski
 */
578 0df17fad Leszek Koltunski
  public long rotate(Data4D angleaxis, Data3D center)
579 568b29d8 Leszek Koltunski
    {
580 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angleaxis, center);
581 6a06a912 Leszek Koltunski
    }
582
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584
/**
585 568b29d8 Leszek Koltunski
 * Rotates the Object by quaternion.
586 0df17fad Leszek Koltunski
 *
587 568b29d8 Leszek Koltunski
 * @param quaternion The quaternion describing the rotation.
588 0df17fad Leszek Koltunski
 * @param center     Coordinates of the Point we are rotating around.
589 568b29d8 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
590 6a06a912 Leszek Koltunski
 */
591 0df17fad Leszek Koltunski
  public long quaternion(Data4D quaternion, Data3D center )
592 568b29d8 Leszek Koltunski
    {
593 0df17fad Leszek Koltunski
    return mM.add(EffectNames.QUATERNION,quaternion,center);
594 6a06a912 Leszek Koltunski
    }
595
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597
/**
598 568b29d8 Leszek Koltunski
 * Shears the Object.
599 6a06a912 Leszek Koltunski
 *
600 8c3cdec5 Leszek Koltunski
 * @param shear   The 3-tuple of shear factors. The first controls level
601
 *                of shearing in the X-axis, second - Y-axis and the third -
602
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
603
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
604 0df17fad Leszek Koltunski
 * @param center  Center of shearing, i.e. the point which stays unmoved.
605 e0a16874 Leszek Koltunski
 * @return        ID of the effect added, or -1 if we failed to add one.
606 6a06a912 Leszek Koltunski
 */
607 0df17fad Leszek Koltunski
  public long shear(Data3D shear, Data3D center)
608 6a06a912 Leszek Koltunski
    {
609 0df17fad Leszek Koltunski
    return mM.add(EffectNames.SHEAR, shear, center);
610 6a06a912 Leszek Koltunski
    }
611
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613
// Fragment-based effects  
614
///////////////////////////////////////////////////////////////////////////////////////////////////
615
/**
616 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
617 6a06a912 Leszek Koltunski
 *        
618 2fce34f4 Leszek Koltunski
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
619 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
620
 *               Valid range: <0,1>
621 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
622 2fce34f4 Leszek Koltunski
 * @param region Region this Effect is limited to.
623
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
624
 * @return       ID of the effect added, or -1 if we failed to add one.
625 6a06a912 Leszek Koltunski
 */
626 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
627 6a06a912 Leszek Koltunski
    {
628 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
629 6a06a912 Leszek Koltunski
    }
630
631
///////////////////////////////////////////////////////////////////////////////////////////////////
632
/**
633 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change all three of its RGB components.
634
 *
635
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
636 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
637
 *               Valid range: <0,1>
638 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
639 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
640 6a06a912 Leszek Koltunski
 */
641 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color)
642 6a06a912 Leszek Koltunski
    {
643 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CHROMA, blend, color);
644 6a06a912 Leszek Koltunski
    }
645
646
///////////////////////////////////////////////////////////////////////////////////////////////////
647
/**
648 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its transparency level.
649 6a06a912 Leszek Koltunski
 *        
650 2fce34f4 Leszek Koltunski
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
651 e4878781 Leszek Koltunski
 *               moment: pixel.a *= alpha.
652
 *               Valid range: <0,1>
653 d7bbef2f Leszek Koltunski
 * @param region Region this Effect is limited to. 
654 2fce34f4 Leszek Koltunski
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
655 d7bbef2f Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one. 
656 6a06a912 Leszek Koltunski
 */
657 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
658 6a06a912 Leszek Koltunski
    {
659 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
660 6a06a912 Leszek Koltunski
    }
661
662
///////////////////////////////////////////////////////////////////////////////////////////////////
663
/**
664 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its transparency level.
665
 *
666
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
667 e4878781 Leszek Koltunski
 *               given moment: pixel.a *= alpha.
668
 *               Valid range: <0,1>
669 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
670 6a06a912 Leszek Koltunski
 */
671 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha)
672 6a06a912 Leszek Koltunski
    {
673 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.ALPHA, alpha);
674 6a06a912 Leszek Koltunski
    }
675
676
///////////////////////////////////////////////////////////////////////////////////////////////////
677
/**
678 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its brightness level.
679 6a06a912 Leszek Koltunski
 *        
680 2fce34f4 Leszek Koltunski
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
681 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
682 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
683 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
684 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
685 6a06a912 Leszek Koltunski
 */
686 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
687 6a06a912 Leszek Koltunski
    {
688 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
689 6a06a912 Leszek Koltunski
    }
690
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692
/**
693 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its brightness level.
694
 *
695
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
696 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
697 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
698 6a06a912 Leszek Koltunski
 */
699 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness)
700 6a06a912 Leszek Koltunski
    {
701 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.BRIGHTNESS, brightness);
702 6a06a912 Leszek Koltunski
    }
703
704
///////////////////////////////////////////////////////////////////////////////////////////////////
705
/**
706 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its contrast level.
707 6a06a912 Leszek Koltunski
 *        
708 2fce34f4 Leszek Koltunski
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
709 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
710 e0a16874 Leszek Koltunski
 * @param region   Region this Effect is limited to.
711 2fce34f4 Leszek Koltunski
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
712 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
713 6a06a912 Leszek Koltunski
 */
714 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
715 6a06a912 Leszek Koltunski
    {
716 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
717 6a06a912 Leszek Koltunski
    }
718
719
///////////////////////////////////////////////////////////////////////////////////////////////////
720
/**
721 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its contrast level.
722
 *
723
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
724 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
725 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
726 6a06a912 Leszek Koltunski
 */
727 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast)
728 6a06a912 Leszek Koltunski
    {
729 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CONTRAST, contrast);
730 6a06a912 Leszek Koltunski
    }
731
732
///////////////////////////////////////////////////////////////////////////////////////////////////
733
/**
734 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its saturation level.
735 6a06a912 Leszek Koltunski
 *        
736 2fce34f4 Leszek Koltunski
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
737 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
738 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
739 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
740 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
741 6a06a912 Leszek Koltunski
 */
742 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
743 6a06a912 Leszek Koltunski
    {
744 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
745 6a06a912 Leszek Koltunski
    }
746
747
///////////////////////////////////////////////////////////////////////////////////////////////////
748
/**
749 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its saturation level.
750
 *
751
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
752 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
753 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
754 6a06a912 Leszek Koltunski
 */
755 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation)
756 6a06a912 Leszek Koltunski
    {
757 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.SATURATION, saturation);
758 6a06a912 Leszek Koltunski
    }
759
760
///////////////////////////////////////////////////////////////////////////////////////////////////
761
// Vertex-based effects  
762
///////////////////////////////////////////////////////////////////////////////////////////////////
763
/**
764 e0a16874 Leszek Koltunski
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
765 f2fe7e28 Leszek Koltunski
 *
766
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
767
 *               currently being dragged with.
768 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
769 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
770
 * @return       ID of the effect added, or -1 if we failed to add one.
771 6a06a912 Leszek Koltunski
 */
772 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center, Data4D region)
773 6a06a912 Leszek Koltunski
    {  
774 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, region);
775 6a06a912 Leszek Koltunski
    }
776
777
///////////////////////////////////////////////////////////////////////////////////////////////////
778
/**
779 e0a16874 Leszek Koltunski
 * Distort the whole Object by a (possibly changing in time) vector of force.
780 f2fe7e28 Leszek Koltunski
 *
781
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
782
 *               currently being dragged with.
783 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
784 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
785 6a06a912 Leszek Koltunski
 */
786 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center)
787 d425545a Leszek Koltunski
    {
788 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, null);
789 d425545a Leszek Koltunski
    }
790 6a06a912 Leszek Koltunski
791 6ebdbbf1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
792
/**
793
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
794
 * a (possibly changing in time) point on the Object.
795
 *
796
 * @param vector Vector of force that deforms the shape of the whole Object.
797
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
798
 * @param region Region that masks the Effect.
799
 * @return       ID of the effect added, or -1 if we failed to add one.
800
 */
801
  public long deform(Data3D vector, Data3D center, Data4D region)
802
    {
803
    return mV.add(EffectNames.DEFORM, vector, center, region);
804
    }
805
806 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
807
/**
808 e0a16874 Leszek Koltunski
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
809 9351ad55 Leszek Koltunski
 * a (possibly changing in time) point on the Object.
810 6a06a912 Leszek Koltunski
 *     
811 f2fe7e28 Leszek Koltunski
 * @param vector Vector of force that deforms the shape of the whole Object.
812 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
813 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
814 6a06a912 Leszek Koltunski
 */
815 fa6c352d Leszek Koltunski
  public long deform(Data3D vector, Data3D center)
816 6a06a912 Leszek Koltunski
    {  
817 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DEFORM, vector, center, null);
818 6a06a912 Leszek Koltunski
    }
819
820
///////////////////////////////////////////////////////////////////////////////////////////////////  
821
/**
822 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
823 6a06a912 Leszek Koltunski
 * away from the center (degree<=1)
824 f2fe7e28 Leszek Koltunski
 *
825
 * @param sink   The current degree of the Effect.
826 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
827 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
828
 * @return       ID of the effect added, or -1 if we failed to add one.
829 6a06a912 Leszek Koltunski
 */
830 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center, Data4D region)
831 6a06a912 Leszek Koltunski
    {
832 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SINK, sink, center, region);
833 6a06a912 Leszek Koltunski
    }
834
835
///////////////////////////////////////////////////////////////////////////////////////////////////
836
/**
837 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
838
 * away from the center (degree<=1)
839
 *
840
 * @param sink   The current degree of the Effect.
841 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
842 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
843 6a06a912 Leszek Koltunski
 */
844 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center)
845 d425545a Leszek Koltunski
    {
846
    return mV.add(EffectNames.SINK, sink, center);
847
    }
848 6a06a912 Leszek Koltunski
849 82ee855a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
850
/**
851
 * Pull all points around the center of the Effect towards a line passing through the center
852
 * (that's if degree>=1) or push them away from the line (degree<=1)
853
 *
854
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
855
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
856
 * @param region Region that masks the Effect.
857
 * @return       ID of the effect added, or -1 if we failed to add one.
858
 */
859
  public long pinch(Data2D pinch, Data3D center, Data4D region)
860
    {
861
    return mV.add(EffectNames.PINCH, pinch, center, region);
862
    }
863
864
///////////////////////////////////////////////////////////////////////////////////////////////////
865
/**
866
 * Pull all points around the center of the Effect towards a line passing through the center
867
 * (that's if degree>=1) or push them away from the line (degree<=1)
868
 *
869
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
870
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
871
 * @return       ID of the effect added, or -1 if we failed to add one.
872
 */
873
  public long pinch(Data2D pinch, Data3D center)
874
    {
875
    return mV.add(EffectNames.PINCH, pinch, center);
876
    }
877
878 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////  
879
/**
880 f2fe7e28 Leszek Koltunski
 * Rotate part of the Object around the Center of the Effect by a certain angle.
881
 *
882 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
883 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
884 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
885
 * @return       ID of the effect added, or -1 if we failed to add one.
886 6a06a912 Leszek Koltunski
 */
887 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center, Data4D region)
888 6a06a912 Leszek Koltunski
    {    
889 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SWIRL, swirl, center, region);
890 6a06a912 Leszek Koltunski
    }
891
892
///////////////////////////////////////////////////////////////////////////////////////////////////
893
/**
894 f2fe7e28 Leszek Koltunski
 * Rotate the whole Object around the Center of the Effect by a certain angle.
895
 *
896 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
897 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
898 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
899 6a06a912 Leszek Koltunski
 */
900 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center)
901 d425545a Leszek Koltunski
    {
902
    return mV.add(EffectNames.SWIRL, swirl, center);
903
    }
904 4fde55a0 Leszek Koltunski
905
///////////////////////////////////////////////////////////////////////////////////////////////////
906
/**
907
 * Directional, sinusoidal wave effect.
908
 *
909 350cc2f5 Leszek Koltunski
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
910 ea16dc89 Leszek Koltunski
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
911 350cc2f5 Leszek Koltunski
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
912
 *               describe the 'direction' of the wave.
913 3695d6fa Leszek Koltunski
 *               <p>
914 d0c902b8 Leszek Koltunski
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
915
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
916
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
917
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
918 3695d6fa Leszek Koltunski
 *               <p>
919
 *               <p>
920 d0c902b8 Leszek Koltunski
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
921
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
922
 *               will be sine shapes.
923 3695d6fa Leszek Koltunski
 *               <p>
924 d0c902b8 Leszek Koltunski
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
925
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
926
 *               YZ-plane with be sine shapes.
927 3695d6fa Leszek Koltunski
 *               <p>
928 d0c902b8 Leszek Koltunski
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
929 350cc2f5 Leszek Koltunski
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
930
 *               value if sin at this point.
931 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
932 4fde55a0 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
933
 */
934 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center)
935 4fde55a0 Leszek Koltunski
    {
936 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.WAVE, wave, center, null);
937 4fde55a0 Leszek Koltunski
    }
938
939
///////////////////////////////////////////////////////////////////////////////////////////////////
940
/**
941
 * Directional, sinusoidal wave effect.
942
 *
943 421c2728 Leszek Koltunski
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
944 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
945 4fde55a0 Leszek Koltunski
 * @param region Region that masks the Effect.
946
 * @return       ID of the effect added, or -1 if we failed to add one.
947
 */
948 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center, Data4D region)
949 4fde55a0 Leszek Koltunski
    {
950
    return mV.add(EffectNames.WAVE, wave, center, region);
951
    }
952 d6e94c84 Leszek Koltunski
953
///////////////////////////////////////////////////////////////////////////////////////////////////
954
// Postprocess-based effects
955
///////////////////////////////////////////////////////////////////////////////////////////////////
956
/**
957
 * Blur the object.
958
 *
959
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
960
 *               take into account 10 pixels in each direction.
961
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
962
 * @return ID of the effect added, or -1 if we failed to add one.
963
 */
964
  public long blur(Data1D radius, Data2D center)
965
    {
966
    return mP.add(EffectNames.BLUR, radius, center);
967
    }
968 f2fe7e28 Leszek Koltunski
  }