Revision 96e3b88a
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/library/effect/Effect.java | ||
---|---|---|
142 | 142 |
* |
143 | 143 |
* @y.exclude |
144 | 144 |
*/ |
145 |
public int getAndAssociation()
|
|
145 |
public void writeAssociations(int[] intUniforms, int index1, int index2)
|
|
146 | 146 |
{ |
147 |
return mAndAssociation; |
|
148 |
} |
|
149 |
|
|
150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
151 |
/** |
|
152 |
* Only for use by the library itself. |
|
153 |
* |
|
154 |
* @y.exclude |
|
155 |
*/ |
|
156 |
public int getEquAssociation() |
|
157 |
{ |
|
158 |
return mEquAssociation; |
|
147 |
intUniforms[index1] = mAndAssociation; |
|
148 |
intUniforms[index2] = mEquAssociation; |
|
159 | 149 |
} |
160 | 150 |
|
161 | 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/effect/FragmentEffect.java | ||
---|---|---|
27 | 27 |
*/ |
28 | 28 |
public abstract class FragmentEffect extends Effect |
29 | 29 |
{ |
30 |
/** |
|
31 |
* 12: 4-per effect interpolated values, 3 dimensional Center (+padding), 3 dimensional Region (+padding). |
|
32 |
*/ |
|
33 |
public static final int NUM_UNIFORMS = 12; |
|
30 |
/** |
|
31 |
* 12: 4-per effect interpolated values, 3 dimensional Center (+padding), 3 dimensional Region (+padding). |
|
32 |
*/ |
|
33 |
public static final int NUM_FLOAT_UNIFORMS = 12; |
|
34 |
/** |
|
35 |
* 1: the name |
|
36 |
*/ |
|
37 |
public static final int NUM_INT_UNIFORMS = 1; |
|
38 |
|
|
34 | 39 |
static final int VALUES_OFFSET = 0; |
35 | 40 |
static final int CENTER_OFFSET = 5; |
36 | 41 |
static final int REGION_OFFSET = 8; |
src/main/java/org/distorted/library/effect/MatrixEffect.java | ||
---|---|---|
25 | 25 |
*/ |
26 | 26 |
public abstract class MatrixEffect extends Effect |
27 | 27 |
{ |
28 |
/** |
|
29 |
* 7: 4 per-effect interpolated values + 3 dimensional center. |
|
30 |
*/ |
|
31 |
public static final int NUM_UNIFORMS = 7; |
|
28 |
/** |
|
29 |
* 7: 4 per-effect interpolated values + 3 dimensional center. |
|
30 |
*/ |
|
31 |
public static final int NUM_FLOAT_UNIFORMS = 7; |
|
32 |
/** |
|
33 |
* 0: nothing |
|
34 |
*/ |
|
35 |
public static final int NUM_INT_UNIFORMS = 1; |
|
36 |
|
|
32 | 37 |
static final int CENTER_OFFSET = 4; |
33 | 38 |
|
34 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/effect/MatrixEffectMove.java | ||
---|---|---|
50 | 50 |
*/ |
51 | 51 |
public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index) |
52 | 52 |
{ |
53 |
float sx = uniforms[NUM_UNIFORMS*index ]; |
|
54 |
float sy = uniforms[NUM_UNIFORMS*index+1]; |
|
55 |
float sz = uniforms[NUM_UNIFORMS*index+2]; |
|
53 |
float sx = uniforms[NUM_FLOAT_UNIFORMS*index ];
|
|
54 |
float sy = uniforms[NUM_FLOAT_UNIFORMS*index+1];
|
|
55 |
float sz = uniforms[NUM_FLOAT_UNIFORMS*index+2];
|
|
56 | 56 |
|
57 | 57 |
Matrix.translateM(matrixP, 0, sx, sy, sz); |
58 | 58 |
Matrix.translateM(matrixV, 0, sx, sy, sz); |
src/main/java/org/distorted/library/effect/MatrixEffectQuaternion.java | ||
---|---|---|
56 | 56 |
*/ |
57 | 57 |
public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index) |
58 | 58 |
{ |
59 |
float qX = uniforms[NUM_UNIFORMS*index ]; |
|
60 |
float qY = uniforms[NUM_UNIFORMS*index+1]; |
|
61 |
float qZ = uniforms[NUM_UNIFORMS*index+2]; |
|
62 |
float qW = uniforms[NUM_UNIFORMS*index+3]; |
|
63 |
|
|
64 |
float x = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET ]; |
|
65 |
float y = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1]; |
|
66 |
float z = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2]; |
|
59 |
float qX = uniforms[NUM_FLOAT_UNIFORMS*index ];
|
|
60 |
float qY = uniforms[NUM_FLOAT_UNIFORMS*index+1];
|
|
61 |
float qZ = uniforms[NUM_FLOAT_UNIFORMS*index+2];
|
|
62 |
float qW = uniforms[NUM_FLOAT_UNIFORMS*index+3];
|
|
63 |
|
|
64 |
float x = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET ];
|
|
65 |
float y = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+1];
|
|
66 |
float z = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+2];
|
|
67 | 67 |
|
68 | 68 |
Matrix.translateM(matrixP, 0, x, y, z); |
69 | 69 |
multiplyByQuat (matrixP, qX, qY, qZ, qW); |
src/main/java/org/distorted/library/effect/MatrixEffectRotate.java | ||
---|---|---|
54 | 54 |
*/ |
55 | 55 |
public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index) |
56 | 56 |
{ |
57 |
float angle = uniforms[NUM_UNIFORMS*index ]; |
|
58 |
float axisX = uniforms[NUM_UNIFORMS*index+1]; |
|
59 |
float axisY = uniforms[NUM_UNIFORMS*index+2]; |
|
60 |
float axisZ = uniforms[NUM_UNIFORMS*index+3]; |
|
57 |
float angle = uniforms[NUM_FLOAT_UNIFORMS*index ];
|
|
58 |
float axisX = uniforms[NUM_FLOAT_UNIFORMS*index+1];
|
|
59 |
float axisY = uniforms[NUM_FLOAT_UNIFORMS*index+2];
|
|
60 |
float axisZ = uniforms[NUM_FLOAT_UNIFORMS*index+3];
|
|
61 | 61 |
|
62 |
float x = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET ]; |
|
63 |
float y = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1]; |
|
64 |
float z = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2]; |
|
62 |
float x = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET ];
|
|
63 |
float y = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+1];
|
|
64 |
float z = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+2];
|
|
65 | 65 |
|
66 | 66 |
Matrix.translateM(matrixP, 0, x, y, z); |
67 | 67 |
Matrix.rotateM (matrixP, 0, angle, axisX, axisY, axisZ); |
src/main/java/org/distorted/library/effect/MatrixEffectScale.java | ||
---|---|---|
57 | 57 |
*/ |
58 | 58 |
public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index) |
59 | 59 |
{ |
60 |
float sx = uniforms[NUM_UNIFORMS*index ]; |
|
61 |
float sy = uniforms[NUM_UNIFORMS*index+1]; |
|
62 |
float sz = uniforms[NUM_UNIFORMS*index+2]; |
|
60 |
float sx = uniforms[NUM_FLOAT_UNIFORMS*index ];
|
|
61 |
float sy = uniforms[NUM_FLOAT_UNIFORMS*index+1];
|
|
62 |
float sz = uniforms[NUM_FLOAT_UNIFORMS*index+2];
|
|
63 | 63 |
|
64 | 64 |
Matrix.scaleM(matrixP, 0, sx, sy, sz); |
65 | 65 |
Matrix.scaleM(matrixV, 0, sy*sz, sx*sz, sx*sy); |
src/main/java/org/distorted/library/effect/MatrixEffectShear.java | ||
---|---|---|
54 | 54 |
*/ |
55 | 55 |
public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index) |
56 | 56 |
{ |
57 |
float sx = uniforms[NUM_UNIFORMS*index ]; |
|
58 |
float sy = uniforms[NUM_UNIFORMS*index+1]; |
|
59 |
float sz = uniforms[NUM_UNIFORMS*index+2]; |
|
57 |
float sx = uniforms[NUM_FLOAT_UNIFORMS*index ];
|
|
58 |
float sy = uniforms[NUM_FLOAT_UNIFORMS*index+1];
|
|
59 |
float sz = uniforms[NUM_FLOAT_UNIFORMS*index+2];
|
|
60 | 60 |
|
61 |
float x = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET ]; |
|
62 |
float y = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1]; |
|
63 |
float z = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2]; |
|
61 |
float x = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET ];
|
|
62 |
float y = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+1];
|
|
63 |
float z = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+2];
|
|
64 | 64 |
|
65 | 65 |
Matrix.translateM(matrixP, 0, x, y, z); |
66 | 66 |
|
src/main/java/org/distorted/library/effect/PostprocessEffect.java | ||
---|---|---|
36 | 36 |
public abstract class PostprocessEffect extends Effect implements InternalMaster.Slave |
37 | 37 |
{ |
38 | 38 |
private static final int MIPMAP = 0; |
39 |
/** |
|
40 |
* 5: 5 per-effect interpolated values. |
|
41 |
*/ |
|
42 |
public static final int NUM_UNIFORMS = 6; |
|
39 |
/** |
|
40 |
* 5 per-effect interpolated values. |
|
41 |
*/ |
|
42 |
public static final int NUM_FLOAT_UNIFORMS = 6; |
|
43 |
/** |
|
44 |
* 1: the name of the effect |
|
45 |
*/ |
|
46 |
public static final int NUM_INT_UNIFORMS = 1; |
|
43 | 47 |
|
44 | 48 |
static final int POS_DATA_SIZE= 2; |
45 | 49 |
static final int TEX_DATA_SIZE= 2; |
src/main/java/org/distorted/library/effect/VertexEffect.java | ||
---|---|---|
29 | 29 |
*/ |
30 | 30 |
public abstract class VertexEffect extends Effect |
31 | 31 |
{ |
32 |
/** |
|
33 |
* 12: 5 per-effect interpolated values, 3-dimensional center, 4-dimensional Region |
|
34 |
*/ |
|
35 |
public static final int NUM_UNIFORMS = 12; |
|
32 |
/** |
|
33 |
* 12: 5 per-effect interpolated values, 3-dimensional center, 4-dimensional Region |
|
34 |
*/ |
|
35 |
public static final int NUM_FLOAT_UNIFORMS = 12; |
|
36 |
/** |
|
37 |
* 3: name, AND association, equ Association |
|
38 |
*/ |
|
39 |
public static final int NUM_INT_UNIFORMS = 3; |
|
40 |
|
|
36 | 41 |
static final int VALUES_OFFSET = 0; |
37 | 42 |
static final int CENTER_OFFSET = 5; |
38 | 43 |
static final int REGION_OFFSET = 8; |
src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
---|---|---|
24 | 24 |
import org.distorted.library.effect.EffectType; |
25 | 25 |
import org.distorted.library.main.DistortedLibrary; |
26 | 26 |
import org.distorted.library.main.InternalMaster; |
27 |
import org.distorted.library.mesh.MeshBase; |
|
28 | 27 |
|
29 | 28 |
import java.util.ArrayList; |
30 | 29 |
import java.util.HashMap; |
... | ... | |
44 | 43 |
private static final int DETACH = 2; |
45 | 44 |
private static final int DETALL = 3; |
46 | 45 |
|
46 |
long mTime; |
|
47 | 47 |
int mNumEffects; // 'ToBe' will be more than mNumEffects if doWork() hasn't |
48 | 48 |
private int mNumEffectsToBe; // added them yet (or less if it hasn't removed some yet) |
49 |
float[] mUniforms; |
|
50 |
private int mNumUniforms; |
|
49 |
private int mNumFloatUniforms, mNumIntUniforms; |
|
51 | 50 |
Effect[] mEffects; |
52 |
int[] mName; |
|
53 |
int[] mAndAssociation; |
|
54 |
int[] mEquAssociation; |
|
55 |
long mTime; |
|
56 | 51 |
|
57 |
private static int[] mMax = new int[EffectType.LENGTH]; |
|
52 |
float[] mFloatUniforms; |
|
53 |
int[] mIntUniforms; |
|
54 |
|
|
55 |
static int[] mMax = new int[EffectType.LENGTH]; |
|
58 | 56 |
private static long mNextID; |
59 | 57 |
private static HashMap<ArrayList<Long>,Long> mMapID = new HashMap<>(); // maps lists of Effect IDs (longs) to a |
60 | 58 |
// single long - the queue ID. |
... | ... | |
65 | 63 |
private static class Job |
66 | 64 |
{ |
67 | 65 |
int type; |
68 |
int num; |
|
66 |
int num1, num2;
|
|
69 | 67 |
boolean notify; |
70 | 68 |
Effect effect; |
71 | 69 |
|
72 |
Job(int t, int m, boolean n, Effect e) |
|
70 |
Job(int t, int m1, int m2, boolean n, Effect e)
|
|
73 | 71 |
{ |
74 | 72 |
type = t; |
75 |
num = m; |
|
73 |
num1 = m1; |
|
74 |
num2 = m2; |
|
76 | 75 |
notify= n; |
77 | 76 |
effect= e; |
78 | 77 |
} |
... | ... | |
87 | 86 |
|
88 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
89 | 88 |
|
90 |
EffectQueue(int numUniforms, int index) |
|
89 |
EffectQueue(int numFloatUniforms, int numIntUniforms, int index)
|
|
91 | 90 |
{ |
92 |
mCreated = false; |
|
93 |
mTime = 0; |
|
94 |
mID = 0; |
|
95 |
mNumEffects = 0; |
|
96 |
mNumEffectsToBe = 0; |
|
97 |
mIndex = index; |
|
98 |
mNumUniforms = numUniforms; |
|
99 |
|
|
100 |
mJobs.add(new Job(CREATE,numUniforms,false,null)); // create the stuff that depends on max number |
|
101 |
InternalMaster.newSlave(this); // of uniforms later, on first render. |
|
91 |
mCreated = false; |
|
92 |
mTime = 0; |
|
93 |
mID = 0; |
|
94 |
mNumEffects = 0; |
|
95 |
mNumEffectsToBe = 0; |
|
96 |
mIndex = index; |
|
97 |
mNumFloatUniforms = numFloatUniforms; |
|
98 |
mNumIntUniforms = numIntUniforms; |
|
99 |
|
|
100 |
mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms, false,null)); // create the stuff that depends on max number |
|
101 |
InternalMaster.newSlave(this); // of uniforms later, on first render. |
|
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
108 | 108 |
{ |
109 | 109 |
if( !source.mCreated ) |
110 | 110 |
{ |
111 |
mCreated = false; |
|
112 |
mTime = 0; |
|
113 |
mID = 0; |
|
114 |
mNumEffects = 0; |
|
115 |
mNumEffectsToBe = 0; |
|
116 |
mIndex = source.mIndex; |
|
117 |
mNumUniforms = source.mNumUniforms; |
|
111 |
mCreated = false; |
|
112 |
mTime = 0; |
|
113 |
mID = 0; |
|
114 |
mNumEffects = 0; |
|
115 |
mNumEffectsToBe = 0; |
|
116 |
mIndex = source.mIndex; |
|
117 |
mNumFloatUniforms = source.mNumFloatUniforms; |
|
118 |
mNumIntUniforms = source.mNumIntUniforms; |
|
118 | 119 |
|
119 | 120 |
int numJobs = source.mJobs.size(); |
120 | 121 |
|
... | ... | |
128 | 129 |
} |
129 | 130 |
else |
130 | 131 |
{ |
131 |
mCreated = true; |
|
132 |
mTime = source.mTime; |
|
133 |
mID = source.mID; |
|
134 |
mNumEffects = source.mNumEffects; |
|
135 |
mNumEffectsToBe = source.mNumEffectsToBe; |
|
136 |
mIndex = source.mIndex; |
|
137 |
mNumUniforms = source.mNumUniforms; |
|
132 |
mCreated = true; |
|
133 |
mTime = source.mTime; |
|
134 |
mID = source.mID; |
|
135 |
mNumEffects = source.mNumEffects; |
|
136 |
mNumEffectsToBe = source.mNumEffectsToBe; |
|
137 |
mIndex = source.mIndex; |
|
138 |
mNumFloatUniforms = source.mNumFloatUniforms; |
|
139 |
mNumIntUniforms = source.mNumIntUniforms; |
|
138 | 140 |
|
139 | 141 |
int max = mMax[mIndex]; |
140 |
if( max>0 ) |
|
141 |
{ |
|
142 |
mUniforms = new float[max*source.mNumUniforms]; |
|
143 |
mEffects = new Effect[max]; |
|
144 |
mName = new int[max]; |
|
145 |
mAndAssociation = new int[max]; |
|
146 |
mEquAssociation = new int[max]; |
|
147 |
} |
|
148 | 142 |
|
149 |
for(int i=0; i<mNumEffects; i++ )
|
|
143 |
if( max>0 )
|
|
150 | 144 |
{ |
151 |
mEffects[i] = source.mEffects[i]; |
|
152 |
mName[i] = source.mName[i]; |
|
153 |
mAndAssociation[i] = source.mAndAssociation[i]; |
|
154 |
mEquAssociation[i] = source.mEquAssociation[i]; |
|
145 |
mEffects = new Effect[max]; |
|
146 |
mFloatUniforms = new float[max*source.mNumFloatUniforms]; |
|
147 |
mIntUniforms = new int[max*source.mNumIntUniforms]; |
|
148 |
|
|
149 |
if( mNumEffects>=0 ) |
|
150 |
{ |
|
151 |
System.arraycopy(source.mEffects, 0, mEffects, 0, mNumEffects); |
|
152 |
} |
|
153 |
|
|
154 |
if( mNumIntUniforms*mNumEffects>=0 ) |
|
155 |
{ |
|
156 |
System.arraycopy(source.mIntUniforms, 0, mIntUniforms, 0, mNumIntUniforms*mNumEffects); |
|
157 |
} |
|
155 | 158 |
} |
156 | 159 |
} |
157 | 160 |
} |
... | ... | |
268 | 271 |
{ |
269 | 272 |
mNumEffects--; |
270 | 273 |
|
271 |
for(int j=effect; j<mNumEffects; j++ ) |
|
274 |
int max = mMax[mIndex]; |
|
275 |
|
|
276 |
for(int i=effect; i<mNumEffects; i++ ) |
|
272 | 277 |
{ |
273 |
mEffects[j] = mEffects[j+1]; |
|
274 |
mName[j] = mName[j+1]; |
|
275 |
mAndAssociation[j] = mAndAssociation[j+1]; |
|
276 |
mEquAssociation[j] = mEquAssociation[j+1]; |
|
278 |
mEffects[i]= mEffects[i+1]; |
|
279 |
|
|
280 |
for(int j=0; j<mNumIntUniforms; j++) |
|
281 |
{ |
|
282 |
mIntUniforms[j*max + i] = mIntUniforms[j*max + i+1]; |
|
283 |
} |
|
277 | 284 |
} |
278 | 285 |
|
279 | 286 |
mEffects[mNumEffects] = null; |
... | ... | |
289 | 296 |
{ |
290 | 297 |
if( mEffects[i].getName() == name ) |
291 | 298 |
{ |
292 |
mJobs.add(new Job(DETACH,0,true,mEffects[i])); |
|
299 |
mJobs.add(new Job(DETACH,0,0,true,mEffects[i]));
|
|
293 | 300 |
ret++; |
294 | 301 |
} |
295 | 302 |
} |
... | ... | |
311 | 318 |
{ |
312 | 319 |
if( mEffects[i].getID() == id ) |
313 | 320 |
{ |
314 |
mJobs.add(new Job(DETACH,0,true,mEffects[i])); |
|
321 |
mJobs.add(new Job(DETACH,0,0,true,mEffects[i]));
|
|
315 | 322 |
InternalMaster.newSlave(this); |
316 | 323 |
mNumEffectsToBe--; |
317 | 324 |
return 1; |
... | ... | |
329 | 336 |
{ |
330 | 337 |
if( mEffects[i]==effect ) |
331 | 338 |
{ |
332 |
mJobs.add(new Job(DETACH,0,true,mEffects[i])); |
|
339 |
mJobs.add(new Job(DETACH,0,0,true,mEffects[i]));
|
|
333 | 340 |
InternalMaster.newSlave(this); |
334 | 341 |
mNumEffectsToBe--; |
335 | 342 |
return 1; |
... | ... | |
345 | 352 |
|
346 | 353 |
public synchronized int removeAll(boolean notify) |
347 | 354 |
{ |
348 |
mJobs.add(new Job(DETALL,0,notify,null)); |
|
355 |
mJobs.add(new Job(DETALL,0,0,notify,null));
|
|
349 | 356 |
InternalMaster.newSlave(this); |
350 | 357 |
mNumEffectsToBe = 0; |
351 | 358 |
return mNumEffects; |
... | ... | |
357 | 364 |
{ |
358 | 365 |
if( mMax[mIndex]>mNumEffectsToBe || !mCreated ) |
359 | 366 |
{ |
360 |
mJobs.add(new Job(ATTACH,-1,false,effect)); |
|
367 |
mJobs.add(new Job(ATTACH,-1,0,false,effect));
|
|
361 | 368 |
InternalMaster.newSlave(this); |
362 | 369 |
mNumEffectsToBe++; |
363 | 370 |
return true; |
... | ... | |
372 | 379 |
{ |
373 | 380 |
if( mMax[mIndex]>mNumEffectsToBe || !mCreated ) |
374 | 381 |
{ |
375 |
mJobs.add(new Job(ATTACH,position,false,effect)); |
|
382 |
mJobs.add(new Job(ATTACH,position,0,false,effect));
|
|
376 | 383 |
InternalMaster.newSlave(this); |
377 | 384 |
mNumEffectsToBe++; |
378 | 385 |
return true; |
... | ... | |
427 | 434 |
case CREATE: int max = mMax[mIndex]; |
428 | 435 |
if( max>0 ) |
429 | 436 |
{ |
430 |
mUniforms = new float[max*job.num]; |
|
431 |
mEffects = new Effect[max]; |
|
432 |
mName = new int[max]; |
|
433 |
mAndAssociation = new int[max]; |
|
434 |
mEquAssociation = new int[max]; |
|
437 |
mEffects = new Effect[max]; |
|
438 |
mFloatUniforms = new float[max*job.num1]; |
|
439 |
mIntUniforms = new int[max*job.num2]; |
|
435 | 440 |
} |
436 | 441 |
mCreated = true; |
437 | 442 |
|
438 | 443 |
break; |
439 | 444 |
case ATTACH: if( mMax[mIndex]>mNumEffects ) // it is possible that we have first |
440 | 445 |
{ // added effects and then lowered mMax |
441 |
int position = job.num; |
|
446 |
int position = job.num1;
|
|
442 | 447 |
|
443 | 448 |
if( position==-1 ) |
444 | 449 |
{ |
445 |
mEffects[mNumEffects] = job.effect; |
|
446 |
mName[mNumEffects] = job.effect.getName().ordinal(); |
|
447 |
mAndAssociation[mNumEffects] = job.effect.getAndAssociation(); |
|
448 |
mEquAssociation[mNumEffects] = job.effect.getEquAssociation(); |
|
450 |
mEffects[mNumEffects] = job.effect; |
|
451 |
mIntUniforms[mNumEffects] = job.effect.getName().ordinal(); |
|
449 | 452 |
|
450 | 453 |
mNumEffects++; |
451 | 454 |
changed = true; |
... | ... | |
454 | 457 |
{ |
455 | 458 |
for(int j=mNumEffects; j>position; j--) |
456 | 459 |
{ |
457 |
mEffects[j] = mEffects[j-1]; |
|
458 |
mName[j] = mName[j-1]; |
|
459 |
mAndAssociation[j] = mAndAssociation[j-1]; |
|
460 |
mEquAssociation[j] = mEquAssociation[j-1]; |
|
460 |
mEffects[j] = mEffects[j-1]; |
|
461 |
mIntUniforms[j] = mIntUniforms[j-1]; |
|
461 | 462 |
} |
462 | 463 |
|
463 |
mEffects[position] = job.effect; |
|
464 |
mName[position] = job.effect.getName().ordinal(); |
|
465 |
mAndAssociation[position] = job.effect.getAndAssociation(); |
|
466 |
mEquAssociation[position] = job.effect.getEquAssociation(); |
|
464 |
mEffects[position] = job.effect; |
|
465 |
mIntUniforms[position] = job.effect.getName().ordinal(); |
|
467 | 466 |
|
468 | 467 |
mNumEffects++; |
469 | 468 |
changed = true; |
src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
class EffectQueueFragment extends EffectQueue |
31 | 31 |
{ |
32 |
private static final int NUM_UNIFORMS = FragmentEffect.NUM_UNIFORMS; |
|
32 |
private static final int NUM_FLOAT_UNIFORMS = FragmentEffect.NUM_FLOAT_UNIFORMS; |
|
33 |
private static final int NUM_INT_UNIFORMS = FragmentEffect.NUM_INT_UNIFORMS; |
|
34 |
|
|
33 | 35 |
private static final int INDEX = EffectType.FRAGMENT.ordinal(); |
34 | 36 |
|
35 | 37 |
private static int[] mNumEffectsH = new int[MAIN_VARIANTS]; |
... | ... | |
40 | 42 |
|
41 | 43 |
EffectQueueFragment() |
42 | 44 |
{ |
43 |
super(NUM_UNIFORMS,INDEX);
|
|
45 |
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
|
|
44 | 46 |
} |
45 | 47 |
|
46 | 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
69 | 71 |
|
70 | 72 |
for(int i=0; i<mNumEffects; i++) |
71 | 73 |
{ |
72 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, currTime, step) )
|
|
74 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
73 | 75 |
{ |
74 | 76 |
EffectMessageSender.newMessage(mEffects[i]); |
75 | 77 |
} |
... | ... | |
86 | 88 |
|
87 | 89 |
if( mNumEffects>0 ) |
88 | 90 |
{ |
89 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mName ,0); |
|
90 |
GLES30.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0); |
|
91 |
for(int i=0; i<mNumEffects; i++) |
|
92 |
{ |
|
93 |
String f = |
|
94 |
mFloatUniforms[12*i]+" "+ |
|
95 |
mFloatUniforms[12*i+1]+" "+ |
|
96 |
mFloatUniforms[12*i+2]+" "+ |
|
97 |
mFloatUniforms[12*i+3]+" "+ |
|
98 |
mFloatUniforms[12*i+4]+" "+ |
|
99 |
mFloatUniforms[12*i+5]+" "+ |
|
100 |
mFloatUniforms[12*i+6]+" "+ |
|
101 |
mFloatUniforms[12*i+7]+" "+ |
|
102 |
mFloatUniforms[12*i+8]+" "+ |
|
103 |
mFloatUniforms[12*i+9]+" "+ |
|
104 |
mFloatUniforms[12*i+10]+" "+ |
|
105 |
mFloatUniforms[12*i+11]; |
|
106 |
|
|
107 |
android.util.Log.e("frag", i+" name: "+mIntUniforms[i]+" float: "+f); |
|
108 |
} |
|
109 |
|
|
110 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mIntUniforms , 0); |
|
111 |
GLES30.glUniform4fv( mUniformsH[variant],(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms, 0); |
|
91 | 112 |
} |
92 | 113 |
} |
93 | 114 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java | ||
---|---|---|
29 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 30 |
|
31 | 31 |
class EffectQueueMatrix extends EffectQueue |
32 |
{ |
|
33 |
private static final int NUM_UNIFORMS = MatrixEffect.NUM_UNIFORMS; |
|
32 |
{ |
|
33 |
private static final int NUM_FLOAT_UNIFORMS = MatrixEffect.NUM_FLOAT_UNIFORMS; |
|
34 |
private static final int NUM_INT_UNIFORMS = MatrixEffect.NUM_INT_UNIFORMS; |
|
35 |
|
|
34 | 36 |
private static final int INDEX = EffectType.MATRIX.ordinal(); |
35 | 37 |
|
36 | 38 |
private static float[] mMVPMatrix = new float[16]; |
... | ... | |
45 | 47 |
|
46 | 48 |
EffectQueueMatrix() |
47 | 49 |
{ |
48 |
super(NUM_UNIFORMS,INDEX );
|
|
50 |
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
|
|
49 | 51 |
} |
50 | 52 |
|
51 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
74 | 76 |
|
75 | 77 |
for(int i=0; i<mNumEffects; i++) |
76 | 78 |
{ |
77 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, currTime, step) )
|
|
79 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
78 | 80 |
{ |
79 | 81 |
EffectMessageSender.newMessage(mEffects[i]); |
80 | 82 |
} |
... | ... | |
115 | 117 |
// the 'Model' part of the MV matrix |
116 | 118 |
for(int i=mNumEffects-1; i>=0; i--) |
117 | 119 |
{ |
118 |
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,mUniforms,i); |
|
120 |
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,mFloatUniforms,i);
|
|
119 | 121 |
} |
120 | 122 |
|
121 | 123 |
// combined Model-View-Projection matrix |
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
---|---|---|
47 | 47 |
*/ |
48 | 48 |
public class EffectQueuePostprocess extends EffectQueue |
49 | 49 |
{ |
50 |
private static final int NUM_UNIFORMS = PostprocessEffect.NUM_UNIFORMS; |
|
50 |
private static final int NUM_FLOAT_UNIFORMS = PostprocessEffect.NUM_FLOAT_UNIFORMS; |
|
51 |
private static final int NUM_INT_UNIFORMS = PostprocessEffect.NUM_INT_UNIFORMS; |
|
52 |
|
|
51 | 53 |
private static final int INDEX = EffectType.POSTPROCESS.ordinal(); |
52 | 54 |
|
53 | 55 |
private int mHalo; |
... | ... | |
62 | 64 |
|
63 | 65 |
EffectQueuePostprocess() |
64 | 66 |
{ |
65 |
super(NUM_UNIFORMS,INDEX );
|
|
67 |
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX );
|
|
66 | 68 |
} |
67 | 69 |
|
68 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
89 | 91 |
// first zero out the 'alpha' because BLUR effect will not overwrite this (it is a 1D effect) |
90 | 92 |
// and if previously there was a GLOW effect here then mA would be non-zero and we don't want |
91 | 93 |
// that (see preprocess()) |
92 |
mUniforms[NUM_UNIFORMS*i+5]=0.0f;
|
|
94 |
mFloatUniforms[NUM_FLOAT_UNIFORMS*i+5]=0.0f;
|
|
93 | 95 |
|
94 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, currTime, step) )
|
|
96 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
95 | 97 |
{ |
96 | 98 |
EffectMessageSender.newMessage(mEffects[i]); |
97 | 99 |
} |
98 | 100 |
|
99 |
halo = (int)mUniforms[NUM_UNIFORMS*i];
|
|
101 |
halo = (int)mFloatUniforms[NUM_FLOAT_UNIFORMS*i];
|
|
100 | 102 |
if( halo>mHalo ) mHalo = halo; |
101 | 103 |
} |
102 | 104 |
|
103 | 105 |
// TODO (now only really works in case of 1 effect!) |
104 | 106 |
if( mNumEffects>0 ) |
105 | 107 |
{ |
106 |
mR = mUniforms[2]; |
|
107 |
mG = mUniforms[3]; |
|
108 |
mB = mUniforms[4]; |
|
109 |
mA = mUniforms[5]; |
|
108 |
mR = mFloatUniforms[2];
|
|
109 |
mG = mFloatUniforms[3];
|
|
110 |
mB = mFloatUniforms[4];
|
|
111 |
mA = mFloatUniforms[5];
|
|
110 | 112 |
} |
111 | 113 |
|
112 | 114 |
mTime = currTime; |
... | ... | |
214 | 216 |
|
215 | 217 |
for(int i=0; i<mNumEffects; i++) |
216 | 218 |
{ |
217 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, buffer);
|
|
219 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(mFloatUniforms,NUM_FLOAT_UNIFORMS*i, buffer);
|
|
218 | 220 |
} |
219 | 221 |
|
220 | 222 |
GLES30.glEnable(GLES30.GL_BLEND); |
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
---|---|---|
32 | 32 |
* @y.exclude |
33 | 33 |
*/ |
34 | 34 |
public class EffectQueueVertex extends EffectQueue |
35 |
{ |
|
36 |
private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS; |
|
35 |
{ |
|
36 |
private static final int NUM_FLOAT_UNIFORMS = VertexEffect.NUM_FLOAT_UNIFORMS; |
|
37 |
private static final int NUM_INT_UNIFORMS = VertexEffect.NUM_INT_UNIFORMS; |
|
38 |
|
|
37 | 39 |
private static final int INDEX = EffectType.VERTEX.ordinal(); |
38 | 40 |
|
39 | 41 |
private static int[] mNumEffectsH = new int[MAIN_VARIANTS]; |
... | ... | |
47 | 49 |
|
48 | 50 |
public EffectQueueVertex() |
49 | 51 |
{ |
50 |
super(NUM_UNIFORMS,INDEX);
|
|
52 |
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
|
|
51 | 53 |
} |
52 | 54 |
|
53 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
83 | 85 |
|
84 | 86 |
for(int i=0; i<mNumEffects; i++) |
85 | 87 |
{ |
86 |
mAndAssociation[i] = mEffects[i].getAndAssociation(); |
|
87 |
mEquAssociation[i] = mEffects[i].getEquAssociation(); |
|
88 |
mEffects[i].writeAssociations(mIntUniforms, mMax[INDEX]+i, 2*mMax[INDEX]+i); |
|
88 | 89 |
|
89 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, currTime, step) )
|
|
90 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
90 | 91 |
{ |
91 | 92 |
EffectMessageSender.newMessage(mEffects[i]); |
92 | 93 |
} |
... | ... | |
108 | 109 |
|
109 | 110 |
if( mNumEffects>0 ) |
110 | 111 |
{ |
111 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mName , 0);
|
|
112 |
GLES30.glUniform1iv( mAndAssociationH[variant], mNumEffects, mAndAssociation, 0);
|
|
113 |
GLES30.glUniform1iv( mEquAssociationH[variant], mNumEffects, mEquAssociation, 0);
|
|
114 |
GLES30.glUniform4fv( mUniformsH[variant] ,(NUM_UNIFORMS/4)*mNumEffects, mUniforms , 0);
|
|
112 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mIntUniforms , 0 );
|
|
113 |
GLES30.glUniform1iv( mAndAssociationH[variant], mNumEffects, mIntUniforms , mMax[INDEX]);
|
|
114 |
GLES30.glUniform1iv( mEquAssociationH[variant], mNumEffects, mIntUniforms , 2*mMax[INDEX]);
|
|
115 |
GLES30.glUniform4fv( mUniformsH[variant] ,(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms , 0 );
|
|
115 | 116 |
} |
116 | 117 |
} |
117 | 118 |
} |
src/main/java/org/distorted/library/mesh/AssociationUniformBlock.java | ||
---|---|---|
79 | 79 |
*/ |
80 | 80 |
public static void setAssociationSize(int size) |
81 | 81 |
{ |
82 |
mAssociationSize = size; |
|
82 |
if( size>0 ) mAssociationSize = size; // if we are not using any VertexEffects, there |
|
83 |
// will be no 'meshAssociation' UBO in the shader, |
|
84 |
// and thus its detected size will be 0. Do not change |
|
85 |
// the initial guess then - we still might need the |
|
86 |
// associations for applying the MatrixEffects to a |
|
87 |
// mesh, for one. |
|
83 | 88 |
} |
84 | 89 |
|
85 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
136 | 141 |
|
137 | 142 |
if( mAssociationSize != 4*oldLen ) |
138 | 143 |
{ |
144 |
android.util.Log.e("ass", "assSize="+mAssociationSize+" oldLen="+oldLen); |
|
145 |
|
|
139 | 146 |
int[] tmp = new int[oldLen]; |
140 | 147 |
System.arraycopy(mAssociations, 0, tmp, 0, oldLen); |
141 | 148 |
|
src/main/res/raw/main_fragment_shader.glsl | ||
---|---|---|
120 | 120 |
diff = (v_Position - fUniforms[effect+1].yzw)/fUniforms[effect+2].xyz; |
121 | 121 |
degree = max(0.0,1.0-dot(diff,diff)); |
122 | 122 |
|
123 |
color.a *= (degree*(fUniforms[effect].x-1.0)+1.0); |
|
124 |
|
|
123 | 125 |
// ENABLED EFFECTS WILL BE INSERTED HERE |
124 | 126 |
|
125 | 127 |
effect+=3; |
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
49 | 49 |
#if NUM_VERTEX>0 |
50 | 50 |
uniform int vNumEffects; // total number of vertex effects |
51 | 51 |
uniform int vName[NUM_VERTEX]; // their names. |
52 |
uniform int vEffAndAssoc[NUM_VERTEX];// Associations of the vertex effects. Those are used to connect an effect to a Mesh component. |
|
53 |
uniform int vEffEquAssoc[NUM_VERTEX];// Components the vertex effects work on. Likewise used to connect an effect to a Mesh component. |
|
54 |
|
|
52 | 55 |
uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
53 | 56 |
// The first vec4 is the Interpolated values, |
54 | 57 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
55 |
uniform int vEffAndAssoc[NUM_VERTEX];// Associations of the vertex effects. Those are used to connect an effect to a Mesh component. |
|
56 |
uniform int vEffEquAssoc[NUM_VERTEX];// Components the vertex effects work on. Likewise used to connect an effect to a Mesh component. |
|
57 | 58 |
|
58 |
layout (std140, binding=1) uniform meshAssociation
|
|
59 |
layout (shared, binding=1) uniform meshAssociation
|
|
59 | 60 |
{ |
60 | 61 |
int vComAndAssoc[MAX_COMPON]; // 'logical AND' association of the component. |
61 | 62 |
int vComEquAssoc[MAX_COMPON]; // 'equal' association of the component. |
Also available in: Unified diff
Introducing UBO to Effect Queues: step 1.