Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 47d838ca

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