commit ffbf279e96795c8c5cc2210f68d748d820334a59
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Thu Jun 30 14:06:55 2016 +0100

    revert latest changes to the fragment shader.
    small things in DistortedObjects.

diff --git a/src/main/java/org/distorted/library/DistortedBitmap.java b/src/main/java/org/distorted/library/DistortedBitmap.java
index 606ed64..ca966f9 100644
--- a/src/main/java/org/distorted/library/DistortedBitmap.java
+++ b/src/main/java/org/distorted/library/DistortedBitmap.java
@@ -51,7 +51,7 @@ public class DistortedBitmap extends DistortedObject
 ///////////////////////////////////////////////////////////////////////////////////////////////////  
 /**
  * Default constructor: creates a DistortedBitmap (width,height) pixels in size, with the distortion
- * grid of size 'size' and does not fill it up with any Bitmap data just yet.
+ * grid of 'cols' and does not fill it up with any Bitmap data just yet.
  * <p>
  * Distortion grid is a grid of rectangles the Bitmap is split to. The vertices of this grid are then 
  * moved around by the Vertex Shader to create various Vertex Effects.
@@ -65,12 +65,13 @@ public class DistortedBitmap extends DistortedObject
  *       
  * @param width  width of the DistortedBitmap, in pixels.
  * @param height height of the DistortedBitmap, in pixels.
- * @param gridSize Horizontal size of the distortion grid. 2<=size&lt;256.
+ * @param cols   Number of columns in the distortion grid. 2<=size&lt;256.
+ *               Number of rows gets calculated with 'rows = cols*height/width'.
  */
-   public DistortedBitmap(int width, int height, int gridSize)
+   public DistortedBitmap(int width, int height, int cols)
      {     
-     int xsize = gridSize;
-     int ysize = xsize*height/width;
+     int xsize = cols;
+     int ysize = cols*height/width;
      
      if( xsize<2   ) xsize=  2;
      if( xsize>256 ) xsize=256;
@@ -79,9 +80,9 @@ public class DistortedBitmap extends DistortedObject
      
      mSizeX= width;
      mSizeY= height;
-     mSizeZ= 1;     
+     mSizeZ= 1;
      mGrid = new DistortedBitmapGrid(xsize,ysize);
-     initializeData(gridSize);
+     initializeData();
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////   
diff --git a/src/main/java/org/distorted/library/DistortedCubes.java b/src/main/java/org/distorted/library/DistortedCubes.java
index ac58e85..23bb86a 100644
--- a/src/main/java/org/distorted/library/DistortedCubes.java
+++ b/src/main/java/org/distorted/library/DistortedCubes.java
@@ -67,10 +67,10 @@ public class DistortedCubes extends DistortedObject
  *
  *              X
  *             </p>
- * @param gridSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
+ * @param cubeSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
  * @param frontOnly Only create the front wall or side and back as well?
  */
- public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly)
+ public DistortedCubes(int cols, String desc, int cubeSize, boolean frontOnly)
    {
    int Rs = 0;
    int Cs = 0;
@@ -93,11 +93,11 @@ public class DistortedCubes extends DistortedObject
        }
      }
      
-   mSizeX= gridSize*Cs;
-   mSizeY= gridSize*Rs;
-   mSizeZ= frontOnly ? 0 : gridSize;
+   mSizeX= cubeSize*Cs;
+   mSizeY= cubeSize*Rs;
+   mSizeZ= frontOnly ? 1 : cubeSize;
    mGrid = new DistortedCubesGrid(cols,desc, frontOnly);
-   initializeData(gridSize);
+   initializeData();
    }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/DistortedObject.java b/src/main/java/org/distorted/library/DistortedObject.java
index ec471a9..83d2c7f 100644
--- a/src/main/java/org/distorted/library/DistortedObject.java
+++ b/src/main/java/org/distorted/library/DistortedObject.java
@@ -46,7 +46,7 @@ public abstract class DistortedObject
  
   protected DistortedObjectGrid mGrid = null;
   protected long mID;
-  protected int mSizeX, mSizeY, mSizeZ, mSize; // in screen space
+  protected int mSizeX, mSizeY, mSizeZ; // in screen space
 
   protected Bitmap[] mBmp= null; //
   int[] mTextureDataH;           // have to be shared among all the cloned Objects
@@ -58,10 +58,9 @@ public abstract class DistortedObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  protected void initializeData(int size)
+  protected void initializeData()
     {
     mID             = DistortedObjectList.add(this);
-    mSize           = size;
     mTextureDataH   = new int[1];
     mTextureDataH[0]= 0;
     mBmp            = new Bitmap[1];
@@ -220,7 +219,6 @@ public abstract class DistortedObject
     mSizeX = dc.mSizeX;
     mSizeY = dc.mSizeY;
     mSizeZ = dc.mSizeZ;
-    mSize  = dc.mSize;
     mGrid  = dc.mGrid;
 
     if( (flags & Distorted.CLONE_BITMAP) != 0 )
diff --git a/src/main/java/org/distorted/library/DistortedObjectGrid.java b/src/main/java/org/distorted/library/DistortedObjectGrid.java
index 50fcfa0..ed3c7e1 100644
--- a/src/main/java/org/distorted/library/DistortedObjectGrid.java
+++ b/src/main/java/org/distorted/library/DistortedObjectGrid.java
@@ -34,7 +34,7 @@ abstract class DistortedObjectGrid
 
    protected int dataLength;                       
       
-   protected FloatBuffer mGridPositions,mGridColors,mGridNormals,mGridTexture;
+   protected FloatBuffer mGridPositions,mGridNormals,mGridTexture;
  
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
diff --git a/src/main/res/raw/main_fragment_shader.glsl b/src/main/res/raw/main_fragment_shader.glsl
index bd985c1..1690718 100644
--- a/src/main/res/raw/main_fragment_shader.glsl
+++ b/src/main/res/raw/main_fragment_shader.glsl
@@ -32,62 +32,57 @@ uniform int fType[NUM_FRAGMENT];        // their types.
 uniform vec4 fUniforms[2*NUM_FRAGMENT]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1]. First vec4 is the Interpolated values,
                                         // next describes the Region, i.e. area over which the effect is active.
 
-const vec3 LUMI3= vec3( 0.2125, 0.7154, 0.0721 );
-const vec3 ZERO3= vec3(0.0,0.0,0.0);
-const vec3 HALF3= vec3(0.5,0.5,0.5);
-const vec2 ONE2 = vec2(1.0,1.0);
-const vec2 HALF2= vec2(0.5,0.5);
-
+const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 );                                        
+ 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // MACROBLOCK EFFECT
 
-void macroblock(float degree, int effect, inout vec4 pixel)
+void macroblock(float degree, int effect, inout vec2 tex)
   {
-  vec2 a = degree*(fUniforms[effect].yz-ONE2)+ONE2;
-  vec2 tex = ( max((1.0-degree)*v_TexCoordinate,floor(v_TexCoordinate*a)) + degree*HALF2 ) / a;
-
-  pixel = texture2D(u_Texture, tex);
+  vec2 one = vec2(1.0,1.0);  
+  vec2 a = degree*(fUniforms[effect].yz-one)+one;
+  tex = ( max((1.0-degree)*tex,floor(tex*a)) + degree*vec2(0.5,0.5) ) / a;
   }
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // CHROMA EFFECT
 
-void chroma(float degree, int effect, inout vec4 pixel)
+void chroma(float degree, int effect, inout vec4 color)
   {
-  pixel.rgb = mix( pixel.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
+  color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
   }
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // ALPHA EFFECT (change transparency level)
 
-void alpha(float degree, int effect, inout vec4 pixel)
+void alpha(float degree, int effect, inout vec4 color)
   {
-  pixel.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
+  color.a *= (degree*(fUniforms[effect].x-1.0)+1.0); 
   }
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // BRIGHTNESS EFFECT
 
-void brightness(float degree, int effect, inout vec4 pixel)
+void brightness(float degree, int effect, inout vec4 color)
   {
-  pixel.rgb = mix(ZERO3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
+  color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
   }
-
+  
 //////////////////////////////////////////////////////////////////////////////////////////////
 // CONTRAST EFFECT
 
-void contrast(float degree, int effect, inout vec4 pixel)
+void contrast(float degree, int effect, inout vec4 color)
   {
-  pixel.rgb = mix(HALF3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
+  color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
   }
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // SATURATION EFFECT
 
-void saturation(float degree, int effect, inout vec4 pixel)
+void saturation(float degree, int effect, inout vec4 color)
   {
-  float luminance = dot(LUMI3,pixel.rgb);
-  pixel.rgb = mix(vec3(luminance,luminance,luminance), pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
+  float luminance = dot(LUMI,color.rgb);
+  color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
   }
 
 #endif
@@ -96,30 +91,31 @@ void saturation(float degree, int effect, inout vec4 pixel)
 
 void main()                    		
   {  
-  vec4 pixel = texture2D(u_Texture, v_TexCoordinate);
+  vec2 tex = v_TexCoordinate;
+  vec4 col = vec4(1.0,1.0,1.0,1.0);
 
 #if NUM_FRAGMENT>0
   vec2 diff;
   float pointDegree;
-
+  
   for(int i=0; i<fNumEffects; i++)
     {
     diff = (v_Position.xy - fUniforms[2*i+1].xy)/fUniforms[2*i+1].zw;
     pointDegree = max(0.0,1.0-dot(diff,diff));
 
-         if( fType[i]==MACROBLOCK        ) macroblock(sign(pointDegree),2*i, pixel);
-    else if( fType[i]==CHROMA            ) chroma    (sign(pointDegree),2*i, pixel);
-    else if( fType[i]==SMOOTH_CHROMA     ) chroma    (     pointDegree ,2*i, pixel);
-    else if( fType[i]==ALPHA             ) alpha     (sign(pointDegree),2*i, pixel);
-    else if( fType[i]==SMOOTH_ALPHA      ) alpha     (     pointDegree ,2*i, pixel);
-    else if( fType[i]==BRIGHTNESS        ) brightness(sign(pointDegree),2*i, pixel);
-    else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness(     pointDegree ,2*i, pixel);
-    else if( fType[i]==CONTRAST          ) contrast  (sign(pointDegree),2*i, pixel);
-    else if( fType[i]==SMOOTH_CONTRAST   ) contrast  (     pointDegree ,2*i, pixel);
-    else if( fType[i]==SATURATION        ) saturation(sign(pointDegree),2*i, pixel);
-    else if( fType[i]==SMOOTH_SATURATION ) saturation(     pointDegree ,2*i, pixel);
+         if( fType[i]==MACROBLOCK        ) macroblock(sign(pointDegree),2*i,tex);
+    else if( fType[i]==CHROMA            ) chroma    (sign(pointDegree),2*i,col);
+    else if( fType[i]==SMOOTH_CHROMA     ) chroma    (     pointDegree ,2*i,col);
+    else if( fType[i]==ALPHA             ) alpha     (sign(pointDegree),2*i,col);
+    else if( fType[i]==SMOOTH_ALPHA      ) alpha     (     pointDegree ,2*i,col);
+    else if( fType[i]==BRIGHTNESS        ) brightness(sign(pointDegree),2*i,col);
+    else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness(     pointDegree ,2*i,col);
+    else if( fType[i]==CONTRAST          ) contrast  (sign(pointDegree),2*i,col);
+    else if( fType[i]==SMOOTH_CONTRAST   ) contrast  (     pointDegree ,2*i,col);
+    else if( fType[i]==SATURATION        ) saturation(sign(pointDegree),2*i,col);
+    else if( fType[i]==SMOOTH_SATURATION ) saturation(     pointDegree ,2*i,col);
     }
 #endif
  
-  gl_FragColor = pixel*0.5*(v_Normal.z+1.0);
+  gl_FragColor = (col * 0.5 * (v_Normal.z+1.0) * texture2D(u_Texture, tex));
   }
\ No newline at end of file
