commit f1d5ea12a7b2363025394522e263cbdde0b90224
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Tue Jan 24 00:51:31 2017 +0000

    Small progress with Blur.

diff --git a/src/main/java/org/distorted/library/DistortedEffects.java b/src/main/java/org/distorted/library/DistortedEffects.java
index 7214928..cd6929f 100644
--- a/src/main/java/org/distorted/library/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/DistortedEffects.java
@@ -305,7 +305,6 @@ public class DistortedEffects
     EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
     EffectQueueVertex.sendZero();
     EffectQueueFragment.sendZero();
-    EffectQueuePostprocess.sendZero(df.mWidth, df.mHeight, mMVPMatrix);
 
     GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
     GLES30.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
diff --git a/src/main/java/org/distorted/library/EffectQueuePostprocess.java b/src/main/java/org/distorted/library/EffectQueuePostprocess.java
index 250f9ee..548207a 100644
--- a/src/main/java/org/distorted/library/EffectQueuePostprocess.java
+++ b/src/main/java/org/distorted/library/EffectQueuePostprocess.java
@@ -49,14 +49,13 @@ class EffectQueuePostprocess extends EffectQueue
   private static final int NUM_CACHE    = 0;
   private static final int INDEX = EffectTypes.POSTPROCESS.ordinal();
 
-  private static int mNumEffectsH;
-  private static int mTypeH;
-  private static int mUniformsH;
+  private static int mRadiusH;
+  private static int mOneOverH;
   private static int mObjDH;
   private static int mMVPMatrixH;
 
   private static final FloatBuffer mQuadPositions, mQuadTexture;
-  private static DistortedProgram mProgram;
+  private static DistortedProgram mBlurProgram;
 
   static
     {
@@ -84,32 +83,16 @@ class EffectQueuePostprocess extends EffectQueue
   static void createProgram(Resources resources)
   throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
     {
-    final InputStream postVertexStream   = resources.openRawResource(R.raw.post_vertex_shader);
-    final InputStream postFragmentStream = resources.openRawResource(R.raw.post_fragment_shader);
+    final InputStream postVertexStream   = resources.openRawResource(R.raw.blur_vertex_shader);
+    final InputStream postFragmentStream = resources.openRawResource(R.raw.blur_fragment_shader);
 
-    String postFragmentHeader= ("#version 100\n#define NUM_POSTPROCESS "  + DistortedEffects.getMaxPostprocess()+"\n");
+    mBlurProgram = new DistortedProgram(postVertexStream,postFragmentStream, "", "");
 
-    for(EffectNames name: EffectNames.values() )
-      {
-      if( name.getType()== EffectTypes.POSTPROCESS)
-        postFragmentHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
-      }
-
-    mProgram = new DistortedProgram(postVertexStream,postFragmentStream, "", postFragmentHeader);
-
-    int postProgramH = mProgram.getProgramHandle();
-    getUniforms(postProgramH);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private static void getUniforms(int mProgramH)
-    {
-    mNumEffectsH= GLES30.glGetUniformLocation( mProgramH, "pNumEffects");
-    mTypeH      = GLES30.glGetUniformLocation( mProgramH, "pType");
-    mUniformsH  = GLES30.glGetUniformLocation( mProgramH, "pUniforms");
-    mObjDH      = GLES30.glGetUniformLocation( mProgramH, "u_objD");
-    mMVPMatrixH = GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
+    int blurProgramH = mBlurProgram.getProgramHandle();
+    mRadiusH    = GLES30.glGetUniformLocation( blurProgramH, "u_Radius");
+    mOneOverH   = GLES30.glGetUniformLocation( blurProgramH, "one_over_objD");
+    mObjDH      = GLES30.glGetUniformLocation( blurProgramH, "u_objD");
+    mMVPMatrixH = GLES30.glGetUniformLocation( blurProgramH, "u_MVPMatrix");
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -156,36 +139,22 @@ class EffectQueuePostprocess extends EffectQueue
     mUniforms[NUM_UNIFORMS*index+3] = mUniforms[NUM_UNIFORMS*(index+1)+3];
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  synchronized static void sendZero(float w, float h, float[] mvp)
-    {
-    GLES30.glUniform1i( mNumEffectsH, 0);
-    GLES30.glUniform2f( mObjDH , w, h);
-    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // w,h - width and height of hte input texture. MVP - Model-View-Projection matrix to apply to the
 // texture; df - output FBO.
 
   synchronized void render(float w, float h, float[] mvp, DistortedFramebuffer df)
     {
-    mProgram.useProgram();
+    mBlurProgram.useProgram();
     df.setAsOutput();
 
-    GLES30.glUniform1i( mNumEffectsH, mNumEffects);
+    GLES30.glUniform1f( mRadiusH, mUniforms[0]);
+    GLES30.glUniform2f( mOneOverH, 1/w,1/h);
     GLES30.glUniform2f( mObjDH , w, h );
     GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
 
-    if( mNumEffects>0 )
-      {
-      GLES30.glUniform1iv( mTypeH    ,                  mNumEffects, mName    ,0);
-      GLES30.glUniform4fv( mUniformsH, (NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
-      }
-
-    GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
-    GLES30.glVertexAttribPointer(mProgram.mAttribute[1], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mQuadTexture);
+    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
+    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mQuadTexture);
     GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
     }
 
diff --git a/src/main/res/raw/blur_fragment_shader.glsl b/src/main/res/raw/blur_fragment_shader.glsl
new file mode 100644
index 0000000..1683c79
--- /dev/null
+++ b/src/main/res/raw/blur_fragment_shader.glsl
@@ -0,0 +1,43 @@
+//////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                          //
+//                                                                                          //
+// This file is part of Distorted.                                                          //
+//                                                                                          //
+// Distorted is free software: you can redistribute it and/or modify                        //
+// it under the terms of the GNU General Public License as published by                     //
+// the Free Software Foundation, either version 2 of the License, or                        //
+// (at your option) any later version.                                                      //
+//                                                                                          //
+// Distorted is distributed in the hope that it will be useful,                             //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                           //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                            //
+// GNU General Public License for more details.                                             //
+//                                                                                          //
+// You should have received a copy of the GNU General Public License                        //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+precision lowp float;
+
+varying vec2 v_TexCoordinate;
+uniform sampler2D u_Texture;
+uniform vec2 one_over_objD;
+uniform float u_Radius;
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+void main()
+  {
+  vec2 tex;
+  vec4 pixel = vec4(0.0);
+  float denom = 1.0 / ((2.0*u_Radius+1.0)*(2.0*u_Radius+1.0));
+
+  for (float x = -u_Radius; x <= u_Radius; x+=1.0)
+    for (float y = -u_Radius; y <= u_Radius; y+=1.0)
+      {
+      tex = vec2(v_TexCoordinate.x + x*one_over_objD.x, v_TexCoordinate.y + y*one_over_objD.y);
+      pixel += texture2D(u_Texture,tex)*denom;
+      }
+
+  gl_FragColor = pixel;
+  }
\ No newline at end of file
diff --git a/src/main/res/raw/blur_vertex_shader.glsl b/src/main/res/raw/blur_vertex_shader.glsl
new file mode 100644
index 0000000..8aa39a6
--- /dev/null
+++ b/src/main/res/raw/blur_vertex_shader.glsl
@@ -0,0 +1,36 @@
+//////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                          //
+//                                                                                          //
+// This file is part of Distorted.                                                          //
+//                                                                                          //
+// Distorted is free software: you can redistribute it and/or modify                        //
+// it under the terms of the GNU General Public License as published by                     //
+// the Free Software Foundation, either version 2 of the License, or                        //
+// (at your option) any later version.                                                      //
+//                                                                                          //
+// Distorted is distributed in the hope that it will be useful,                             //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                           //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                            //
+// GNU General Public License for more details.                                             //
+//                                                                                          //
+// You should have received a copy of the GNU General Public License                        // 
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+precision lowp float;
+
+uniform vec2 u_objD;             // object width X object height.
+uniform mat4 u_MVPMatrix;        // the combined model/view/projection matrix.
+
+attribute vec2 a_Position;       // Per-vertex position information we will pass in.
+attribute vec2 a_TexCoordinate;  // Per-vertex texture coordinate information we will pass in.
+varying   vec2 v_TexCoordinate;  //
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+// empty 2D vertex shader for postprocessing
+
+void main()
+  {
+  v_TexCoordinate = a_TexCoordinate;
+  gl_Position     = u_MVPMatrix*vec4( u_objD*a_Position, 0.0, 1.0);
+  }
\ No newline at end of file
diff --git a/src/main/res/raw/post_fragment_shader.glsl b/src/main/res/raw/post_fragment_shader.glsl
deleted file mode 100644
index 231afa9..0000000
--- a/src/main/res/raw/post_fragment_shader.glsl
+++ /dev/null
@@ -1,65 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright 2016 Leszek Koltunski                                                          //
-//                                                                                          //
-// This file is part of Distorted.                                                          //
-//                                                                                          //
-// Distorted is free software: you can redistribute it and/or modify                        //
-// it under the terms of the GNU General Public License as published by                     //
-// the Free Software Foundation, either version 2 of the License, or                        //
-// (at your option) any later version.                                                      //
-//                                                                                          //
-// Distorted is distributed in the hope that it will be useful,                             //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of                           //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                            //
-// GNU General Public License for more details.                                             //
-//                                                                                          //
-// You should have received a copy of the GNU General Public License                        //
-// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
-//////////////////////////////////////////////////////////////////////////////////////////////
-
-precision lowp float;
-
-varying vec2 v_TexCoordinate;
-uniform sampler2D u_Texture;
-uniform vec2 u_objD;
-uniform int pNumEffects;                 // total number of postprocessing effects
-
-#if NUM_POSTPROCESS>0
-uniform int pType[NUM_POSTPROCESS];      // their types.
-uniform vec4 pUniforms[NUM_POSTPROCESS]; // i-th effect is 1 vec4: [i].
-
-//////////////////////////////////////////////////////////////////////////////////////////////
-// BLUR EFFECT
-
-void blur(out vec4 pixel,float radius)
-  {
-  pixel = vec4(0.0);
-
-  float blurSizeH = 1.0 / u_objD.x;
-  float blurSizeV = 1.0 / u_objD.y;
-  float denom     = 1.0 / ((2.0*radius+1.0)*(2.0*radius+1.0));
-
-  for (float x = -radius; x <= radius; x+=1.0)
-    for (float y = -radius; y <= radius; y+=1.0)
-      {
-      pixel += texture2D( u_Texture, vec2(v_TexCoordinate.x + x*blurSizeH, v_TexCoordinate.y + y*blurSizeV) ) *denom;
-      }
-  }
-
-#endif
-
-//////////////////////////////////////////////////////////////////////////////////////////////
-
-void main()
-  {
-  vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
-
-#if NUM_POSTPROCESS>0
-  for(int i=0; i<pNumEffects; i++)
-    {
-    if( pType[i]==BLUR ) blur(pixel,pUniforms[i].x);
-    }
-#endif
-
-  gl_FragColor = pixel;
-  }
\ No newline at end of file
diff --git a/src/main/res/raw/post_vertex_shader.glsl b/src/main/res/raw/post_vertex_shader.glsl
deleted file mode 100644
index 0b04ef8..0000000
--- a/src/main/res/raw/post_vertex_shader.glsl
+++ /dev/null
@@ -1,37 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright 2016 Leszek Koltunski                                                          //
-//                                                                                          //
-// This file is part of Distorted.                                                          //
-//                                                                                          //
-// Distorted is free software: you can redistribute it and/or modify                        //
-// it under the terms of the GNU General Public License as published by                     //
-// the Free Software Foundation, either version 2 of the License, or                        //
-// (at your option) any later version.                                                      //
-//                                                                                          //
-// Distorted is distributed in the hope that it will be useful,                             //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of                           //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                            //
-// GNU General Public License for more details.                                             //
-//                                                                                          //
-// You should have received a copy of the GNU General Public License                        // 
-// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
-//////////////////////////////////////////////////////////////////////////////////////////////
-
-precision lowp float;
-
-uniform vec2 u_objD;             // object width X object height.
-                                 // point (0,0) is the center of the object
-uniform mat4 u_MVPMatrix;        // the combined model/view/projection matrix.
-
-attribute vec2 a_Position;       // Per-vertex position information we will pass in.
-attribute vec2 a_TexCoordinate;  // Per-vertex texture coordinate information we will pass in.
-varying   vec2 v_TexCoordinate;  //
-
-//////////////////////////////////////////////////////////////////////////////////////////////
-// empty 2D vertex shader for postprocessing
-
-void main()
-  {
-  v_TexCoordinate = a_TexCoordinate;
-  gl_Position     = u_MVPMatrix*vec4( u_objD*a_Position, 0.0, 1.0);
-  }
\ No newline at end of file
