Revision 02ef26bc
Added by Leszek Koltunski about 9 years ago
| src/main/java/org/distorted/library/DistortedObject.java | ||
|---|---|---|
| 739 | 739 |
*/ |
| 740 | 740 |
public long distort(Data3D vector, Data2D center) |
| 741 | 741 |
{
|
| 742 |
return mV.add(EffectNames.DISTORT, vector, center); |
|
| 742 |
return mV.add(EffectNames.DISTORT, vector, center, null);
|
|
| 743 | 743 |
} |
| 744 | 744 |
|
| 745 | 745 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 753 | 753 |
*/ |
| 754 | 754 |
public long deform(Data3D vector, Data2D center) |
| 755 | 755 |
{
|
| 756 |
return mV.add(EffectNames.DEFORM, vector, center); |
|
| 756 |
return mV.add(EffectNames.DEFORM, vector, center, null);
|
|
| 757 | 757 |
} |
| 758 | 758 |
|
| 759 | 759 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 822 | 822 |
* @param center 2-dimensional Data that, at any given time, returns the Center of the Effect. |
| 823 | 823 |
* @return ID of the effect added, or -1 if we failed to add one. |
| 824 | 824 |
*/ |
| 825 |
public long wave(Data3D wave, Data2D center)
|
|
| 825 |
public long wave(Data4D wave, Data2D center)
|
|
| 826 | 826 |
{
|
| 827 |
return mV.add(EffectNames.WAVE, wave, center); |
|
| 827 |
return mV.add(EffectNames.WAVE, wave, center, null);
|
|
| 828 | 828 |
} |
| 829 | 829 |
|
| 830 | 830 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 838 | 838 |
* @param region Region that masks the Effect. |
| 839 | 839 |
* @return ID of the effect added, or -1 if we failed to add one. |
| 840 | 840 |
*/ |
| 841 |
public long wave(Data3D wave, Data2D center, Data4D region)
|
|
| 841 |
public long wave(Data4D wave, Data2D center, Data4D region)
|
|
| 842 | 842 |
{
|
| 843 | 843 |
return mV.add(EffectNames.WAVE, wave, center, region); |
| 844 | 844 |
} |
| src/main/java/org/distorted/library/EffectNames.java | ||
|---|---|---|
| 85 | 85 |
|
| 86 | 86 |
///////////////////////////////////////////////////////////////////////////////// |
| 87 | 87 |
// VERTEX EFFECTS |
| 88 |
// Always 9 Uniforms: 3 per-effect interpolated values, 4-dimensional Region,
|
|
| 89 |
// 2-dimensional center of the effect.
|
|
| 88 |
// Always 12 Uniforms: 4 per-effect interpolated values, 2 caches, 2-dimensional
|
|
| 89 |
// center of the effect, 4-dimensional Region
|
|
| 90 | 90 |
/** |
| 91 | 91 |
* Apply a 3D vector of force to area around a point on the surface of the Object. |
| 92 | 92 |
* <p> |
| 93 |
* Uniforms: (forceX,forceY,forceZ,regionX,regionY,regionRX,regionRY,centerX,centerY) |
|
| 93 |
* Uniforms: (forceX ,forceY ,forceZ ,UNUSED , |
|
| 94 |
* UNUSED , UNUSED,centerX ,centerY , |
|
| 95 |
* regionX,regionY,regionRX,regionRY) |
|
| 94 | 96 |
* Unity: (forceX,forceY,forceZ) = (0,0,0) |
| 95 | 97 |
*/ |
| 96 | 98 |
DISTORT ( EffectTypes.VERTEX , new float[] {0.0f,0.0f,0.0f} ),
|
| 97 | 99 |
/** |
| 98 | 100 |
* Deform the whole Object by applying a 2D vector of force to a center point. |
| 99 | 101 |
* <p> |
| 100 |
* Uniforms: (forceX,forceY,UNUSED,UNUSED,UNUSED,UNUSED,UNUSED,centerX,centerY) |
|
| 102 |
* Uniforms: (forceX,forceY,UNUSED,UNUSED, |
|
| 103 |
* UNUSED,UNUSED,centerX,centerY, |
|
| 104 |
* UNUSED,UNUSED,UNUSED,UNUSED) |
|
| 101 | 105 |
* Unity: (forceX,forceY) = (0,0) |
| 102 | 106 |
*/ |
| 103 | 107 |
DEFORM ( EffectTypes.VERTEX , new float[] {0.0f,0.0f} ),
|
| 104 | 108 |
/** |
| 105 | 109 |
* Pull (or push away) all points around a center point to (from) it. |
| 106 | 110 |
* <p> |
| 107 |
* Uniforms: (sinkFactor,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY) |
|
| 111 |
* Uniforms: (sinkFactor,UNUSED,UNUSED,UNUSED, |
|
| 112 |
* UNUSED,UNUSED,centerX,centerY, |
|
| 113 |
* regionX,regionY,regionRX,regionRY) |
|
| 108 | 114 |
* Unity: sinkFactor = 1 |
| 109 | 115 |
*/ |
| 110 | 116 |
SINK ( EffectTypes.VERTEX , new float[] {1.0f} ),
|
| 111 | 117 |
/** |
| 112 | 118 |
* Smoothly rotate a limited area around a center point. |
| 113 | 119 |
* <p> |
| 114 |
* Uniforms: (swirlAngle,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY) |
|
| 120 |
* Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED, |
|
| 121 |
* cache1, UNUSED,centerX,centerY, |
|
| 122 |
* regionX,regionY,regionRX,regionRY) |
|
| 115 | 123 |
* Unity: swirlAngle = 0 |
| 116 | 124 |
*/ |
| 117 | 125 |
SWIRL ( EffectTypes.VERTEX , new float[] {0.0f} ),
|
| ... | ... | |
| 119 | 127 |
* Directional sinusoidal wave effect. The direction of the wave is given by the 'angle' |
| 120 | 128 |
* parameter, which is the angle (in degrees) the direction forms with the X-axis. |
| 121 | 129 |
* <p> |
| 122 |
* Uniforms: (amplitude,angle,length,regionX,regionY,regionRX,regionRY,centerX,centerY) |
|
| 130 |
* Uniforms: (amplitude,angleAmp,length,angleLen, |
|
| 131 |
* cache1, cache2,centerX,centerY, |
|
| 132 |
* regionX,regionY,regionRX,regionRY) |
|
| 123 | 133 |
* Unity: amplitude = 0 |
| 124 | 134 |
*/ |
| 125 | 135 |
WAVE ( EffectTypes.VERTEX , new float[] {0.0f} ),
|
| src/main/java/org/distorted/library/EffectQueueVertex.java | ||
|---|---|---|
| 167 | 167 |
if( mName[effect]==EffectNames.SWIRL.ordinal() ) |
| 168 | 168 |
{
|
| 169 | 169 |
d = Math.PI*mUniforms[NUM_UNIFORMS*effect]/180; |
| 170 |
mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.sin(d);
|
|
| 171 |
mUniforms[NUM_UNIFORMS*effect+5] = (float)Math.cos(d);
|
|
| 170 |
mUniforms[NUM_UNIFORMS*effect ] = (float)Math.sin(d);
|
|
| 171 |
mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.cos(d);
|
|
| 172 | 172 |
} |
| 173 | 173 |
if( mName[effect]==EffectNames.WAVE.ordinal() ) |
| 174 | 174 |
{
|
| 175 | 175 |
d = Math.PI*mUniforms[NUM_UNIFORMS*effect+1]/180; |
| 176 |
mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.sin(d); |
|
| 176 |
mUniforms[NUM_UNIFORMS*effect+1] = (float)Math.sin(d); |
|
| 177 |
mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.cos(d); |
|
| 178 |
d = Math.PI*mUniforms[NUM_UNIFORMS*effect+3]/180; |
|
| 179 |
mUniforms[NUM_UNIFORMS*effect+3] = (float)Math.sin(d); |
|
| 177 | 180 |
mUniforms[NUM_UNIFORMS*effect+5] = (float)Math.cos(d); |
| 178 | 181 |
} |
| 179 | 182 |
} |
| 180 |
|
|
| 183 |
|
|
| 181 | 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 182 |
// distort, wave
|
|
| 185 |
// wave |
|
| 183 | 186 |
|
| 184 |
synchronized long add(EffectNames eln, Data3D data, Data2D center, Data4D region)
|
|
| 187 |
synchronized long add(EffectNames eln, Data4D data, Data2D center, Data4D region)
|
|
| 185 | 188 |
{
|
| 186 | 189 |
if( mMax[INDEX]>mNumEffects ) |
| 187 | 190 |
{
|
| 188 |
EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
|
|
| 191 |
EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); |
|
| 189 | 192 |
|
| 190 |
if( data instanceof Dynamic3D)
|
|
| 191 |
mInter[0][mNumEffects] = (Dynamic3D)data;
|
|
| 192 |
else if( data instanceof Static3D)
|
|
| 193 |
if( data instanceof Dynamic4D)
|
|
| 194 |
mInter[0][mNumEffects] = (Dynamic4D)data;
|
|
| 195 |
else if( data instanceof Static4D)
|
|
| 193 | 196 |
{
|
| 194 | 197 |
mInter[0][mNumEffects] = null; |
| 195 |
mUniforms[NUM_UNIFORMS*mNumEffects ] = ((Static3D)data).getX(); |
|
| 196 |
mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)data).getY(); |
|
| 197 |
mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ(); |
|
| 198 |
mUniforms[NUM_UNIFORMS*mNumEffects ] = ((Static4D)data).getX(); |
|
| 199 |
mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static4D)data).getY(); |
|
| 200 |
mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static4D)data).getZ(); |
|
| 201 |
mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static4D)data).getW(); |
|
| 198 | 202 |
} |
| 199 | 203 |
|
| 200 | 204 |
return addPriv(eln,center,region); |
| 201 | 205 |
} |
| 202 |
|
|
| 206 |
|
|
| 203 | 207 |
return -1; |
| 204 | 208 |
} |
| 205 |
|
|
| 209 |
|
|
| 206 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 207 |
// deform, distort, wave
|
|
| 211 |
// deform,distort
|
|
| 208 | 212 |
|
| 209 |
synchronized long add(EffectNames eln, Data3D data, Data2D center) |
|
| 213 |
synchronized long add(EffectNames eln, Data3D data, Data2D center, Data4D region)
|
|
| 210 | 214 |
{
|
| 211 | 215 |
if( mMax[INDEX]>mNumEffects ) |
| 212 | 216 |
{
|
| ... | ... | |
| 222 | 226 |
mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ(); |
| 223 | 227 |
} |
| 224 | 228 |
|
| 225 |
return addPriv(eln,center,null);
|
|
| 229 |
return addPriv(eln,center,region);
|
|
| 226 | 230 |
} |
| 227 | 231 |
|
| 228 | 232 |
return -1; |
| 229 | 233 |
} |
| 230 |
|
|
| 234 |
|
|
| 231 | 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 232 | 236 |
// sink, swirl |
| 233 | 237 |
|
| src/main/java/org/distorted/library/type/Dynamic4D.java | ||
|---|---|---|
| 24 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 25 | 25 |
/** |
| 26 | 26 |
* A 4-dimensional implementation of the Dynamic class to interpolate between a list |
| 27 |
* of Float4Ds.
|
|
| 27 |
* of Static4Ds.
|
|
| 28 | 28 |
*/ |
| 29 | 29 |
|
| 30 | 30 |
public class Dynamic4D extends Dynamic implements Data4D |
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 334 | 334 |
vec4 SO = vUniforms[effect+2]; |
| 335 | 335 |
float d1_circle = degree_region(SO,PS); |
| 336 | 336 |
float d1_bitmap = degree_bitmap(center,PS); |
| 337 |
float sinA = vUniforms[effect+1].x; // sin(A) precomputed in EffectListVertex.postprocess
|
|
| 338 |
float cosA = vUniforms[effect+1].y; // cos(A) precomputed in EffectListVertex.postprocess
|
|
| 337 |
float sinA = vUniforms[effect ].x; // sin(A) precomputed in EffectListVertex.postprocess
|
|
| 338 |
float cosA = vUniforms[effect+1].x; // cos(A) precomputed in EffectListVertex.postprocess
|
|
| 339 | 339 |
vec2 PS2 = vec2( PS.x*cosA+PS.y*sinA,-PS.x*sinA+PS.y*cosA ); // vector PS rotated by A radians clockwise around center. |
| 340 | 340 |
vec4 SG = (1.0-d1_circle)*SO; // coordinates of the dilated circle P is going to get rotated around |
| 341 | 341 |
float d2 = max(0.0,degree(SG,center,PS2)); // make it a max(0,deg) because otherwise when center=left edge of the |
| ... | ... | |
| 350 | 350 |
|
| 351 | 351 |
void wave(in int effect, inout vec4 v) |
| 352 | 352 |
{
|
| 353 |
vec2 center = vUniforms[effect+1].zw; |
|
| 353 |
vec2 center = vUniforms[effect+1].zw; |
|
| 354 |
float sinA = vUniforms[effect ].y; |
|
| 355 |
float cosA = vUniforms[effect+1].x; |
|
| 356 |
float sinB = vUniforms[effect ].w; |
|
| 357 |
float cosB = vUniforms[effect+1].y; |
|
| 358 |
float amplitude = vUniforms[effect ].x; |
|
| 359 |
float length = vUniforms[effect ].z; |
|
| 360 |
|
|
| 354 | 361 |
vec2 ps = center-v.xy; |
| 355 | 362 |
float deg = degree_region(vUniforms[effect+2],ps); |
| 356 |
vec2 sincos = vUniforms[effect+1].xy; |
|
| 357 |
|
|
| 358 |
float amplitude = vUniforms[effect].x; |
|
| 359 |
float length = vUniforms[effect].z; |
|
| 360 |
float d = dot( vec2(-ps.y,-ps.x),sincos ); |
|
| 363 |
float d = -ps.x*cosB-ps.y*sinB; |
|
| 361 | 364 |
float num = length==0.0 ? 0.0 : d / length; |
| 362 | 365 |
|
| 363 |
v.xy += (sin(1.578*num)*amplitude*deg*sincos);
|
|
| 366 |
v.xy += (sin(1.578*num)*amplitude*deg*vec2(sinB,cosB));
|
|
| 364 | 367 |
} |
| 365 | 368 |
|
| 366 | 369 |
#endif |
Also available in: Unified diff
Preparation to make the WAVE effect fully 3D