1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Distorted is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.library;
|
21
|
|
22
|
import android.content.res.Resources;
|
23
|
import android.opengl.GLES30;
|
24
|
import android.opengl.Matrix;
|
25
|
|
26
|
import org.distorted.library.message.EffectListener;
|
27
|
import org.distorted.library.program.DistortedProgram;
|
28
|
import org.distorted.library.program.FragmentCompilationException;
|
29
|
import org.distorted.library.program.FragmentUniformsException;
|
30
|
import org.distorted.library.program.LinkingException;
|
31
|
import org.distorted.library.program.VertexCompilationException;
|
32
|
import org.distorted.library.program.VertexUniformsException;
|
33
|
import org.distorted.library.type.Data1D;
|
34
|
import org.distorted.library.type.Data2D;
|
35
|
import org.distorted.library.type.Data3D;
|
36
|
import org.distorted.library.type.Data4D;
|
37
|
import org.distorted.library.type.Data5D;
|
38
|
import org.distorted.library.type.Static3D;
|
39
|
|
40
|
import java.io.InputStream;
|
41
|
import java.nio.Buffer;
|
42
|
import java.nio.ByteBuffer;
|
43
|
import java.nio.ByteOrder;
|
44
|
import java.nio.FloatBuffer;
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
/**
|
48
|
* Class containing Matrix,Vertex and Fragment effect queues. Postprocessing queue is held in a separate
|
49
|
* class.
|
50
|
* <p>
|
51
|
* The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
|
52
|
*/
|
53
|
public class DistortedEffects
|
54
|
{
|
55
|
static final int MAIN_PROGRAM = 0;
|
56
|
static final int FEED_PROGRAM = 1;
|
57
|
static final int NUM_PROGRAMS = 2;
|
58
|
|
59
|
// THIS IS FOR MAIN AND FEEDBACK PROGRAMS ///
|
60
|
private static boolean[] mEffectEnabled = new boolean[EffectNames.size()];
|
61
|
|
62
|
static
|
63
|
{
|
64
|
int len = EffectNames.size();
|
65
|
|
66
|
for(int i=0; i<len; i++)
|
67
|
{
|
68
|
mEffectEnabled[i] = false;
|
69
|
}
|
70
|
}
|
71
|
|
72
|
/// MAIN PROGRAM ///
|
73
|
private static DistortedProgram mMainProgram;
|
74
|
private static int mMainTextureH;
|
75
|
|
76
|
/// BLIT PROGRAM ///
|
77
|
private static DistortedProgram mBlitProgram;
|
78
|
private static int mBlitTextureH;
|
79
|
private static int mBlitDepthH;
|
80
|
private static final FloatBuffer mQuadPositions;
|
81
|
|
82
|
static
|
83
|
{
|
84
|
float[] positionData= { -0.5f, -0.5f, -0.5f, 0.5f, 0.5f,-0.5f, 0.5f, 0.5f };
|
85
|
mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
86
|
mQuadPositions.put(positionData).position(0);
|
87
|
}
|
88
|
|
89
|
/// DEBUG PROGRAM /////
|
90
|
private static DistortedProgram mDebugProgram;
|
91
|
|
92
|
private static int mDebugObjDH;
|
93
|
private static int mDebugMVPMatrixH;
|
94
|
|
95
|
/// FEEDBACK PROGRAM //
|
96
|
private static DistortedProgram mFeedbackProgram;
|
97
|
|
98
|
|
99
|
private static float[] mMVPMatrix = new float[16];
|
100
|
private static float[] mTmpMatrix = new float[16];
|
101
|
|
102
|
private static long mNextID =0;
|
103
|
private long mID;
|
104
|
|
105
|
private EffectQueueMatrix mM;
|
106
|
private EffectQueueFragment mF;
|
107
|
private EffectQueueVertex mV;
|
108
|
|
109
|
private boolean matrixCloned, vertexCloned, fragmentCloned;
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
static void createProgram(Resources resources)
|
114
|
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
|
115
|
{
|
116
|
//// BOTH MAIN AND FEEDBACK PROGRAMS ///////
|
117
|
String mainVertHeader= Distorted.GLSL_VERSION;
|
118
|
String mainFragHeader= Distorted.GLSL_VERSION;
|
119
|
|
120
|
EffectNames name;
|
121
|
EffectTypes type;
|
122
|
boolean foundF = false;
|
123
|
boolean foundV = false;
|
124
|
|
125
|
for(int i=0; i<mEffectEnabled.length; i++)
|
126
|
{
|
127
|
if( mEffectEnabled[i] )
|
128
|
{
|
129
|
name = EffectNames.getName(i);
|
130
|
type = EffectNames.getType(i);
|
131
|
|
132
|
if( type == EffectTypes.VERTEX )
|
133
|
{
|
134
|
mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
|
135
|
foundV = true;
|
136
|
}
|
137
|
else if( type == EffectTypes.FRAGMENT )
|
138
|
{
|
139
|
mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
|
140
|
foundF = true;
|
141
|
}
|
142
|
}
|
143
|
}
|
144
|
|
145
|
mainVertHeader += ("#define NUM_VERTEX " + ( foundV ? getMaxVertex() : 0 ) + "\n");
|
146
|
mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
|
147
|
|
148
|
//android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
|
149
|
//android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
|
150
|
|
151
|
//////////////////////////////////////////////////////////////////////////////////////
|
152
|
////////// MAIN PROGRAM //////////////////////////////////////////////////////////////
|
153
|
//////////////////////////////////////////////////////////////////////////////////////
|
154
|
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
|
155
|
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
|
156
|
|
157
|
mMainProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader, Distorted.GLSL);
|
158
|
|
159
|
int mainProgramH = mMainProgram.getProgramHandle();
|
160
|
EffectQueueFragment.getUniforms(mainProgramH);
|
161
|
EffectQueueVertex.getUniforms(MAIN_PROGRAM,mainProgramH);
|
162
|
EffectQueueMatrix.getUniforms(MAIN_PROGRAM,mainProgramH);
|
163
|
mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
|
164
|
|
165
|
//////////////////////////////////////////////////////////////////////////////////////
|
166
|
////////// FEEDBACK PROGRAM //////////////////////////////////////////////////////////
|
167
|
//////////////////////////////////////////////////////////////////////////////////////
|
168
|
final InputStream feedVertStream = resources.openRawResource(R.raw.main_vertex_shader);
|
169
|
final InputStream feedFragStream = resources.openRawResource(R.raw.feedback_fragment_shader);
|
170
|
|
171
|
String[] feedback = { "v_Position" };
|
172
|
|
173
|
mFeedbackProgram = new DistortedProgram(feedVertStream,feedFragStream, mainVertHeader, Distorted.GLSL_VERSION, Distorted.GLSL, feedback);
|
174
|
|
175
|
int feedProgramH = mFeedbackProgram.getProgramHandle();
|
176
|
EffectQueueFragment.getUniforms(feedProgramH);
|
177
|
EffectQueueVertex.getUniforms(FEED_PROGRAM,feedProgramH);
|
178
|
EffectQueueMatrix.getUniforms(FEED_PROGRAM,feedProgramH);
|
179
|
|
180
|
//////////////////////////////////////////////////////////////////////////////////////
|
181
|
////////// BLIT PROGRAM //////////////////////////////////////////////////////////////
|
182
|
//////////////////////////////////////////////////////////////////////////////////////
|
183
|
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
|
184
|
final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
|
185
|
|
186
|
String blitVertHeader= (Distorted.GLSL_VERSION + "#define NUM_VERTEX 0\n" );
|
187
|
String blitFragHeader= (Distorted.GLSL_VERSION + "#define NUM_FRAGMENT 0\n");
|
188
|
|
189
|
try
|
190
|
{
|
191
|
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
|
192
|
}
|
193
|
catch(Exception e)
|
194
|
{
|
195
|
android.util.Log.e("EFFECTS", "exception trying to compile BLIT program: "+e.getMessage());
|
196
|
throw new RuntimeException(e.getMessage());
|
197
|
}
|
198
|
|
199
|
int blitProgramH = mBlitProgram.getProgramHandle();
|
200
|
mBlitTextureH = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
|
201
|
mBlitDepthH = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
|
202
|
|
203
|
//////////////////////////////////////////////////////////////////////////////////////
|
204
|
////////// DEBUG PROGRAM /////////////////////////////////////////////////////////////
|
205
|
//////////////////////////////////////////////////////////////////////////////////////
|
206
|
final InputStream debugVertexStream = resources.openRawResource(R.raw.test_vertex_shader);
|
207
|
final InputStream debugFragmentStream = resources.openRawResource(R.raw.test_fragment_shader);
|
208
|
|
209
|
try
|
210
|
{
|
211
|
mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, Distorted.GLSL_VERSION, Distorted.GLSL_VERSION, Distorted.GLSL);
|
212
|
}
|
213
|
catch(Exception e)
|
214
|
{
|
215
|
android.util.Log.e("EFFECTS", "exception trying to compile DEBUG program: "+e.getMessage());
|
216
|
throw new RuntimeException(e.getMessage());
|
217
|
}
|
218
|
|
219
|
int debugProgramH = mDebugProgram.getProgramHandle();
|
220
|
mDebugObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
|
221
|
mDebugMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
|
222
|
}
|
223
|
|
224
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225
|
|
226
|
private void initializeEffectLists(DistortedEffects d, int flags)
|
227
|
{
|
228
|
if( (flags & Distorted.CLONE_MATRIX) != 0 )
|
229
|
{
|
230
|
mM = d.mM;
|
231
|
matrixCloned = true;
|
232
|
}
|
233
|
else
|
234
|
{
|
235
|
mM = new EffectQueueMatrix(mID);
|
236
|
matrixCloned = false;
|
237
|
}
|
238
|
|
239
|
if( (flags & Distorted.CLONE_VERTEX) != 0 )
|
240
|
{
|
241
|
mV = d.mV;
|
242
|
vertexCloned = true;
|
243
|
}
|
244
|
else
|
245
|
{
|
246
|
mV = new EffectQueueVertex(mID);
|
247
|
vertexCloned = false;
|
248
|
}
|
249
|
|
250
|
if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
|
251
|
{
|
252
|
mF = d.mF;
|
253
|
fragmentCloned = true;
|
254
|
}
|
255
|
else
|
256
|
{
|
257
|
mF = new EffectQueueFragment(mID);
|
258
|
fragmentCloned = false;
|
259
|
}
|
260
|
}
|
261
|
|
262
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
263
|
// DEBUG ONLY
|
264
|
|
265
|
@SuppressWarnings("unused")
|
266
|
private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices, long currTime)
|
267
|
{
|
268
|
int len = vertices.length/3;
|
269
|
int minx = Integer.MAX_VALUE;
|
270
|
int maxx = Integer.MIN_VALUE;
|
271
|
int miny = Integer.MAX_VALUE;
|
272
|
int maxy = Integer.MIN_VALUE;
|
273
|
int wx,wy;
|
274
|
|
275
|
float x,y,z, X,Y,W, ndcX,ndcY;
|
276
|
|
277
|
for(int i=0; i<len; i++)
|
278
|
{
|
279
|
x = 2*halfX*vertices[3*i ];
|
280
|
y = 2*halfY*vertices[3*i+1];
|
281
|
z = 2*halfZ*vertices[3*i+2];
|
282
|
|
283
|
X = mvp[ 0]*x + mvp[ 4]*y + mvp[ 8]*z + mvp[12];
|
284
|
Y = mvp[ 1]*x + mvp[ 5]*y + mvp[ 9]*z + mvp[13];
|
285
|
W = mvp[ 3]*x + mvp[ 7]*y + mvp[11]*z + mvp[15];
|
286
|
|
287
|
ndcX = X/W;
|
288
|
ndcY = Y/W;
|
289
|
|
290
|
wx = (int)(surface.mWidth *(ndcX+1)/2);
|
291
|
wy = (int)(surface.mHeight*(ndcY+1)/2);
|
292
|
|
293
|
if( wx<minx ) minx = wx;
|
294
|
if( wx>maxx ) maxx = wx;
|
295
|
if( wy<miny ) miny = wy;
|
296
|
if( wy>maxy ) maxy = wy;
|
297
|
}
|
298
|
|
299
|
mDebugProgram.useProgram();
|
300
|
surface.setAsOutput(currTime);
|
301
|
|
302
|
Matrix.setIdentityM( mTmpMatrix, 0);
|
303
|
Matrix.translateM ( mTmpMatrix, 0, minx-surface.mWidth/2, maxy-surface.mHeight/2, -surface.mDistance);
|
304
|
Matrix.scaleM ( mTmpMatrix, 0, (float)(maxx-minx)/(2*halfX), (float)(maxy-miny)/(2*halfY), 1.0f);
|
305
|
Matrix.translateM ( mTmpMatrix, 0, halfX,-halfY, 0);
|
306
|
Matrix.multiplyMM ( mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
|
307
|
|
308
|
GLES30.glUniform2f(mDebugObjDH, 2*halfX, 2*halfY);
|
309
|
GLES30.glUniformMatrix4fv(mDebugMVPMatrixH, 1, false, mMVPMatrix , 0);
|
310
|
|
311
|
GLES30.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
312
|
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
313
|
}
|
314
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
315
|
|
316
|
void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
|
317
|
{
|
318
|
mM.compute(currTime);
|
319
|
mV.compute(currTime);
|
320
|
mF.compute(currTime);
|
321
|
|
322
|
float halfZ = halfW*mesh.zFactor;
|
323
|
|
324
|
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
325
|
|
326
|
mMainProgram.useProgram();
|
327
|
GLES30.glUniform1i(mMainTextureH, 0);
|
328
|
surface.setAsOutput(currTime);
|
329
|
mM.send(MAIN_PROGRAM,surface,halfW,halfH,halfZ);
|
330
|
mV.send(MAIN_PROGRAM,halfW,halfH,halfZ);
|
331
|
mF.send(halfW,halfH);
|
332
|
|
333
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mPosVBO[0]);
|
334
|
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
|
335
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mNorVBO[0]);
|
336
|
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, 0);
|
337
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mTexVBO[0]);
|
338
|
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, 0);
|
339
|
|
340
|
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
341
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0 );
|
342
|
}
|
343
|
|
344
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
345
|
|
346
|
void drawPrivFeedback(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
|
347
|
{
|
348
|
mM.compute(currTime);
|
349
|
mV.compute(currTime);
|
350
|
mF.compute(currTime);
|
351
|
|
352
|
float halfZ = halfW*mesh.zFactor;
|
353
|
|
354
|
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
355
|
|
356
|
mFeedbackProgram.useProgram();
|
357
|
surface.setAsOutput(currTime);
|
358
|
mM.send(FEED_PROGRAM,surface,halfW,halfH,halfZ);
|
359
|
mV.send(FEED_PROGRAM,halfW,halfH,halfZ);
|
360
|
|
361
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mPosVBO[0]);
|
362
|
GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[0], MeshObject.POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
|
363
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mNorVBO[0]);
|
364
|
GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[1], MeshObject.NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, 0);
|
365
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mTexVBO[0]);
|
366
|
GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, 0);
|
367
|
|
368
|
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mesh.mPosTBO[0]);
|
369
|
GLES30.glEnable(GLES30.GL_RASTERIZER_DISCARD);
|
370
|
GLES30.glBeginTransformFeedback(GLES30.GL_POINTS);
|
371
|
GLES30.glDrawArrays(GLES30.GL_POINTS, 0, mesh.dataLength);
|
372
|
|
373
|
int error = GLES30.glGetError();
|
374
|
if (error != GLES30.GL_NO_ERROR)
|
375
|
{
|
376
|
throw new RuntimeException("2 glError 0x" + Integer.toHexString(error));
|
377
|
}
|
378
|
|
379
|
GLES30.glEndTransformFeedback();
|
380
|
GLES30.glDisable(GLES30.GL_RASTERIZER_DISCARD);
|
381
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0 );
|
382
|
/*
|
383
|
int len = mesh.dataLength*MeshObject.BYTES_PER_FLOAT*MeshObject.POSITION_DATA_SIZE;
|
384
|
|
385
|
Buffer mappedBuffer = GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, len, GLES30.GL_MAP_READ_BIT);
|
386
|
FloatBuffer fb = ((ByteBuffer) mappedBuffer).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
387
|
FloatBuffer bb = mesh.mMeshPositions;
|
388
|
|
389
|
String msgB = "";
|
390
|
for(int d=0; d<mesh.dataLength; d++)
|
391
|
{
|
392
|
msgB+="("+(2*halfW*bb.get(3*d+0))+","+(2*halfH*bb.get(3*d+1))+","+(2*halfZ*bb.get(3*d+2))+")";
|
393
|
}
|
394
|
android.util.Log.d( "Feedback", msgB);
|
395
|
|
396
|
String msgA = "";
|
397
|
for(int d=0; d<mesh.dataLength; d++)
|
398
|
{
|
399
|
msgA+="("+fb.get(3*d+0)+","+fb.get(3*d+1)+","+fb.get(3*d+2)+")";
|
400
|
}
|
401
|
android.util.Log.d( "Feedback", msgA);
|
402
|
|
403
|
android.util.Log.e( "Feedback",msgA.equalsIgnoreCase(msgB) ? "identical":"not identical");
|
404
|
|
405
|
GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER);
|
406
|
*/
|
407
|
|
408
|
/// DEBUG ONLY //////
|
409
|
// displayBoundingRect(halfW, halfH, halfZ, surface, mM.getMVP(), fb, currTime );
|
410
|
/// END DEBUG ///////
|
411
|
|
412
|
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
|
413
|
|
414
|
|
415
|
|
416
|
|
417
|
mMainProgram.useProgram();
|
418
|
GLES30.glUniform1i(mMainTextureH, 0);
|
419
|
mM.sendFeedback(MAIN_PROGRAM,surface,halfW,halfH,halfZ);
|
420
|
mV.sendZero(MAIN_PROGRAM);
|
421
|
mF.send(halfW,halfH);
|
422
|
|
423
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mPosTBO[0]);
|
424
|
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
|
425
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mNorVBO[0]);
|
426
|
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NORMAL_DATA_SIZE , GLES30.GL_FLOAT, false, 0, 0);
|
427
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mTexVBO[0]);
|
428
|
GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, 0);
|
429
|
|
430
|
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
|
431
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0 );
|
432
|
}
|
433
|
|
434
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
435
|
|
436
|
static void blitPriv(DistortedOutputSurface surface)
|
437
|
{
|
438
|
mBlitProgram.useProgram();
|
439
|
|
440
|
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
441
|
GLES30.glUniform1i(mBlitTextureH, 0);
|
442
|
GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
|
443
|
GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
444
|
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
|
445
|
}
|
446
|
|
447
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
448
|
|
449
|
private void releasePriv()
|
450
|
{
|
451
|
if( !matrixCloned ) mM.abortAll(false);
|
452
|
if( !vertexCloned ) mV.abortAll(false);
|
453
|
if( !fragmentCloned ) mF.abortAll(false);
|
454
|
|
455
|
mM = null;
|
456
|
mV = null;
|
457
|
mF = null;
|
458
|
}
|
459
|
|
460
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
461
|
|
462
|
static void onDestroy()
|
463
|
{
|
464
|
mNextID = 0;
|
465
|
|
466
|
int len = EffectNames.size();
|
467
|
|
468
|
for(int i=0; i<len; i++)
|
469
|
{
|
470
|
mEffectEnabled[i] = false;
|
471
|
}
|
472
|
}
|
473
|
|
474
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
475
|
// PUBLIC API
|
476
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
477
|
/**
|
478
|
* Create empty effect queue.
|
479
|
*/
|
480
|
public DistortedEffects()
|
481
|
{
|
482
|
mID = ++mNextID;
|
483
|
initializeEffectLists(this,0);
|
484
|
}
|
485
|
|
486
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
487
|
/**
|
488
|
* Copy constructor.
|
489
|
* <p>
|
490
|
* Whatever we do not clone gets created just like in the default constructor.
|
491
|
*
|
492
|
* @param dc Source object to create our object from
|
493
|
* @param flags A bitmask of values specifying what to copy.
|
494
|
* For example, CLONE_VERTEX | CLONE_MATRIX.
|
495
|
*/
|
496
|
public DistortedEffects(DistortedEffects dc, int flags)
|
497
|
{
|
498
|
mID = ++mNextID;
|
499
|
initializeEffectLists(dc,flags);
|
500
|
}
|
501
|
|
502
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
503
|
/**
|
504
|
* Releases all resources. After this call, the queue should not be used anymore.
|
505
|
*/
|
506
|
@SuppressWarnings("unused")
|
507
|
public synchronized void delete()
|
508
|
{
|
509
|
releasePriv();
|
510
|
}
|
511
|
|
512
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
513
|
/**
|
514
|
* Returns unique ID of this instance.
|
515
|
*
|
516
|
* @return ID of the object.
|
517
|
*/
|
518
|
public long getID()
|
519
|
{
|
520
|
return mID;
|
521
|
}
|
522
|
|
523
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
524
|
/**
|
525
|
* Adds the calling class to the list of Listeners that get notified each time some event happens
|
526
|
* to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
|
527
|
*
|
528
|
* @param el A class implementing the EffectListener interface that wants to get notifications.
|
529
|
*/
|
530
|
@SuppressWarnings("unused")
|
531
|
public void registerForMessages(EffectListener el)
|
532
|
{
|
533
|
mV.registerForMessages(el);
|
534
|
mF.registerForMessages(el);
|
535
|
mM.registerForMessages(el);
|
536
|
}
|
537
|
|
538
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
539
|
/**
|
540
|
* Removes the calling class from the list of Listeners.
|
541
|
*
|
542
|
* @param el A class implementing the EffectListener interface that no longer wants to get notifications.
|
543
|
*/
|
544
|
@SuppressWarnings("unused")
|
545
|
public void deregisterForMessages(EffectListener el)
|
546
|
{
|
547
|
mV.deregisterForMessages(el);
|
548
|
mF.deregisterForMessages(el);
|
549
|
mM.deregisterForMessages(el);
|
550
|
}
|
551
|
|
552
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
553
|
/**
|
554
|
* Aborts all Effects.
|
555
|
* @return Number of effects aborted.
|
556
|
*/
|
557
|
public int abortAllEffects()
|
558
|
{
|
559
|
return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
|
560
|
}
|
561
|
|
562
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
563
|
/**
|
564
|
* Aborts all Effects of a given type, for example all MATRIX Effects.
|
565
|
*
|
566
|
* @param type one of the constants defined in {@link EffectTypes}
|
567
|
* @return Number of effects aborted.
|
568
|
*/
|
569
|
public int abortEffects(EffectTypes type)
|
570
|
{
|
571
|
switch(type)
|
572
|
{
|
573
|
case MATRIX : return mM.abortAll(true);
|
574
|
case VERTEX : return mV.abortAll(true);
|
575
|
case FRAGMENT : return mF.abortAll(true);
|
576
|
default : return 0;
|
577
|
}
|
578
|
}
|
579
|
|
580
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
581
|
/**
|
582
|
* Aborts a single Effect.
|
583
|
*
|
584
|
* @param id ID of the Effect we want to abort.
|
585
|
* @return number of Effects aborted. Always either 0 or 1.
|
586
|
*/
|
587
|
public int abortEffect(long id)
|
588
|
{
|
589
|
int type = (int)(id&EffectTypes.MASK);
|
590
|
|
591
|
if( type==EffectTypes.MATRIX.type ) return mM.removeByID(id>>EffectTypes.LENGTH);
|
592
|
if( type==EffectTypes.VERTEX.type ) return mV.removeByID(id>>EffectTypes.LENGTH);
|
593
|
if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
|
594
|
|
595
|
return 0;
|
596
|
}
|
597
|
|
598
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
599
|
/**
|
600
|
* Abort all Effects of a given name, for example all rotations.
|
601
|
*
|
602
|
* @param name one of the constants defined in {@link EffectNames}
|
603
|
* @return number of Effects aborted.
|
604
|
*/
|
605
|
public int abortEffects(EffectNames name)
|
606
|
{
|
607
|
switch(name.getType())
|
608
|
{
|
609
|
case MATRIX : return mM.removeByType(name);
|
610
|
case VERTEX : return mV.removeByType(name);
|
611
|
case FRAGMENT : return mF.removeByType(name);
|
612
|
default : return 0;
|
613
|
}
|
614
|
}
|
615
|
|
616
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
617
|
/**
|
618
|
* Print some info about a given Effect to Android's standard out. Used for debugging only.
|
619
|
*
|
620
|
* @param id Effect ID we want to print info about
|
621
|
* @return <code>true</code> if a single Effect of type effectType has been found.
|
622
|
*/
|
623
|
@SuppressWarnings("unused")
|
624
|
public boolean printEffect(long id)
|
625
|
{
|
626
|
int type = (int)(id&EffectTypes.MASK);
|
627
|
|
628
|
if( type==EffectTypes.MATRIX.type ) return mM.printByID(id>>EffectTypes.LENGTH);
|
629
|
if( type==EffectTypes.VERTEX.type ) return mV.printByID(id>>EffectTypes.LENGTH);
|
630
|
if( type==EffectTypes.FRAGMENT.type) return mF.printByID(id>>EffectTypes.LENGTH);
|
631
|
|
632
|
return false;
|
633
|
}
|
634
|
|
635
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
636
|
/**
|
637
|
* Enables a given Effect.
|
638
|
* <p>
|
639
|
* By default, all effects are disabled. One has to explicitly enable each effect one intends to use.
|
640
|
* This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
|
641
|
* The point: by enabling only the effects we need, we can optimize the shaders.
|
642
|
*
|
643
|
* @param name Name of the Effect to enable.
|
644
|
*/
|
645
|
public static void enableEffect(EffectNames name)
|
646
|
{
|
647
|
mEffectEnabled[name.ordinal()] = true;
|
648
|
}
|
649
|
|
650
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
651
|
/**
|
652
|
* Returns the maximum number of Matrix effects.
|
653
|
*
|
654
|
* @return The maximum number of Matrix effects
|
655
|
*/
|
656
|
@SuppressWarnings("unused")
|
657
|
public static int getMaxMatrix()
|
658
|
{
|
659
|
return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
|
660
|
}
|
661
|
|
662
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
663
|
/**
|
664
|
* Returns the maximum number of Vertex effects.
|
665
|
*
|
666
|
* @return The maximum number of Vertex effects
|
667
|
*/
|
668
|
@SuppressWarnings("unused")
|
669
|
public static int getMaxVertex()
|
670
|
{
|
671
|
return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
|
672
|
}
|
673
|
|
674
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
675
|
/**
|
676
|
* Returns the maximum number of Fragment effects.
|
677
|
*
|
678
|
* @return The maximum number of Fragment effects
|
679
|
*/
|
680
|
@SuppressWarnings("unused")
|
681
|
public static int getMaxFragment()
|
682
|
{
|
683
|
return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
|
684
|
}
|
685
|
|
686
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
687
|
/**
|
688
|
* Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
|
689
|
* This can fail if:
|
690
|
* <ul>
|
691
|
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE)
|
692
|
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
|
693
|
* before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
694
|
* time only decreasing the value of 'max' is permitted.
|
695
|
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
|
696
|
* </ul>
|
697
|
*
|
698
|
* @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
|
699
|
* than Byte.MAX_VALUE
|
700
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
701
|
*/
|
702
|
@SuppressWarnings("unused")
|
703
|
public static boolean setMaxMatrix(int max)
|
704
|
{
|
705
|
return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
|
706
|
}
|
707
|
|
708
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
709
|
/**
|
710
|
* Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
|
711
|
* This can fail if:
|
712
|
* <ul>
|
713
|
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE)
|
714
|
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
|
715
|
* before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
716
|
* time only decreasing the value of 'max' is permitted.
|
717
|
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
|
718
|
* </ul>
|
719
|
*
|
720
|
* @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
|
721
|
* than Byte.MAX_VALUE
|
722
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
723
|
*/
|
724
|
@SuppressWarnings("unused")
|
725
|
public static boolean setMaxVertex(int max)
|
726
|
{
|
727
|
return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
|
728
|
}
|
729
|
|
730
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
731
|
/**
|
732
|
* Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
|
733
|
* This can fail if:
|
734
|
* <ul>
|
735
|
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE)
|
736
|
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
|
737
|
* before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
738
|
* time only decreasing the value of 'max' is permitted.
|
739
|
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
|
740
|
* </ul>
|
741
|
*
|
742
|
* @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
|
743
|
* than Byte.MAX_VALUE
|
744
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
745
|
*/
|
746
|
@SuppressWarnings("unused")
|
747
|
public static boolean setMaxFragment(int max)
|
748
|
{
|
749
|
return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
|
750
|
}
|
751
|
|
752
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
753
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
754
|
// Individual effect functions.
|
755
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
756
|
// Matrix-based effects
|
757
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
758
|
/**
|
759
|
* Moves the Object by a (possibly changing in time) vector.
|
760
|
*
|
761
|
* @param vector 3-dimensional Data which at any given time will return a Static3D
|
762
|
* representing the current coordinates of the vector we want to move the Object with.
|
763
|
* @return ID of the effect added, or -1 if we failed to add one.
|
764
|
*/
|
765
|
public long move(Data3D vector)
|
766
|
{
|
767
|
return mM.add(EffectNames.MOVE,vector);
|
768
|
}
|
769
|
|
770
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
771
|
/**
|
772
|
* Scales the Object by (possibly changing in time) 3D scale factors.
|
773
|
*
|
774
|
* @param scale 3-dimensional Data which at any given time returns a Static3D
|
775
|
* representing the current x- , y- and z- scale factors.
|
776
|
* @return ID of the effect added, or -1 if we failed to add one.
|
777
|
*/
|
778
|
public long scale(Data3D scale)
|
779
|
{
|
780
|
return mM.add(EffectNames.SCALE,scale);
|
781
|
}
|
782
|
|
783
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
784
|
/**
|
785
|
* Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
|
786
|
*
|
787
|
* @param scale The factor to scale all 3 dimensions with.
|
788
|
* @return ID of the effect added, or -1 if we failed to add one.
|
789
|
*/
|
790
|
public long scale(float scale)
|
791
|
{
|
792
|
return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
|
793
|
}
|
794
|
|
795
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
796
|
/**
|
797
|
* Rotates the Object by 'angle' degrees around the center.
|
798
|
* Static axis of rotation is given by the last parameter.
|
799
|
*
|
800
|
* @param angle Angle that we want to rotate the Object to. Unit: degrees
|
801
|
* @param axis Axis of rotation
|
802
|
* @param center Coordinates of the Point we are rotating around.
|
803
|
* @return ID of the effect added, or -1 if we failed to add one.
|
804
|
*/
|
805
|
public long rotate(Data1D angle, Static3D axis, Data3D center )
|
806
|
{
|
807
|
return mM.add(EffectNames.ROTATE, angle, axis, center);
|
808
|
}
|
809
|
|
810
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
811
|
/**
|
812
|
* Rotates the Object by 'angle' degrees around the center.
|
813
|
* Here both angle and axis can dynamically change.
|
814
|
*
|
815
|
* @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
|
816
|
* @param center Coordinates of the Point we are rotating around.
|
817
|
* @return ID of the effect added, or -1 if we failed to add one.
|
818
|
*/
|
819
|
public long rotate(Data4D angleaxis, Data3D center)
|
820
|
{
|
821
|
return mM.add(EffectNames.ROTATE, angleaxis, center);
|
822
|
}
|
823
|
|
824
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
825
|
/**
|
826
|
* Rotates the Object by quaternion.
|
827
|
*
|
828
|
* @param quaternion The quaternion describing the rotation.
|
829
|
* @param center Coordinates of the Point we are rotating around.
|
830
|
* @return ID of the effect added, or -1 if we failed to add one.
|
831
|
*/
|
832
|
public long quaternion(Data4D quaternion, Data3D center )
|
833
|
{
|
834
|
return mM.add(EffectNames.QUATERNION,quaternion,center);
|
835
|
}
|
836
|
|
837
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
838
|
/**
|
839
|
* Shears the Object.
|
840
|
*
|
841
|
* @param shear The 3-tuple of shear factors. The first controls level
|
842
|
* of shearing in the X-axis, second - Y-axis and the third -
|
843
|
* Z-axis. Each is the tangens of the shear angle, i.e 0 -
|
844
|
* no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
|
845
|
* @param center Center of shearing, i.e. the point which stays unmoved.
|
846
|
* @return ID of the effect added, or -1 if we failed to add one.
|
847
|
*/
|
848
|
public long shear(Data3D shear, Data3D center)
|
849
|
{
|
850
|
return mM.add(EffectNames.SHEAR, shear, center);
|
851
|
}
|
852
|
|
853
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
854
|
// Fragment-based effects
|
855
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
856
|
/**
|
857
|
* Makes a certain sub-region of the Object smoothly change all three of its RGB components.
|
858
|
*
|
859
|
* @param blend 1-dimensional Data that returns the level of blend a given pixel will be
|
860
|
* mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
|
861
|
* Valid range: <0,1>
|
862
|
* @param color Color to mix. (1,0,0) is RED.
|
863
|
* @param region Region this Effect is limited to.
|
864
|
* @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
|
865
|
* @return ID of the effect added, or -1 if we failed to add one.
|
866
|
*/
|
867
|
public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
|
868
|
{
|
869
|
return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
|
870
|
}
|
871
|
|
872
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
873
|
/**
|
874
|
* Makes the whole Object smoothly change all three of its RGB components.
|
875
|
*
|
876
|
* @param blend 1-dimensional Data that returns the level of blend a given pixel will be
|
877
|
* mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
|
878
|
* Valid range: <0,1>
|
879
|
* @param color Color to mix. (1,0,0) is RED.
|
880
|
* @return ID of the effect added, or -1 if we failed to add one.
|
881
|
*/
|
882
|
public long chroma(Data1D blend, Data3D color)
|
883
|
{
|
884
|
return mF.add(EffectNames.CHROMA, blend, color);
|
885
|
}
|
886
|
|
887
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
888
|
/**
|
889
|
* Makes a certain sub-region of the Object smoothly change its transparency level.
|
890
|
*
|
891
|
* @param alpha 1-dimensional Data that returns the level of transparency we want to have at any given
|
892
|
* moment: pixel.a *= alpha.
|
893
|
* Valid range: <0,1>
|
894
|
* @param region Region this Effect is limited to.
|
895
|
* @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
|
896
|
* @return ID of the effect added, or -1 if we failed to add one.
|
897
|
*/
|
898
|
public long alpha(Data1D alpha, Data4D region, boolean smooth)
|
899
|
{
|
900
|
return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
|
901
|
}
|
902
|
|
903
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
904
|
/**
|
905
|
* Makes the whole Object smoothly change its transparency level.
|
906
|
*
|
907
|
* @param alpha 1-dimensional Data that returns the level of transparency we want to have at any
|
908
|
* given moment: pixel.a *= alpha.
|
909
|
* Valid range: <0,1>
|
910
|
* @return ID of the effect added, or -1 if we failed to add one.
|
911
|
*/
|
912
|
public long alpha(Data1D alpha)
|
913
|
{
|
914
|
return mF.add(EffectNames.ALPHA, alpha);
|
915
|
}
|
916
|
|
917
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
918
|
/**
|
919
|
* Makes a certain sub-region of the Object smoothly change its brightness level.
|
920
|
*
|
921
|
* @param brightness 1-dimensional Data that returns the level of brightness we want to have
|
922
|
* at any given moment. Valid range: <0,infinity)
|
923
|
* @param region Region this Effect is limited to.
|
924
|
* @param smooth If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
|
925
|
* @return ID of the effect added, or -1 if we failed to add one.
|
926
|
*/
|
927
|
public long brightness(Data1D brightness, Data4D region, boolean smooth)
|
928
|
{
|
929
|
return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
|
930
|
}
|
931
|
|
932
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
933
|
/**
|
934
|
* Makes the whole Object smoothly change its brightness level.
|
935
|
*
|
936
|
* @param brightness 1-dimensional Data that returns the level of brightness we want to have
|
937
|
* at any given moment. Valid range: <0,infinity)
|
938
|
* @return ID of the effect added, or -1 if we failed to add one.
|
939
|
*/
|
940
|
public long brightness(Data1D brightness)
|
941
|
{
|
942
|
return mF.add(EffectNames.BRIGHTNESS, brightness);
|
943
|
}
|
944
|
|
945
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
946
|
/**
|
947
|
* Makes a certain sub-region of the Object smoothly change its contrast level.
|
948
|
*
|
949
|
* @param contrast 1-dimensional Data that returns the level of contrast we want to have
|
950
|
* at any given moment. Valid range: <0,infinity)
|
951
|
* @param region Region this Effect is limited to.
|
952
|
* @param smooth If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
|
953
|
* @return ID of the effect added, or -1 if we failed to add one.
|
954
|
*/
|
955
|
public long contrast(Data1D contrast, Data4D region, boolean smooth)
|
956
|
{
|
957
|
return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
|
958
|
}
|
959
|
|
960
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
961
|
/**
|
962
|
* Makes the whole Object smoothly change its contrast level.
|
963
|
*
|
964
|
* @param contrast 1-dimensional Data that returns the level of contrast we want to have
|
965
|
* at any given moment. Valid range: <0,infinity)
|
966
|
* @return ID of the effect added, or -1 if we failed to add one.
|
967
|
*/
|
968
|
public long contrast(Data1D contrast)
|
969
|
{
|
970
|
return mF.add(EffectNames.CONTRAST, contrast);
|
971
|
}
|
972
|
|
973
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
974
|
/**
|
975
|
* Makes a certain sub-region of the Object smoothly change its saturation level.
|
976
|
*
|
977
|
* @param saturation 1-dimensional Data that returns the level of saturation we want to have
|
978
|
* at any given moment. Valid range: <0,infinity)
|
979
|
* @param region Region this Effect is limited to.
|
980
|
* @param smooth If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
|
981
|
* @return ID of the effect added, or -1 if we failed to add one.
|
982
|
*/
|
983
|
public long saturation(Data1D saturation, Data4D region, boolean smooth)
|
984
|
{
|
985
|
return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
|
986
|
}
|
987
|
|
988
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
989
|
/**
|
990
|
* Makes the whole Object smoothly change its saturation level.
|
991
|
*
|
992
|
* @param saturation 1-dimensional Data that returns the level of saturation we want to have
|
993
|
* at any given moment. Valid range: <0,infinity)
|
994
|
* @return ID of the effect added, or -1 if we failed to add one.
|
995
|
*/
|
996
|
public long saturation(Data1D saturation)
|
997
|
{
|
998
|
return mF.add(EffectNames.SATURATION, saturation);
|
999
|
}
|
1000
|
|
1001
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1002
|
// Vertex-based effects
|
1003
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1004
|
/**
|
1005
|
* Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
|
1006
|
*
|
1007
|
* @param vector 3-dimensional Vector which represents the force the Center of the Effect is
|
1008
|
* currently being dragged with.
|
1009
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1010
|
* @param region Region that masks the Effect.
|
1011
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1012
|
*/
|
1013
|
public long distort(Data3D vector, Data3D center, Data4D region)
|
1014
|
{
|
1015
|
return mV.add(EffectNames.DISTORT, vector, center, region);
|
1016
|
}
|
1017
|
|
1018
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1019
|
/**
|
1020
|
* Distort the whole Object by a (possibly changing in time) vector of force.
|
1021
|
*
|
1022
|
* @param vector 3-dimensional Vector which represents the force the Center of the Effect is
|
1023
|
* currently being dragged with.
|
1024
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1025
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1026
|
*/
|
1027
|
public long distort(Data3D vector, Data3D center)
|
1028
|
{
|
1029
|
return mV.add(EffectNames.DISTORT, vector, center, null);
|
1030
|
}
|
1031
|
|
1032
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1033
|
/**
|
1034
|
* Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
|
1035
|
* a (possibly changing in time) point on the Object.
|
1036
|
*
|
1037
|
* @param vector Vector of force that deforms the shape of the whole Object.
|
1038
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1039
|
* @param region Region that masks the Effect.
|
1040
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1041
|
*/
|
1042
|
public long deform(Data3D vector, Data3D center, Data4D region)
|
1043
|
{
|
1044
|
return mV.add(EffectNames.DEFORM, vector, center, region);
|
1045
|
}
|
1046
|
|
1047
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1048
|
/**
|
1049
|
* Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
|
1050
|
* a (possibly changing in time) point on the Object.
|
1051
|
*
|
1052
|
* @param vector Vector of force that deforms the shape of the whole Object.
|
1053
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1054
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1055
|
*/
|
1056
|
public long deform(Data3D vector, Data3D center)
|
1057
|
{
|
1058
|
return mV.add(EffectNames.DEFORM, vector, center, null);
|
1059
|
}
|
1060
|
|
1061
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1062
|
/**
|
1063
|
* Pull all points around the center of the Effect towards the center (if degree>=1) or push them
|
1064
|
* away from the center (degree<=1)
|
1065
|
*
|
1066
|
* @param sink The current degree of the Effect.
|
1067
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1068
|
* @param region Region that masks the Effect.
|
1069
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1070
|
*/
|
1071
|
public long sink(Data1D sink, Data3D center, Data4D region)
|
1072
|
{
|
1073
|
return mV.add(EffectNames.SINK, sink, center, region);
|
1074
|
}
|
1075
|
|
1076
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1077
|
/**
|
1078
|
* Pull all points around the center of the Effect towards the center (if degree>=1) or push them
|
1079
|
* away from the center (degree<=1)
|
1080
|
*
|
1081
|
* @param sink The current degree of the Effect.
|
1082
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1083
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1084
|
*/
|
1085
|
public long sink(Data1D sink, Data3D center)
|
1086
|
{
|
1087
|
return mV.add(EffectNames.SINK, sink, center);
|
1088
|
}
|
1089
|
|
1090
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1091
|
/**
|
1092
|
* Pull all points around the center of the Effect towards a line passing through the center
|
1093
|
* (that's if degree>=1) or push them away from the line (degree<=1)
|
1094
|
*
|
1095
|
* @param pinch The current degree of the Effect + angle the line forms with X-axis
|
1096
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1097
|
* @param region Region that masks the Effect.
|
1098
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1099
|
*/
|
1100
|
public long pinch(Data2D pinch, Data3D center, Data4D region)
|
1101
|
{
|
1102
|
return mV.add(EffectNames.PINCH, pinch, center, region);
|
1103
|
}
|
1104
|
|
1105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1106
|
/**
|
1107
|
* Pull all points around the center of the Effect towards a line passing through the center
|
1108
|
* (that's if degree>=1) or push them away from the line (degree<=1)
|
1109
|
*
|
1110
|
* @param pinch The current degree of the Effect + angle the line forms with X-axis
|
1111
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1112
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1113
|
*/
|
1114
|
public long pinch(Data2D pinch, Data3D center)
|
1115
|
{
|
1116
|
return mV.add(EffectNames.PINCH, pinch, center);
|
1117
|
}
|
1118
|
|
1119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1120
|
/**
|
1121
|
* Rotate part of the Object around the Center of the Effect by a certain angle.
|
1122
|
*
|
1123
|
* @param swirl The angle of Swirl (in degrees). Positive values swirl clockwise.
|
1124
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1125
|
* @param region Region that masks the Effect.
|
1126
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1127
|
*/
|
1128
|
public long swirl(Data1D swirl, Data3D center, Data4D region)
|
1129
|
{
|
1130
|
return mV.add(EffectNames.SWIRL, swirl, center, region);
|
1131
|
}
|
1132
|
|
1133
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1134
|
/**
|
1135
|
* Rotate the whole Object around the Center of the Effect by a certain angle.
|
1136
|
*
|
1137
|
* @param swirl The angle of Swirl (in degrees). Positive values swirl clockwise.
|
1138
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1139
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1140
|
*/
|
1141
|
public long swirl(Data1D swirl, Data3D center)
|
1142
|
{
|
1143
|
return mV.add(EffectNames.SWIRL, swirl, center);
|
1144
|
}
|
1145
|
|
1146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1147
|
/**
|
1148
|
* Directional, sinusoidal wave effect.
|
1149
|
*
|
1150
|
* @param wave A 5-dimensional data structure describing the wave: first member is the amplitude,
|
1151
|
* second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
|
1152
|
* wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
|
1153
|
* describe the 'direction' of the wave.
|
1154
|
* <p>
|
1155
|
* Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
|
1156
|
* need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
|
1157
|
* forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
|
1158
|
* the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
|
1159
|
* <p>
|
1160
|
* <p>
|
1161
|
* Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
|
1162
|
* in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
|
1163
|
* will be sine shapes.
|
1164
|
* <p>
|
1165
|
* Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
|
1166
|
* but this time it waves in the Y-direction, i.e. cross sections of the surface and the
|
1167
|
* YZ-plane with be sine shapes.
|
1168
|
* <p>
|
1169
|
* Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
|
1170
|
* is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
|
1171
|
* value if sin at this point.
|
1172
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1173
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1174
|
*/
|
1175
|
public long wave(Data5D wave, Data3D center)
|
1176
|
{
|
1177
|
return mV.add(EffectNames.WAVE, wave, center, null);
|
1178
|
}
|
1179
|
|
1180
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1181
|
/**
|
1182
|
* Directional, sinusoidal wave effect.
|
1183
|
*
|
1184
|
* @param wave see {@link DistortedEffects#wave(Data5D,Data3D)}
|
1185
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
1186
|
* @param region Region that masks the Effect.
|
1187
|
* @return ID of the effect added, or -1 if we failed to add one.
|
1188
|
*/
|
1189
|
public long wave(Data5D wave, Data3D center, Data4D region)
|
1190
|
{
|
1191
|
return mV.add(EffectNames.WAVE, wave, center, region);
|
1192
|
}
|
1193
|
}
|