commit 02ef26bc2ee98050519381f0abb143c32d94e5b2
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Tue Aug 30 17:29:59 2016 +0100

    Preparation to make the WAVE effect fully 3D

diff --git a/src/main/java/org/distorted/library/DistortedObject.java b/src/main/java/org/distorted/library/DistortedObject.java
index e71ccf4..cc4deda 100644
--- a/src/main/java/org/distorted/library/DistortedObject.java
+++ b/src/main/java/org/distorted/library/DistortedObject.java
@@ -739,7 +739,7 @@ public abstract class DistortedObject
  */
   public long distort(Data3D vector, Data2D center)
     {
-    return mV.add(EffectNames.DISTORT, vector, center);
+    return mV.add(EffectNames.DISTORT, vector, center, null);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -753,7 +753,7 @@ public abstract class DistortedObject
  */
   public long deform(Data3D vector, Data2D center)
     {  
-    return mV.add(EffectNames.DEFORM, vector, center);
+    return mV.add(EffectNames.DEFORM, vector, center, null);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////  
@@ -822,9 +822,9 @@ public abstract class DistortedObject
  * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long wave(Data3D wave, Data2D center)
+  public long wave(Data4D wave, Data2D center)
     {
-    return mV.add(EffectNames.WAVE, wave, center);
+    return mV.add(EffectNames.WAVE, wave, center, null);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -838,7 +838,7 @@ public abstract class DistortedObject
  * @param region Region that masks the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long wave(Data3D wave, Data2D center, Data4D region)
+  public long wave(Data4D wave, Data2D center, Data4D region)
     {
     return mV.add(EffectNames.WAVE, wave, center, region);
     }
diff --git a/src/main/java/org/distorted/library/EffectNames.java b/src/main/java/org/distorted/library/EffectNames.java
index 9d17b41..374eee3 100644
--- a/src/main/java/org/distorted/library/EffectNames.java
+++ b/src/main/java/org/distorted/library/EffectNames.java
@@ -85,33 +85,41 @@ public enum EffectNames
 
  /////////////////////////////////////////////////////////////////////////////////
  // VERTEX EFFECTS
- // Always 9 Uniforms: 3 per-effect interpolated values, 4-dimensional Region,
- // 2-dimensional center of the effect.
+ // Always 12 Uniforms: 4 per-effect interpolated values, 2 caches, 2-dimensional
+ // center of the effect, 4-dimensional Region
  /**
    * Apply a 3D vector of force to area around a point on the surface of the Object.
    * <p>
-   * Uniforms: (forceX,forceY,forceZ,regionX,regionY,regionRX,regionRY,centerX,centerY)
+   * Uniforms: (forceX ,forceY ,forceZ  ,UNUSED  ,
+  *             UNUSED , UNUSED,centerX ,centerY ,
+  *             regionX,regionY,regionRX,regionRY)
    * Unity: (forceX,forceY,forceZ) = (0,0,0)
    */
   DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),
  /**
    * Deform the whole Object by applying a 2D vector of force to a center point.
    * <p>
-   * Uniforms: (forceX,forceY,UNUSED,UNUSED,UNUSED,UNUSED,UNUSED,centerX,centerY)
+   * Uniforms: (forceX,forceY,UNUSED,UNUSED,
+   *            UNUSED,UNUSED,centerX,centerY,
+   *            UNUSED,UNUSED,UNUSED,UNUSED)
    * Unity: (forceX,forceY) = (0,0)
    */
   DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
  /**
    * Pull (or push away) all points around a center point to (from) it.
    * <p>
-   * Uniforms: (sinkFactor,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY)
+   * Uniforms: (sinkFactor,UNUSED,UNUSED,UNUSED,
+   *            UNUSED,UNUSED,centerX,centerY,
+   *            regionX,regionY,regionRX,regionRY)
    * Unity: sinkFactor = 1
    */
   SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
  /**
    * Smoothly rotate a limited area around a center point.
    * <p>
-   * Uniforms: (swirlAngle,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY)
+   * Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED,
+   *            cache1, UNUSED,centerX,centerY,
+   *            regionX,regionY,regionRX,regionRY)
    * Unity: swirlAngle = 0
    */
   SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
@@ -119,7 +127,9 @@ public enum EffectNames
    * Directional sinusoidal wave effect. The direction of the wave is given by the 'angle'
    * parameter, which is the angle (in degrees) the direction forms with the X-axis.
    * <p>
-   * Uniforms: (amplitude,angle,length,regionX,regionY,regionRX,regionRY,centerX,centerY)
+   * Uniforms: (amplitude,angleAmp,length,angleLen,
+   *            cache1, cache2,centerX,centerY,
+   *            regionX,regionY,regionRX,regionRY)
    * Unity: amplitude  = 0
    */
   WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
diff --git a/src/main/java/org/distorted/library/EffectQueueVertex.java b/src/main/java/org/distorted/library/EffectQueueVertex.java
index 1e101bc..29aeb7a 100644
--- a/src/main/java/org/distorted/library/EffectQueueVertex.java
+++ b/src/main/java/org/distorted/library/EffectQueueVertex.java
@@ -167,46 +167,50 @@ class EffectQueueVertex extends EffectQueue
     if( mName[effect]==EffectNames.SWIRL.ordinal() )
       {
       d = Math.PI*mUniforms[NUM_UNIFORMS*effect]/180;
-      mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.sin(d);
-      mUniforms[NUM_UNIFORMS*effect+5] = (float)Math.cos(d);
+      mUniforms[NUM_UNIFORMS*effect  ] = (float)Math.sin(d);
+      mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.cos(d);
       }
     if( mName[effect]==EffectNames.WAVE.ordinal() )
       {
       d = Math.PI*mUniforms[NUM_UNIFORMS*effect+1]/180;
-      mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.sin(d);
+      mUniforms[NUM_UNIFORMS*effect+1] = (float)Math.sin(d);
+      mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.cos(d);
+      d = Math.PI*mUniforms[NUM_UNIFORMS*effect+3]/180;
+      mUniforms[NUM_UNIFORMS*effect+3] = (float)Math.sin(d);
       mUniforms[NUM_UNIFORMS*effect+5] = (float)Math.cos(d);
       }
     }
-  
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// distort, wave
+// wave
 
-  synchronized long add(EffectNames eln, Data3D data, Data2D center, Data4D region)
+  synchronized long add(EffectNames eln, Data4D data, Data2D center, Data4D region)
     {
     if( mMax[INDEX]>mNumEffects )
       {
-      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);    
+      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
 
-      if( data instanceof Dynamic3D)
-        mInter[0][mNumEffects] = (Dynamic3D)data;
-      else if( data instanceof Static3D)
+      if( data instanceof Dynamic4D)
+        mInter[0][mNumEffects] = (Dynamic4D)data;
+      else if( data instanceof Static4D)
         {
         mInter[0][mNumEffects] = null;
-        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)data).getX();
-        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)data).getY();
-        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ();
+        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static4D)data).getX();
+        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static4D)data).getY();
+        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static4D)data).getZ();
+        mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static4D)data).getW();
         }
 
       return addPriv(eln,center,region);
       }
-      
+
     return -1;
     }
-   
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// deform, distort, wave
+// deform,distort
 
-  synchronized long add(EffectNames eln, Data3D data, Data2D center)
+  synchronized long add(EffectNames eln, Data3D data, Data2D center, Data4D region)
     {
     if( mMax[INDEX]>mNumEffects )
       {
@@ -222,12 +226,12 @@ class EffectQueueVertex extends EffectQueue
         mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ();
         }
 
-      return addPriv(eln,center,null);
+      return addPriv(eln,center,region);
       }
       
     return -1;
     }
- 
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // sink, swirl
 
diff --git a/src/main/java/org/distorted/library/type/Dynamic4D.java b/src/main/java/org/distorted/library/type/Dynamic4D.java
index 28ba772..0e27ba4 100644
--- a/src/main/java/org/distorted/library/type/Dynamic4D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic4D.java
@@ -24,7 +24,7 @@ import java.util.Vector;
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /** 
 * A 4-dimensional implementation of the Dynamic class to interpolate between a list
-* of Float4Ds.
+* of Static4Ds.
 */
 
 public class Dynamic4D extends Dynamic implements Data4D
diff --git a/src/main/res/raw/main_vertex_shader.glsl b/src/main/res/raw/main_vertex_shader.glsl
index 8316fc7..fd81c83 100644
--- a/src/main/res/raw/main_vertex_shader.glsl
+++ b/src/main/res/raw/main_vertex_shader.glsl
@@ -334,8 +334,8 @@ void swirl(in int effect, inout vec4 v)
   vec4 SO = vUniforms[effect+2];
   float d1_circle = degree_region(SO,PS);
   float d1_bitmap = degree_bitmap(center,PS);
-  float sinA = vUniforms[effect+1].x;                          // sin(A) precomputed in EffectListVertex.postprocess
-  float cosA = vUniforms[effect+1].y;                          // cos(A) precomputed in EffectListVertex.postprocess
+  float sinA = vUniforms[effect  ].x;                          // sin(A) precomputed in EffectListVertex.postprocess
+  float cosA = vUniforms[effect+1].x;                          // cos(A) precomputed in EffectListVertex.postprocess
   vec2 PS2 = vec2( PS.x*cosA+PS.y*sinA,-PS.x*sinA+PS.y*cosA ); // vector PS rotated by A radians clockwise around center.
   vec4 SG = (1.0-d1_circle)*SO;                                // coordinates of the dilated circle P is going to get rotated around
   float d2 = max(0.0,degree(SG,center,PS2));                   // make it a max(0,deg) because otherwise when center=left edge of the
@@ -350,17 +350,20 @@ void swirl(in int effect, inout vec4 v)
 
 void wave(in int effect, inout vec4 v)
   {
-  vec2 center = vUniforms[effect+1].zw;
+  vec2 center     = vUniforms[effect+1].zw;
+  float sinA      = vUniforms[effect  ].y;
+  float cosA      = vUniforms[effect+1].x;
+  float sinB      = vUniforms[effect  ].w;
+  float cosB      = vUniforms[effect+1].y;
+  float amplitude = vUniforms[effect  ].x;
+  float length    = vUniforms[effect  ].z;
+
   vec2 ps = center-v.xy;
   float deg = degree_region(vUniforms[effect+2],ps);
-  vec2 sincos = vUniforms[effect+1].xy;
-
-  float amplitude = vUniforms[effect].x;
-  float length    = vUniforms[effect].z;
-  float d = dot( vec2(-ps.y,-ps.x),sincos );
+  float d = -ps.x*cosB-ps.y*sinB;
   float num = length==0.0 ? 0.0 : d / length;
 
-  v.xy += (sin(1.578*num)*amplitude*deg*sincos);
+  v.xy += (sin(1.578*num)*amplitude*deg*vec2(sinB,cosB));
   }
 
 #endif
