Revision 0318e7e3
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/library/EffectMessageSender.java | ||
---|---|---|
121 | 121 |
} |
122 | 122 |
|
123 | 123 |
mThis = null; |
124 |
mList.clear(); |
|
124 | 125 |
|
125 | 126 |
//android.util.Log.i("SENDER", "sender thread finished..."); |
126 | 127 |
} |
src/main/java/org/distorted/library/EffectNames.java | ||
---|---|---|
230 | 230 |
case 4: unities[MAXDIM*i+3] = name.unity[3]; |
231 | 231 |
case 3: unities[MAXDIM*i+2] = name.unity[2]; |
232 | 232 |
case 2: unities[MAXDIM*i+1] = name.unity[1]; |
233 |
case 1: unities[MAXDIM*i+0] = name.unity[0];
|
|
233 |
case 1: unities[MAXDIM*i ] = name.unity[0];
|
|
234 | 234 |
case 0: break; |
235 | 235 |
} |
236 | 236 |
|
... | ... | |
267 | 267 |
switch(dimensions[ordinal]) |
268 | 268 |
{ |
269 | 269 |
case 0: break; |
270 |
case 1: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
|
270 |
case 1: buffer[index ]=unities[MAXDIM*ordinal ];
|
|
271 | 271 |
break; |
272 |
case 2: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
|
272 |
case 2: buffer[index ]=unities[MAXDIM*ordinal ];
|
|
273 | 273 |
buffer[index+1]=unities[MAXDIM*ordinal+1]; |
274 | 274 |
break; |
275 |
case 3: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
|
275 |
case 3: buffer[index ]=unities[MAXDIM*ordinal ];
|
|
276 | 276 |
buffer[index+1]=unities[MAXDIM*ordinal+1]; |
277 | 277 |
buffer[index+2]=unities[MAXDIM*ordinal+2]; |
278 | 278 |
break; |
279 |
case 4: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
|
279 |
case 4: buffer[index ]=unities[MAXDIM*ordinal ];
|
|
280 | 280 |
buffer[index+1]=unities[MAXDIM*ordinal+1]; |
281 | 281 |
buffer[index+2]=unities[MAXDIM*ordinal+2]; |
282 | 282 |
buffer[index+3]=unities[MAXDIM*ordinal+3]; |
... | ... | |
291 | 291 |
switch(dimensions[ordinal]) |
292 | 292 |
{ |
293 | 293 |
case 0: return true; |
294 |
case 1: return buffer[index+0]==unities[MAXDIM*ordinal+0];
|
|
295 |
case 2: return buffer[index+0]==unities[MAXDIM*ordinal+0] &&
|
|
294 |
case 1: return buffer[index ]==unities[MAXDIM*ordinal ];
|
|
295 |
case 2: return buffer[index ]==unities[MAXDIM*ordinal ] &&
|
|
296 | 296 |
buffer[index+1]==unities[MAXDIM*ordinal+1]; |
297 |
case 3: return buffer[index+0]==unities[MAXDIM*ordinal+0] &&
|
|
297 |
case 3: return buffer[index ]==unities[MAXDIM*ordinal ] &&
|
|
298 | 298 |
buffer[index+1]==unities[MAXDIM*ordinal+1] && |
299 | 299 |
buffer[index+2]==unities[MAXDIM*ordinal+2]; |
300 |
case 4: return buffer[index+0]==unities[MAXDIM*ordinal+0] &&
|
|
300 |
case 4: return buffer[index ]==unities[MAXDIM*ordinal ] &&
|
|
301 | 301 |
buffer[index+1]==unities[MAXDIM*ordinal+1] && |
302 | 302 |
buffer[index+2]==unities[MAXDIM*ordinal+2] && |
303 | 303 |
buffer[index+3]==unities[MAXDIM*ordinal+3]; |
src/main/java/org/distorted/library/EffectQueue.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
protected int[] mName; |
36 | 36 |
protected float[] mUniforms; |
37 |
protected Dynamic[][] mInter; // center of the effect
|
|
37 |
protected Dynamic[][] mInter; |
|
38 | 38 |
protected long[] mCurrentDuration; |
39 | 39 |
protected byte[] mFreeIndexes; |
40 | 40 |
protected byte[] mIDIndex; |
src/main/java/org/distorted/library/EffectQueueMatrix.java | ||
---|---|---|
89 | 89 |
|
90 | 90 |
static void getUniforms(int mProgramH) |
91 | 91 |
{ |
92 |
mBmpDH = GLES20.glGetUniformLocation(mProgramH, "u_bmpD");
|
|
92 |
mBmpDH = GLES20.glGetUniformLocation(mProgramH, "u_objD");
|
|
93 | 93 |
mDepthH = GLES20.glGetUniformLocation(mProgramH, "u_Depth"); |
94 | 94 |
mMVPMatrixH= GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix"); |
95 | 95 |
mMVMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVMatrix"); |
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
17 | 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
18 | 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 19 |
|
20 |
uniform vec3 u_bmpD; // half of object width x half of object height X half the depth;
|
|
20 |
uniform vec3 u_objD; // half of object width x half of object height X half the depth;
|
|
21 | 21 |
// point (0,0,0) is the center of the object |
22 | 22 |
|
23 | 23 |
uniform float u_Depth; // max absolute value of v.z ; beyond that the vertex would be culled by the near or far planes. |
... | ... | |
90 | 90 |
// |
91 | 91 |
// If we are dragging the top edge: |
92 | 92 |
// |
93 |
// Now point (x,u_bmpD.x) on the top edge will move by vector (X(t),Y(t)) where those functions are given by (*) and
|
|
94 |
// t = x < dSx ? (u_bmpD.x+x)/(u_bmpD.x+dSx) : (u_bmpD.x-x)/(u_bmpD.x-dSx)
|
|
95 |
// Any point (x,y) will move by vector (a*X(t),a*Y(t)) where a is (y+u_bmpD.y)/(2*u_bmpD.y)
|
|
93 |
// Now point (x,u_objD.x) on the top edge will move by vector (X(t),Y(t)) where those functions are given by (*) and
|
|
94 |
// t = x < dSx ? (u_objD.x+x)/(u_objD.x+dSx) : (u_objD.x-x)/(u_objD.x-dSx)
|
|
95 |
// Any point (x,y) will move by vector (a*X(t),a*Y(t)) where a is (y+u_objD.y)/(2*u_objD.y)
|
|
96 | 96 |
|
97 | 97 |
void deform(in int effect, inout vec4 v) |
98 | 98 |
{ |
... | ... | |
100 | 100 |
vec2 w = vUniforms[effect].xy; // w = vec(MM') |
101 | 101 |
vec2 vert_vec, horz_vec; |
102 | 102 |
vec2 signXY = sign(p-v.xy); |
103 |
vec2 time = (u_bmpD.xy+signXY*v.xy)/(u_bmpD.xy+signXY*p);
|
|
104 |
vec2 factorV = vec2(0.5,0.5) + sign(p)*v.xy/(4.0*u_bmpD.xy);
|
|
105 |
vec2 factorD = (u_bmpD.xy-signXY*p)/(2.0*u_bmpD.xy);
|
|
103 |
vec2 time = (u_objD.xy+signXY*v.xy)/(u_objD.xy+signXY*p);
|
|
104 |
vec2 factorV = vec2(0.5,0.5) + sign(p)*v.xy/(4.0*u_objD.xy);
|
|
105 |
vec2 factorD = (u_objD.xy-signXY*p)/(2.0*u_objD.xy);
|
|
106 | 106 |
vec2 vert_d = factorD.x*w; |
107 | 107 |
vec2 horz_d = factorD.y*w; |
108 |
vec2 corr = 0.33 / ( 1.0 + (4.0*u_bmpD.x*u_bmpD.x)/dot(w,w) ) * (p+w+signXY*u_bmpD.xy); // .x = the vector tangent to X(t) at Fl = 0.3*vec(LM') (or vec(RM') if signXY.x=-1).
|
|
109 |
// .y = the vector tangent to X(t) at Fb = 0.3*vec(BM') (or vec(TM') if signXY.y=-1) |
|
110 |
// the scalar: make the length of the speed vectors at Fl and Fr be 0 when force vector 'w' is zero
|
|
108 |
vec2 corr = 0.33 / ( 1.0 + (4.0*u_objD.x*u_objD.x)/dot(w,w) ) * (p+w+signXY*u_objD.xy); // .x = the vector tangent to X(t) at Fl = 0.3*vec(LM') (or vec(RM') if signXY.x=-1).
|
|
109 |
// .y = the vector tangent to X(t) at Fb = 0.3*vec(BM') (or vec(TM') if signXY.y=-1)
|
|
110 |
// the scalar: make the length of the speed vectors at Fl and Fr be 0 when force vector 'w' is zero
|
|
111 | 111 |
vert_vec.x = ( w.x-vert_d.x-corr.x )*time.x*time.x + corr.x*time.x + vert_d.x; |
112 | 112 |
horz_vec.y = (-w.y+horz_d.y+corr.y )*time.y*time.y - corr.y*time.y - horz_d.y; |
113 | 113 |
vert_vec.y = (-3.0*vert_d.y+2.0*w.y )*time.x*time.x*time.x + (-3.0*w.y+5.0*vert_d.y )*time.x*time.x - vert_d.y*time.x - vert_d.y; |
... | ... | |
133 | 133 |
// |
134 | 134 |
// the trick below is the if-less version of the |
135 | 135 |
// |
136 |
// t = dx<0.0 ? (u_bmpD.x-v.x) / (u_bmpD.x-ux) : (u_bmpD.x+v.x) / (u_bmpD.x+ux);
|
|
137 |
// h = dy<0.0 ? (u_bmpD.y-v.y) / (u_bmpD.y-uy) : (u_bmpD.y+v.y) / (u_bmpD.y+uy);
|
|
136 |
// t = dx<0.0 ? (u_objD.x-v.x) / (u_objD.x-ux) : (u_objD.x+v.x) / (u_objD.x+ux);
|
|
137 |
// h = dy<0.0 ? (u_objD.y-v.y) / (u_objD.y-uy) : (u_objD.y+v.y) / (u_objD.y+uy);
|
|
138 | 138 |
// d = min(t,h); |
139 | 139 |
// |
140 |
// float d = min(-ps.x/(sign(ps.x)*u_bmpD.x+p.x),-ps.y/(sign(ps.y)*u_bmpD.y+p.y))+1.0; |
|
141 |
|
|
140 |
// float d = min(-ps.x/(sign(ps.x)*u_objD.x+p.x),-ps.y/(sign(ps.y)*u_objD.y+p.y))+1.0; |
|
141 |
// |
|
142 |
// We still have to avoid division by 0 when p.x = +- u_objD.x or p.y = +- u_objD.y (i.e on the edge of the Object) |
|
143 |
// We do that by first multiplying the above 'float d' with sign(denominator1*denominator2)^2. |
|
144 |
// |
|
142 | 145 |
////////////////////////////////////////////////////////////////////////////////////////////// |
143 | 146 |
// return degree of the point as defined by the bitmap rectangle |
144 | 147 |
|
145 | 148 |
float degree_bitmap(in vec2 S, in vec2 PS) |
146 | 149 |
{ |
147 |
return min(-PS.x/(sign(PS.x)*u_bmpD.x+S.x),-PS.y/(sign(PS.y)*u_bmpD.y+S.y))+1.0; |
|
150 |
vec2 A = sign(PS)*u_objD.xy + S; |
|
151 |
float B = sign(A.x*A.y); |
|
152 |
|
|
153 |
return B*B*(1.0 + min(-PS.x/A.x,-PS.y/A.y)); |
|
148 | 154 |
} |
149 | 155 |
|
150 | 156 |
////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
168 | 174 |
{ |
169 | 175 |
vec2 PO = PS + region.xy; |
170 | 176 |
float D = region.z*region.z-dot(PO,PO); // D = |OX|^2 - |PO|^2 |
171 |
float E = min(-PS.x/(sign(PS.x)*u_bmpD.x+S.x),-PS.y/(sign(PS.y)*u_bmpD.y+S.y))+1.0; |
|
177 |
vec2 A = sign(PS)*u_objD.xy + S; |
|
178 |
float B = sign(A.x*A.y); |
|
179 |
float E = B*B*(1.0 + min(-PS.x/A.x,-PS.y/A.y)); |
|
172 | 180 |
float ps_sq = dot(PS,PS); |
173 | 181 |
float DOT = dot(PS,PO)/ps_sq; |
174 | 182 |
|
... | ... | |
311 | 319 |
|
312 | 320 |
void main() |
313 | 321 |
{ |
314 |
vec4 v = vec4( 2.0*u_bmpD*a_Position,1.0 );
|
|
322 |
vec4 v = vec4( 2.0*u_objD*a_Position,1.0 );
|
|
315 | 323 |
vec4 n = vec4(a_Normal,0.0); |
316 | 324 |
|
317 | 325 |
#if NUM_VERTEX>0 |
Also available in: Unified diff
Important bugfix in the vertex shader: there was division by 0 in case Center point was on the edge of the Object, resulting in some vertices being shot into outer space.