commit d58407a893c335d47a7a5c7b406d535c8d2cc589
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Oct 7 15:23:23 2021 +0200

    New postprocess effect 'Border' (not working yet) and adding it to the testing app 'Triblur'.

diff --git a/src/main/java/org/distorted/library/effect/EffectName.java b/src/main/java/org/distorted/library/effect/EffectName.java
index 7991ce5..67fe213 100644
--- a/src/main/java/org/distorted/library/effect/EffectName.java
+++ b/src/main/java/org/distorted/library/effect/EffectName.java
@@ -75,7 +75,9 @@ public enum EffectName
   SMOOTH_CONTRAST  ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectContrast.class   ),
 
   BLUR             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 2, 0,     0    , PostprocessEffectBlur.class    ),
-  GLOW             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 6, 0,     0    , PostprocessEffectGlow.class    );
+  GLOW             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 6, 0,     0    , PostprocessEffectGlow.class    ),
+  BORDER           ( EffectType.POSTPROCESS,new float[] {0.0f}           , 5, 0,     0    , PostprocessEffectBorder.class  ),
+  ;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffect.java b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
index a128dd7..2289cfa 100644
--- a/src/main/java/org/distorted/library/effect/PostprocessEffect.java
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
@@ -70,7 +70,7 @@ public abstract class PostprocessEffect extends Effect implements InternalMaster
 
   private static class Source
     {
-    private String mName, mVertexShader, mFragmentShader;
+    private final String mName, mVertexShader, mFragmentShader;
 
     Source(String name, String vertex, String fragment)
       {
@@ -81,7 +81,7 @@ public abstract class PostprocessEffect extends Effect implements InternalMaster
     }
 
   static ArrayList<DistortedProgram> mPrograms = new ArrayList<>();
-  private static ArrayList<Source> mSources = new ArrayList<>();
+  private final static ArrayList<Source> mSources = new ArrayList<>();
   private static int mNumSources = 0;
 
   private static class Job
@@ -96,7 +96,7 @@ public abstract class PostprocessEffect extends Effect implements InternalMaster
       }
     }
 
-  private ArrayList<Job> mJobs = new ArrayList<>();
+  private final ArrayList<Job> mJobs = new ArrayList<>();
   private int mQualityLevel;
 
   float mQualityScale;
@@ -141,11 +141,15 @@ public abstract class PostprocessEffect extends Effect implements InternalMaster
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
+ * At this moment the 'buffer' contains a) preprocessed object b) real object rendered 'on top' of
+ * the preprocessed one.
+ * Postprocess buffer. What this means exactly depends on the effect -
+ *
  * Only for use by the library itself.
  *
  * @y.exclude
  */
-  public abstract int apply(float[] uniforms, int index, DistortedFramebuffer buffer);
+  public abstract int postprocess(float[] uniforms, int index, DistortedFramebuffer buffer);
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
   /**
@@ -153,7 +157,7 @@ public abstract class PostprocessEffect extends Effect implements InternalMaster
    *
    * @y.exclude
    */
-  public abstract boolean getRender();
+  public abstract boolean getRenderDirectly();
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
   /**
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java b/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
index 4cf5b56..825c47c 100644
--- a/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
@@ -19,111 +19,15 @@
 
 package org.distorted.library.effect;
 
-import android.opengl.GLES30;
-
-import org.distorted.library.main.DistortedFramebuffer;
-import org.distorted.library.main.InternalRenderState;
-import org.distorted.library.program.DistortedProgram;
 import org.distorted.library.type.Data2D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Blur the Framebuffer.
  */
-public class PostprocessEffectBlur extends PostprocessEffect
+public class PostprocessEffectBlur extends PostprocessEffectBlurred
   {
-  private static final int MAX_RADIUS = 50;
-
-  private final Data2D mBlurHaloAndRadius;
-
-  private static final float[] GAUSSIAN =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
-    {                                       // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
-    0.398948f, 0.398769f, 0.398231f, 0.397336f, 0.396086f, 0.394485f, 0.392537f, 0.390247f, 0.387622f, 0.384668f,
-    0.381393f, 0.377806f, 0.373916f, 0.369733f, 0.365268f, 0.360532f, 0.355538f, 0.350297f, 0.344823f, 0.339129f,
-    0.333229f, 0.327138f, 0.320868f, 0.314436f, 0.307856f, 0.301142f, 0.294309f, 0.287373f, 0.280348f, 0.273248f,
-    0.266089f, 0.258884f, 0.251648f, 0.244394f, 0.237135f, 0.229886f, 0.222657f, 0.215461f, 0.208311f, 0.201217f,
-    0.194189f, 0.187238f, 0.180374f, 0.173605f, 0.166940f, 0.160386f, 0.153951f, 0.147641f, 0.141462f, 0.135420f,
-    0.129520f, 0.123765f, 0.118159f, 0.112706f, 0.107408f, 0.102266f, 0.097284f, 0.092461f, 0.087797f, 0.083294f,
-    0.078951f, 0.074767f, 0.070741f, 0.066872f, 0.063158f, 0.059596f, 0.056184f, 0.052920f, 0.049801f, 0.046823f,
-    0.043984f, 0.041280f, 0.038707f, 0.036262f, 0.033941f, 0.031740f, 0.029655f, 0.027682f, 0.025817f, 0.024056f,
-    0.022395f, 0.020830f, 0.019357f, 0.017971f, 0.016670f, 0.015450f, 0.014305f, 0.013234f, 0.012232f, 0.011295f,
-    0.010421f, 0.009606f, 0.008847f, 0.008140f, 0.007483f, 0.006873f, 0.006307f, 0.005782f, 0.005296f, 0.004847f,
-    0.004432f, 0.000000f
-    };
-  private static final int NUM_GAUSSIAN = GAUSSIAN.length-2;
-
-  // The (fixed-function-sampled) Gaussian Blur kernels are of the size k0=1, k1=2, k2=2, k3=3, k4=3, k5=4, k6=4,...
-  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
-  // in all 4 directions)
-  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
-  private static final float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
-  private static final float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
-  private static final float[] mWeights = new float[MAX_RADIUS];
-  private static final float[] mOffsets = new float[MAX_RADIUS];
-
-  private static DistortedProgram mProgram1, mProgram2;
-  private static int mIndex1, mIndex2;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Clean up of static variables on exit.
-// called by reflection from super class.
-
-  @SuppressWarnings("unused")
-  static void destroyStatics()
-    {
-    mProgram1 = null;
-    mProgram2 = null;
-
-    mIndex1 = 0;
-    mIndex2 = 0;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// This implements the 'Better separable implementation using GPU fixed function sampling' from
-// https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms
-
-  private void computeGaussianKernel(int radius)
-    {
-    int offset = radius + radius*radius/4;
-
-    if( weightsCache[offset]==0.0f )
-      {
-      float z, x= 0.0f, P= (float)NUM_GAUSSIAN / (radius>3 ? radius:3);
-      mWeights[0] = GAUSSIAN[0];
-      float sum   = GAUSSIAN[0];
-      int j;
-
-      for(int i=1; i<=radius; i++)
-        {
-        x += P;
-        j = (int)x;
-        z = x-j;
-
-        mWeights[i] = (1-z)*GAUSSIAN[j] + z*GAUSSIAN[j+1];
-        sum += 2*mWeights[i];
-        }
-
-      for(int i=0; i<=radius; i++) mWeights[i] /= sum;
-
-      int numloops = radius/2;
-      weightsCache[offset] = mWeights[0];
-      offsetsCache[offset] = 0.0f;
-
-      for(int i=0; i<numloops; i++)
-        {
-        offsetsCache[offset+i+1] = mWeights[2*i+1]*(2*i+1) + mWeights[2*i+2]*(2*i+2);
-        weightsCache[offset+i+1] = mWeights[2*i+1] + mWeights[2*i+2];
-        offsetsCache[offset+i+1]/= weightsCache[offset+i+1];
-        }
-
-      if( radius%2 == 1 )
-        {
-        int index = offset + radius/2 +1;
-        offsetsCache[index]=radius;
-        weightsCache[index]=mWeights[radius];
-        }
-      }
-    }
+  private final Data2D mHaloAndRadius;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -133,7 +37,7 @@ public class PostprocessEffectBlur extends PostprocessEffect
  */
   public boolean compute(float[] uniforms, int index, long currentDuration, long step )
     {
-    return mBlurHaloAndRadius.get(uniforms,index,currentDuration,step);
+    return mHaloAndRadius.get(uniforms,index,currentDuration,step);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -142,105 +46,11 @@ public class PostprocessEffectBlur extends PostprocessEffect
  *
  * @y.exclude
  */
-  public boolean getRender()
+  public boolean getRenderDirectly()
     {
     return false;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Only for use by the library itself.
- *
- * @y.exclude
- */
-  public int apply(float[] uniforms, int index, DistortedFramebuffer buffer)
-    {
-    if( mProgram1 ==null)
-      {
-      try
-        {
-        mProgram1 = mPrograms.get(mIndex1);
-        mProgram2 = mPrograms.get(mIndex2);
-        }
-      catch(Exception ex)
-        {
-        return 0;
-        }
-      }
-
-    InternalRenderState.useStencilMark();
-
-    buffer.setAsOutput();
-
-    float w= buffer.getWidth();
-    float h= buffer.getHeight();
-    float n= 1.0f - buffer.getNear();
-
-    float corrW = buffer.getWidthCorrection();
-    float corrH = buffer.getHeightCorrection();
-    float offsetCorrW = corrW/w;
-    float offsetCorrH = corrH/h;
-
-    int radius = (int)(uniforms[index+1]*mQualityScale);
-    if( radius>=MAX_RADIUS ) radius = MAX_RADIUS-1;
-    if( radius<=0          ) radius = 1;
-    computeGaussianKernel(radius);
-
-    int offset = radius + radius*radius/4;
-    radius = (radius+1)/2;
-    GLES30.glViewport(0, 0, (int)w, (int)h);
-
-    // horizontal blur
-    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrW;
-
-    mProgram1.useProgram();
-    buffer.bindForOutput(1);
-    buffer.setAsInput(0);
-
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
-
-    GLES30.glColorMask(true,true,true,true);
-    GLES30.glClearColor(1.0f,1.0f,1.0f,0.0f);
-    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
-
-    GLES30.glUniform1f ( mProgram1.mUniform[0] , n );
-    GLES30.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
-    GLES30.glUniform1i ( mProgram1.mUniform[2] , 0 );
-    GLES30.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
-    GLES30.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
-    GLES30.glUniform1i ( mProgram1.mUniform[5] , radius);
-    GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
-    GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
-    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
-
-    // vertical blur
-    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH;
-
-    mProgram2.useProgram();
-    buffer.bindForOutput(0);
-    buffer.setAsInput(1);
-
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
-
-    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
-
-    GLES30.glUniform1f ( mProgram2.mUniform[0] , n );
-    GLES30.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
-    GLES30.glUniform1i ( mProgram2.mUniform[2] , 0 );
-    GLES30.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
-    GLES30.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
-    GLES30.glUniform1i ( mProgram2.mUniform[5] , radius);
-    GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
-    GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
-    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
-
-    InternalRenderState.unuseStencilMark();
-
-    return 2;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -249,88 +59,37 @@ public class PostprocessEffectBlur extends PostprocessEffect
  */
   public static void enable()
     {
-    final String blurVertex =
-
-      "precision lowp float;  \n"+
-      "in vec2 a_Position;    \n"+
-      "in vec2 a_TexCoord;    \n"+
-      "out vec2 v_TexCoord;   \n"+
-      "uniform float u_Depth; \n"+
-      "uniform vec2 u_TexCorr;\n"+
-
-      "void main()                                      \n"+
-      "  {                                              \n"+
-      "  v_TexCoord = a_TexCoord * u_TexCorr;           \n"+
-      "  gl_Position= vec4(2.0*a_Position,u_Depth,1.0); \n"+
-      "  }";
-
-    final String blurFragment1 =
-
-      "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
-      "precision lowp float;              \n"+
-      "in vec2 v_TexCoord;                \n"+
-      "out vec4 fragColor;                \n"+
-      "uniform sampler2D u_ColorTexture;  \n"+
-      "uniform float u_Offsets[MAX_BLUR]; \n"+
-      "uniform float u_Weights[MAX_BLUR]; \n"+
-      "uniform int u_Radius;              \n"+
-
-      "void main()                                                                                           \n"+
-      "  {                                                                                                   \n"+
-      "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
-      "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
-      "    {                                                                                                 \n"+
-      "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x+u_Offsets[i],v_TexCoord.y)) +                 \n"+
-      "               texture(u_ColorTexture,vec2(v_TexCoord.x-u_Offsets[i],v_TexCoord.y)) ) * u_Weights[i]; \n"+
-      "    }                                                                                                 \n"+
-      "  fragColor = pixel;                                                                                  \n"+
-      "  }";
-
-    final String blurFragment2 =
-
-      "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
-      "precision lowp float;              \n"+
-      "in vec2 v_TexCoord;                \n"+
-      "out vec4 fragColor;                \n"+
-      "uniform sampler2D u_ColorTexture;  \n"+
-      "uniform float u_Offsets[MAX_BLUR]; \n"+
-      "uniform float u_Weights[MAX_BLUR]; \n"+
-      "uniform int u_Radius;              \n"+
+    PostprocessEffectBlurred.enable("BLUR1","BLUR2");
+    }
 
-      "void main()                                                                                           \n"+
-      "  {                                                                                                   \n"+
-      "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
-      "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
-      "    {                                                                                                 \n"+
-      "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y+u_Offsets[i])) +                 \n"+
-      "               texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y-u_Offsets[i])) ) * u_Weights[i]; \n"+
-      "    }                                                                                                 \n"+
-      "  fragColor = pixel;                                                                                  \n"+
-      "  }";
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Clean up of static variables on exit. Called by reflection from super class.
 
-    mIndex1 = PostprocessEffect.register("BLUR1", blurVertex,blurFragment1);
-    mIndex2 = PostprocessEffect.register("BLUR2", blurVertex,blurFragment2);
+  @SuppressWarnings("unused")
+  static void destroyStatics()
+    {
+    PostprocessEffectBlurred.destroyStatics();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Blur the Framebuffer.
  *
- * @param blurHaloAndRadius First float: the halo.
- *                          How far beyond the object does the effect stretch to? Unit: Percentage
- *                          of the size of the original object, i.e. Halo=0 --> no halo around, this
- *                          would mean sharp edges around the object; Halo=100 --> halo of the size
- *                          of the object itself around (in case of blur, this would be - in vast
- *                          majority of cases except an object rendered very closely to the near plane-
- *                          an overkill).
- *                          Second float: the radius.
- *                          The 'strength' if the blur of the edges, in pixels. 0 = no blur, 10 =
- *                          blur of roughly 10 pixels around the whole halo.
+ * @param haloAndRadius First float: the halo.
+ *                      How far beyond the object does the effect stretch to? Unit: Percentage
+ *                      of the size of the original object, i.e. Halo=0 --> no halo around, this
+ *                      would mean sharp edges around the object; Halo=100 --> halo of the size
+ *                      of the object itself around (in case of blur, this would be - in vast
+ *                      majority of cases except an object rendered very closely to the near plane-
+ *                      an overkill).
+ *                      Second float: the radius.
+ *                      The 'strength' if the blur of the edges, in pixels. 0 = no blur, 10 =
+ *                      blur of roughly 10 pixels around the whole halo.
 
  */
-  public PostprocessEffectBlur(Data2D blurHaloAndRadius)
+  public PostprocessEffectBlur(Data2D haloAndRadius)
     {
     super(EffectName.BLUR);
-    mBlurHaloAndRadius = blurHaloAndRadius;
+    mHaloAndRadius = haloAndRadius;
     }
   }
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffectBlurred.java b/src/main/java/org/distorted/library/effect/PostprocessEffectBlurred.java
new file mode 100644
index 0000000..33df079
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffectBlurred.java
@@ -0,0 +1,296 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2017 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/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+import android.opengl.GLES30;
+
+import org.distorted.library.main.DistortedFramebuffer;
+import org.distorted.library.main.InternalRenderState;
+import org.distorted.library.program.DistortedProgram;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Postprocessed effect in which postprocessing is a Gaussian blur - i.e. Blur or Glow.
+ */
+abstract public class PostprocessEffectBlurred extends PostprocessEffect
+  {
+  private static final int MAX_RADIUS = 50;
+
+  private static final float[] GAUSSIAN =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
+    {                                       // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
+    0.398948f, 0.398769f, 0.398231f, 0.397336f, 0.396086f, 0.394485f, 0.392537f, 0.390247f, 0.387622f, 0.384668f,
+    0.381393f, 0.377806f, 0.373916f, 0.369733f, 0.365268f, 0.360532f, 0.355538f, 0.350297f, 0.344823f, 0.339129f,
+    0.333229f, 0.327138f, 0.320868f, 0.314436f, 0.307856f, 0.301142f, 0.294309f, 0.287373f, 0.280348f, 0.273248f,
+    0.266089f, 0.258884f, 0.251648f, 0.244394f, 0.237135f, 0.229886f, 0.222657f, 0.215461f, 0.208311f, 0.201217f,
+    0.194189f, 0.187238f, 0.180374f, 0.173605f, 0.166940f, 0.160386f, 0.153951f, 0.147641f, 0.141462f, 0.135420f,
+    0.129520f, 0.123765f, 0.118159f, 0.112706f, 0.107408f, 0.102266f, 0.097284f, 0.092461f, 0.087797f, 0.083294f,
+    0.078951f, 0.074767f, 0.070741f, 0.066872f, 0.063158f, 0.059596f, 0.056184f, 0.052920f, 0.049801f, 0.046823f,
+    0.043984f, 0.041280f, 0.038707f, 0.036262f, 0.033941f, 0.031740f, 0.029655f, 0.027682f, 0.025817f, 0.024056f,
+    0.022395f, 0.020830f, 0.019357f, 0.017971f, 0.016670f, 0.015450f, 0.014305f, 0.013234f, 0.012232f, 0.011295f,
+    0.010421f, 0.009606f, 0.008847f, 0.008140f, 0.007483f, 0.006873f, 0.006307f, 0.005782f, 0.005296f, 0.004847f,
+    0.004432f, 0.000000f
+    };
+  private static final int NUM_GAUSSIAN = GAUSSIAN.length-2;
+
+  // The (fixed-function-sampled) Gaussian Blur kernels are of the size k0=1, k1=2, k2=2, k3=3, k4=3, k5=4, k6=4,...
+  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
+  // in all 4 directions)
+  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
+  private static final float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
+  private static final float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
+  private static final float[] mWeights = new float[MAX_RADIUS];
+  private static final float[] mOffsets = new float[MAX_RADIUS];
+
+  private static DistortedProgram mProgram1, mProgram2;
+  private static int mIndex1, mIndex2;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static void destroyStatics()
+    {
+    mProgram1 = null;
+    mProgram2 = null;
+
+    mIndex1 = 0;
+    mIndex2 = 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// This implements the 'Better separable implementation using GPU fixed function sampling' from
+// https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms
+
+  private void computeGaussianKernel(int radius)
+    {
+    int offset = radius + radius*radius/4;
+
+    if( weightsCache[offset]==0.0f )
+      {
+      float z, x= 0.0f, P= (float)NUM_GAUSSIAN / (radius>3 ? radius:3);
+      mWeights[0] = GAUSSIAN[0];
+      float sum   = GAUSSIAN[0];
+      int j;
+
+      for(int i=1; i<=radius; i++)
+        {
+        x += P;
+        j = (int)x;
+        z = x-j;
+
+        mWeights[i] = (1-z)*GAUSSIAN[j] + z*GAUSSIAN[j+1];
+        sum += 2*mWeights[i];
+        }
+
+      for(int i=0; i<=radius; i++) mWeights[i] /= sum;
+
+      int numloops = radius/2;
+      weightsCache[offset] = mWeights[0];
+      offsetsCache[offset] = 0.0f;
+
+      for(int i=0; i<numloops; i++)
+        {
+        offsetsCache[offset+i+1] = mWeights[2*i+1]*(2*i+1) + mWeights[2*i+2]*(2*i+2);
+        weightsCache[offset+i+1] = mWeights[2*i+1] + mWeights[2*i+2];
+        offsetsCache[offset+i+1]/= weightsCache[offset+i+1];
+        }
+
+      if( radius%2 == 1 )
+        {
+        int index = offset + radius/2 +1;
+        offsetsCache[index]=radius;
+        weightsCache[index]=mWeights[radius];
+        }
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Only for use by the library itself.
+ *
+ * @y.exclude
+ */
+  public int postprocess(float[] uniforms, int index, DistortedFramebuffer buffer)
+    {
+    if( mProgram1 ==null)
+      {
+      try
+        {
+        mProgram1 = mPrograms.get(mIndex1);
+        mProgram2 = mPrograms.get(mIndex2);
+        }
+      catch(Exception ex)
+        {
+        return 0;
+        }
+      }
+
+    InternalRenderState.useStencilMark();
+
+    buffer.setAsOutput();
+
+    float w= buffer.getWidth();
+    float h= buffer.getHeight();
+    float n= 1.0f - buffer.getNear();
+
+    float corrW = buffer.getWidthCorrection();
+    float corrH = buffer.getHeightCorrection();
+    float offsetCorrW = corrW/w;
+    float offsetCorrH = corrH/h;
+
+    int radius = (int)(uniforms[index+1]*mQualityScale);
+    if( radius>=MAX_RADIUS ) radius = MAX_RADIUS-1;
+    if( radius<=0          ) radius = 1;
+    computeGaussianKernel(radius);
+
+    int offset = radius + radius*radius/4;
+    radius = (radius+1)/2;
+    GLES30.glViewport(0, 0, (int)w, (int)h);
+
+    // horizontal blur
+    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrW;
+
+    mProgram1.useProgram();
+    buffer.bindForOutput(1);
+    buffer.setAsInput(0);
+
+    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
+    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
+
+    GLES30.glColorMask(true,true,true,true);
+    GLES30.glClearColor(1.0f,1.0f,1.0f,0.0f);
+    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
+
+    GLES30.glUniform1f ( mProgram1.mUniform[0] , n );
+    GLES30.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
+    GLES30.glUniform1i ( mProgram1.mUniform[2] , 0 );
+    GLES30.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
+    GLES30.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
+    GLES30.glUniform1i ( mProgram1.mUniform[5] , radius);
+    GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
+    GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
+    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
+
+    // vertical blur
+    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH;
+
+    mProgram2.useProgram();
+    buffer.bindForOutput(0);
+    buffer.setAsInput(1);
+
+    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
+    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
+
+    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
+
+    GLES30.glUniform1f ( mProgram2.mUniform[0] , n );
+    GLES30.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
+    GLES30.glUniform1i ( mProgram2.mUniform[2] , 0 );
+    GLES30.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
+    GLES30.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
+    GLES30.glUniform1i ( mProgram2.mUniform[5] , radius);
+    GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
+    GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
+    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
+
+    InternalRenderState.unuseStencilMark();
+
+    return 2;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
+ */
+  public static void enable(String prog1, String prog2)
+    {
+    final String vertex =
+
+      "precision lowp float;  \n"+
+      "in vec2 a_Position;    \n"+
+      "in vec2 a_TexCoord;    \n"+
+      "out vec2 v_TexCoord;   \n"+
+      "uniform float u_Depth; \n"+
+      "uniform vec2 u_TexCorr;\n"+
+
+      "void main()                                      \n"+
+      "  {                                              \n"+
+      "  v_TexCoord = a_TexCoord * u_TexCorr;           \n"+
+      "  gl_Position= vec4(2.0*a_Position,u_Depth,1.0); \n"+
+      "  }";
+
+    final String fragment1 =
+
+      "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
+      "precision lowp float;              \n"+
+      "in vec2 v_TexCoord;                \n"+
+      "out vec4 fragColor;                \n"+
+      "uniform sampler2D u_ColorTexture;  \n"+
+      "uniform float u_Offsets[MAX_BLUR]; \n"+
+      "uniform float u_Weights[MAX_BLUR]; \n"+
+      "uniform int u_Radius;              \n"+
+
+      "void main()                                                                                           \n"+
+      "  {                                                                                                   \n"+
+      "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
+      "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
+      "    {                                                                                                 \n"+
+      "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x+u_Offsets[i],v_TexCoord.y)) +                 \n"+
+      "               texture(u_ColorTexture,vec2(v_TexCoord.x-u_Offsets[i],v_TexCoord.y)) ) * u_Weights[i]; \n"+
+      "    }                                                                                                 \n"+
+      "  fragColor = pixel;                                                                                  \n"+
+      "  }";
+
+    final String fragment2 =
+
+      "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
+      "precision lowp float;              \n"+
+      "in vec2 v_TexCoord;                \n"+
+      "out vec4 fragColor;                \n"+
+      "uniform sampler2D u_ColorTexture;  \n"+
+      "uniform float u_Offsets[MAX_BLUR]; \n"+
+      "uniform float u_Weights[MAX_BLUR]; \n"+
+      "uniform int u_Radius;              \n"+
+
+      "void main()                                                                                           \n"+
+      "  {                                                                                                   \n"+
+      "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
+      "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
+      "    {                                                                                                 \n"+
+      "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y+u_Offsets[i])) +                 \n"+
+      "               texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y-u_Offsets[i])) ) * u_Weights[i]; \n"+
+      "    }                                                                                                 \n"+
+      "  fragColor = pixel;                                                                                  \n"+
+      "  }";
+
+    mIndex1 = PostprocessEffect.register(prog1, vertex,fragment1);
+    mIndex2 = PostprocessEffect.register(prog2, vertex,fragment2);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Default constructor.
+ */
+  public PostprocessEffectBlurred(EffectName name)
+    {
+    super(name);
+    }
+  }
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffectBorder.java b/src/main/java/org/distorted/library/effect/PostprocessEffectBorder.java
new file mode 100644
index 0000000..ef65894
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffectBorder.java
@@ -0,0 +1,109 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2021 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/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+import org.distorted.library.main.DistortedFramebuffer;
+import org.distorted.library.type.Data1D;
+import org.distorted.library.type.Data4D;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Similar effect to Glow, but this one is not blurred and it's entirely behind the object.
+ */
+public class PostprocessEffectBorder extends PostprocessEffect
+  {
+  private final Data1D mHalo;
+  private final Data4D mColor;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Clean up of static variables on exit. Called by reflection from super class.
+
+  @SuppressWarnings("unused")
+  static void destroyStatics()
+    {
+
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Only for use by the library itself.
+ *
+ * @y.exclude
+ */
+  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
+    {
+    mColor.get(uniforms,index+1,currentDuration,step);
+    return mHalo.get(uniforms,index,currentDuration,step);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Only for use by the library itself.
+ *
+ * @y.exclude
+ */
+  public boolean getRenderDirectly()
+    {
+    return true;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Only for use by the library itself.
+ *
+ * @y.exclude
+ */
+  public int postprocess(float[] uniforms, int index, DistortedFramebuffer buffer)
+    {
+    return 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * No local programs; we do not postprocess anything here. No need to do anything
+ */
+  public static void enable()
+    {
+
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Draw a sharp 'border' around the object. Unlike 'GLOW', the border is entirely around the object
+ * and not in front of it.
+ *
+ * @param halo   How far beyond the object does the effect stretch to? Unit: Percentage of the size
+ *               of the original object, i.e. halo=0 --> no effect at all, halo=100 --> border of
+ *               size of the object itself.
+ *
+ * @param color  RGBA of the color with which to draw the border; example: (1.0f,0.0f,0.0f,0.5f) -
+ *               half transparent red.
+ */
+  public PostprocessEffectBorder(Data1D halo, Data4D color)
+    {
+    super(EffectName.BORDER);
+
+    mHalo = halo;
+    mColor= color;
+    }
+  }
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java b/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
index 0230f83..7022628 100644
--- a/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
@@ -19,11 +19,6 @@
 
 package org.distorted.library.effect;
 
-import android.opengl.GLES30;
-
-import org.distorted.library.main.DistortedFramebuffer;
-import org.distorted.library.main.InternalRenderState;
-import org.distorted.library.program.DistortedProgram;
 import org.distorted.library.type.Data2D;
 import org.distorted.library.type.Data4D;
 
@@ -31,102 +26,11 @@ import org.distorted.library.type.Data4D;
 /**
  * Add a (colored) glow around an object.
  */
-public class PostprocessEffectGlow extends PostprocessEffect
+public class PostprocessEffectGlow extends PostprocessEffectBlurred
   {
-  private static final int MAX_RADIUS = 50;
-
-  private final Data2D mGlowHaloAndRadius;
+  private final Data2D mHaloAndRadius;
   private final Data4D mColor;
 
-  private static final float[] GAUSSIAN =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
-    {                                       // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
-    0.398948f, 0.398769f, 0.398231f, 0.397336f, 0.396086f, 0.394485f, 0.392537f, 0.390247f, 0.387622f, 0.384668f,
-    0.381393f, 0.377806f, 0.373916f, 0.369733f, 0.365268f, 0.360532f, 0.355538f, 0.350297f, 0.344823f, 0.339129f,
-    0.333229f, 0.327138f, 0.320868f, 0.314436f, 0.307856f, 0.301142f, 0.294309f, 0.287373f, 0.280348f, 0.273248f,
-    0.266089f, 0.258884f, 0.251648f, 0.244394f, 0.237135f, 0.229886f, 0.222657f, 0.215461f, 0.208311f, 0.201217f,
-    0.194189f, 0.187238f, 0.180374f, 0.173605f, 0.166940f, 0.160386f, 0.153951f, 0.147641f, 0.141462f, 0.135420f,
-    0.129520f, 0.123765f, 0.118159f, 0.112706f, 0.107408f, 0.102266f, 0.097284f, 0.092461f, 0.087797f, 0.083294f,
-    0.078951f, 0.074767f, 0.070741f, 0.066872f, 0.063158f, 0.059596f, 0.056184f, 0.052920f, 0.049801f, 0.046823f,
-    0.043984f, 0.041280f, 0.038707f, 0.036262f, 0.033941f, 0.031740f, 0.029655f, 0.027682f, 0.025817f, 0.024056f,
-    0.022395f, 0.020830f, 0.019357f, 0.017971f, 0.016670f, 0.015450f, 0.014305f, 0.013234f, 0.012232f, 0.011295f,
-    0.010421f, 0.009606f, 0.008847f, 0.008140f, 0.007483f, 0.006873f, 0.006307f, 0.005782f, 0.005296f, 0.004847f,
-    0.004432f, 0.000000f
-    };
-  private static final int NUM_GAUSSIAN = GAUSSIAN.length-2;
-
-  // The (fixed-function-sampled) Gaussian Blur kernels are of the size k0=1, k1=2, k2=2, k3=3, k4=3, k5=4, k6=4,...
-  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
-  // in all 4 directions)
-  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
-  private static final float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
-  private static final float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
-  private static final float[] mWeights = new float[MAX_RADIUS];
-  private static final float[] mOffsets = new float[MAX_RADIUS];
-
-  private static DistortedProgram mProgram1, mProgram2;
-  private static int mIndex1, mIndex2;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Clean up of static variables on exit.
-// called by reflection from super class.
-
-  @SuppressWarnings("unused")
-  static void destroyStatics()
-    {
-    mProgram1 = null;
-    mProgram2 = null;
-
-    mIndex1 = 0;
-    mIndex2 = 0;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// This implements the 'Better separable implementation using GPU fixed function sampling' from
-// https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms
-
-  private void computeGaussianKernel(int radius)
-    {
-    int offset = radius + radius*radius/4;
-
-    if( weightsCache[offset]==0.0f )
-      {
-      float z, x= 0.0f, P= (float)NUM_GAUSSIAN / (radius>3 ? radius:3);
-      mWeights[0] = GAUSSIAN[0];
-      float sum   = GAUSSIAN[0];
-      int j;
-
-      for(int i=1; i<=radius; i++)
-        {
-        x += P;
-        j = (int)x;
-        z = x-j;
-
-        mWeights[i] = (1-z)*GAUSSIAN[j] + z*GAUSSIAN[j+1];
-        sum += 2*mWeights[i];
-        }
-
-      for(int i=0; i<=radius; i++) mWeights[i] /= sum;
-
-      int numloops = radius/2;
-      weightsCache[offset] = mWeights[0];
-      offsetsCache[offset] = 0.0f;
-
-      for(int i=0; i<numloops; i++)
-        {
-        offsetsCache[offset+i+1] = mWeights[2*i+1]*(2*i+1) + mWeights[2*i+2]*(2*i+2);
-        weightsCache[offset+i+1] = mWeights[2*i+1] + mWeights[2*i+2];
-        offsetsCache[offset+i+1]/= weightsCache[offset+i+1];
-        }
-
-      if( radius%2 == 1 )
-        {
-        int index = offset + radius/2 +1;
-        offsetsCache[index]=radius;
-        weightsCache[index]=mWeights[radius];
-        }
-      }
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Only for use by the library itself.
@@ -136,7 +40,7 @@ public class PostprocessEffectGlow extends PostprocessEffect
   public boolean compute(float[] uniforms, int index, long currentDuration, long step )
     {
     mColor.get(uniforms,index+2,currentDuration,step);
-    return mGlowHaloAndRadius.get(uniforms,index,currentDuration,step);
+    return mHaloAndRadius.get(uniforms,index,currentDuration,step);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -145,105 +49,11 @@ public class PostprocessEffectGlow extends PostprocessEffect
  *
  * @y.exclude
  */
-  public boolean getRender()
+  public boolean getRenderDirectly()
     {
     return true;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Only for use by the library itself.
- *
- * @y.exclude
- */
-  public int apply(float[] uniforms, int index, DistortedFramebuffer buffer)
-    {
-    if( mProgram1 ==null)
-      {
-      try
-        {
-        mProgram1 = mPrograms.get(mIndex1);
-        mProgram2 = mPrograms.get(mIndex2);
-        }
-      catch(Exception ex)
-        {
-        return 0;
-        }
-      }
-
-    InternalRenderState.useStencilMark();
-
-    buffer.setAsOutput();
-
-    float w= buffer.getWidth();
-    float h= buffer.getHeight();
-    float n= 1.0f - buffer.getNear();
-
-    float corrW = buffer.getWidthCorrection();
-    float corrH = buffer.getHeightCorrection();
-    float offsetCorrW = corrW/w;
-    float offsetCorrH = corrH/h;
-
-    int radius = (int)(uniforms[index+1]*mQualityScale);
-    if( radius>=MAX_RADIUS ) radius = MAX_RADIUS-1;
-    if( radius<=0          ) radius = 1;
-    computeGaussianKernel(radius);
-
-    int offset = radius + radius*radius/4;
-    radius = (radius+1)/2;
-    GLES30.glViewport(0, 0, (int)w, (int)h);
-
-    // horizontal blur
-    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrW;
-
-    mProgram1.useProgram();
-    buffer.bindForOutput(1);
-    buffer.setAsInput(0);
-
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
-
-    GLES30.glColorMask(true,true,true,true);
-    GLES30.glClearColor(1.0f,1.0f,1.0f,0.0f);
-    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
-
-    GLES30.glUniform1f ( mProgram1.mUniform[0] , n );
-    GLES30.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
-    GLES30.glUniform1i ( mProgram1.mUniform[2] , 0 );
-    GLES30.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
-    GLES30.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
-    GLES30.glUniform1i ( mProgram1.mUniform[5] , radius);
-    GLES30.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
-    GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
-    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
-
-    // vertical blur
-    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH;
-
-    mProgram2.useProgram();
-    buffer.bindForOutput(0);
-    buffer.setAsInput(1);
-
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
-    GLES30.glTexParameteri( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
-
-    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
-
-    GLES30.glUniform1f ( mProgram2.mUniform[0] , n );
-    GLES30.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
-    GLES30.glUniform1i ( mProgram2.mUniform[2] , 0 );
-    GLES30.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
-    GLES30.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
-    GLES30.glUniform1i ( mProgram2.mUniform[5] , radius);
-    GLES30.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
-    GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
-    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
-
-    InternalRenderState.unuseStencilMark();
-
-    return 2;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -252,89 +62,38 @@ public class PostprocessEffectGlow extends PostprocessEffect
  */
   public static void enable()
     {
-    final String glowVertex =
-
-            "precision lowp float;  \n"+
-            "in vec2 a_Position;    \n"+
-            "in vec2 a_TexCoord;    \n"+
-            "out vec2 v_TexCoord;   \n"+
-            "uniform float u_Depth; \n"+
-            "uniform vec2 u_TexCorr;\n"+
-
-            "void main()                                      \n"+
-            "  {                                              \n"+
-            "  v_TexCoord = a_TexCoord * u_TexCorr;           \n"+
-            "  gl_Position= vec4(2.0*a_Position,u_Depth,1.0); \n"+
-            "  }";
-
-    final String glowFragment1 =
-
-            "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
-            "precision lowp float;              \n"+
-            "in vec2 v_TexCoord;                \n"+
-            "out vec4 fragColor;                \n"+
-            "uniform sampler2D u_ColorTexture;  \n"+
-            "uniform float u_Offsets[MAX_BLUR]; \n"+
-            "uniform float u_Weights[MAX_BLUR]; \n"+
-            "uniform int u_Radius;              \n"+
-
-            "void main()                                                                                           \n"+
-            "  {                                                                                                   \n"+
-            "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
-            "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
-            "    {                                                                                                 \n"+
-            "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x+u_Offsets[i],v_TexCoord.y)) +                 \n"+
-            "               texture(u_ColorTexture,vec2(v_TexCoord.x-u_Offsets[i],v_TexCoord.y)) ) * u_Weights[i]; \n"+
-            "    }                                                                                                 \n"+
-            "  fragColor = pixel;                                                                                  \n"+
-            "  }";
-
-    final String glowFragment2 =
-
-            "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
-            "precision lowp float;              \n"+
-            "in vec2 v_TexCoord;                \n"+
-            "out vec4 fragColor;                \n"+
-            "uniform sampler2D u_ColorTexture;  \n"+
-            "uniform float u_Offsets[MAX_BLUR]; \n"+
-            "uniform float u_Weights[MAX_BLUR]; \n"+
-            "uniform int u_Radius;              \n"+
+    PostprocessEffectBlurred.enable("GLOW1","GLOW2");
+    }
 
-            "void main()                                                                                           \n"+
-            "  {                                                                                                   \n"+
-            "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
-            "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
-            "    {                                                                                                 \n"+
-            "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y+u_Offsets[i])) +                 \n"+
-            "               texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y-u_Offsets[i])) ) * u_Weights[i]; \n"+
-            "    }                                                                                                 \n"+
-            "  fragColor = pixel;                                                                                  \n"+
-            "  }";
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Clean up of static variables on exit. Called by reflection from super class.
 
-    mIndex1 = PostprocessEffect.register("GLOW1", glowVertex,glowFragment1);
-    mIndex2 = PostprocessEffect.register("GLOW2", glowVertex,glowFragment2);
+  @SuppressWarnings("unused")
+  static void destroyStatics()
+    {
+    PostprocessEffectBlurred.destroyStatics();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Make the object glow with a specific color and a halo of specific radius.
  *
- * @param glowHaloAndRadius First float: the halo.
- *                          How far beyond the object does the effect stretch to? Unit: Percentage
- *                          of the size of the original object, i.e. Halo=0 --> no halo around, this
- *                          would mean sharp edges around the object; Halo=100 --> halo of the size
- *                          of the object itself around.
- *                          Second float: the radius.
- *                          The 'strength' if the blur of the edges, in pixels. 0 = no blur, 10 =
- *                          blur of roughly 10 pixels around the whole halo.
- * @param color             RGBA of the color with which to draw the glow; example: (1.0f,0.0f,0.0f,0.5f) -
- *                          half transparent red.
+ * @param haloAndRadius First float: the halo.
+ *                      How far beyond the object does the effect stretch to? Unit: Percentage
+ *                      of the size of the original object, i.e. Halo=0 --> no halo around, this
+ *                      would mean sharp edges around the object; Halo=100 --> halo of the size
+ *                      of the object itself around.
+ *                      Second float: the radius.
+ *                      The 'strength' of the blur of the edges, in pixels. 0 = no blur, 10 =
+ *                      blur of roughly 10 pixels around the whole halo.
+ * @param color         RGBA of the color with which to draw the glow; example: (1.0f,0.0f,0.0f,0.5f) -
+ *                      half transparent red.
  */
-  public PostprocessEffectGlow(Data2D glowHaloAndRadius, Data4D color)
+  public PostprocessEffectGlow(Data2D haloAndRadius, Data4D color)
     {
     super(EffectName.GLOW);
 
-    mGlowHaloAndRadius = glowHaloAndRadius;
-    mColor             = color;
+    mHaloAndRadius = haloAndRadius;
+    mColor         = color;
     }
   }
diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java b/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
index 57d46a7..d149012 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
@@ -156,9 +156,9 @@ public class EffectQueuePostprocess extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // TODO  (now only really works in case of 1 effect!)
 
-  public boolean getRender()
+  public boolean getRenderDirectly()
     {
-    return mNumEffects > 0 && ((PostprocessEffect) mEffects[0]).getRender();
+    return mNumEffects > 0 && ((PostprocessEffect) mEffects[0]).getRenderDirectly();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -213,7 +213,7 @@ public class EffectQueuePostprocess extends EffectQueue
 
     for(int i=0; i<mNumEffects; i++)
       {
-      numRenders += ((PostprocessEffect)mEffects[i]).apply(array,NUM_FLOAT_UNIFORMS*i, buffer);
+      numRenders += ((PostprocessEffect)mEffects[i]).postprocess(array,NUM_FLOAT_UNIFORMS*i, buffer);
       }
 
     GLES30.glEnable(GLES30.GL_BLEND);
diff --git a/src/main/java/org/distorted/library/main/InternalOutputSurface.java b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
index e6cd73e..2b2a964 100644
--- a/src/main/java/org/distorted/library/main/InternalOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
@@ -43,16 +43,16 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
   static final float DEFAULT_NEAR=  0.1f;
 
   private float mFOV;
-  private int mTmpFBO;
+  private final int mTmpFBO;
 
   private long[] mTime;
   private float mClearR, mClearG, mClearB, mClearA, mClearDepth;
   private int mClear, mClearStencil;
   private boolean mRenderWayOIT;
-  private InternalChildrenList mChildren;
+  private final InternalChildrenList mChildren;
 
   // Global buffers used for postprocessing
-  private static DistortedFramebuffer[] mBuffer= new DistortedFramebuffer[EffectQuality.LENGTH];
+  private final static DistortedFramebuffer[] mBuffer= new DistortedFramebuffer[EffectQuality.LENGTH];
 
   float mDistance, mNear, mMipmap;
   float[] mProjectionMatrix;
@@ -456,7 +456,7 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
 
           buffer= mBuffer[currQuality];
           bucketChange= i;
-          renderDirectly = currQueue.getRender();
+          renderDirectly = currQueue.getRenderDirectly();
           }
 
         if( renderDirectly )
