commit 8e88389e2671022c3c233c627e4331ce3b3e5ee9
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Dec 7 11:56:22 2018 +0000

    Translate the size of the Halo around postprocessed objects from 'number pixels around the object' (as held in the Effects themselves) to a float suitable for Inflating the underlying Mesh with the per-vertex Inflate vectors.

diff --git a/src/main/java/org/distorted/library/main/DistortedEffects.java b/src/main/java/org/distorted/library/main/DistortedEffects.java
index 8a6e0e1..d6bef07 100644
--- a/src/main/java/org/distorted/library/main/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/main/DistortedEffects.java
@@ -445,9 +445,17 @@ public class DistortedEffects
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  void send(float halfW, float halfH, float halfZ, float inflate, DistortedOutputSurface surface, int variant)
+  void send(float halfX, float halfY, float halfZ, float marginInPixels, DistortedOutputSurface surface, int variant)
     {
-    mM.send(surface,halfW,halfH,halfZ,variant);
+    float inflate=0.0f;
+
+    mM.send(surface,halfX,halfY,halfZ,variant);
+
+    if( marginInPixels!=0.0f )
+      {
+      inflate = mM.magnify(surface,halfX,halfY,halfZ,marginInPixels);
+      }
+
     mV.send(inflate,variant);
     }
 
diff --git a/src/main/java/org/distorted/library/main/EffectQueueMatrix.java b/src/main/java/org/distorted/library/main/EffectQueueMatrix.java
index 3a27e56..3d77f16 100644
--- a/src/main/java/org/distorted/library/main/EffectQueueMatrix.java
+++ b/src/main/java/org/distorted/library/main/EffectQueueMatrix.java
@@ -41,6 +41,11 @@ class EffectQueueMatrix extends EffectQueue
   private static int[] mMVPMatrixH = new int[Distorted.MAIN_VARIANTS];
   private static int[] mMVMatrixH  = new int[Distorted.MAIN_VARIANTS];
 
+  private static float[] mTmpMatrix = new float[16];
+  private static float[] mTmpResult = new float[4];
+  private static float[] mTmpPoint  = new float[4];
+  private static float mMinX,mMaxX,mMinY,mMaxY;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
   EffectQueueMatrix(long id)
@@ -57,6 +62,57 @@ class EffectQueueMatrix extends EffectQueue
     mMVMatrixH[variant] = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix");
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void magnifyDir()
+    {
+    Matrix.multiplyMV(mTmpResult,0,mTmpMatrix,0,mTmpPoint,0);
+    float nx = mTmpResult[0]/mTmpResult[3];
+    float ny = mTmpResult[1]/mTmpResult[3];
+
+    if( nx<mMinX ) mMinX = nx;
+    if( nx>mMaxX ) mMaxX = nx;
+    if( ny<mMinY ) mMinY = ny;
+    if( ny>mMaxY ) mMaxY = ny;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return a float which describes how much larger an object must be so that it appears to be (about)
+// 'marginInPixels' pixels larger in each direction. Used in Postprocessing.
+
+  float magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
+    {
+    mMinX = Integer.MAX_VALUE;
+    mMaxX = Integer.MIN_VALUE;
+    mMinY = Integer.MAX_VALUE;
+    mMaxY = Integer.MIN_VALUE;
+
+    mTmpPoint[3] = 1.0f;
+
+    Matrix.multiplyMM(mTmpMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
+
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+
+    float xLenInPixels = projection.mWidth *(mMaxX-mMinX)/2;
+    float yLenInPixels = projection.mHeight*(mMaxY-mMinY)/2;
+
+    // already margin / min(xLen,yLen) is the size of the halo.
+    // Here we need a bit more because we are marking not only the halo, but a little bit around
+    // it as well so that the (blur for example) will be smooth on the edges. Thus the 2.0f.
+    //
+    // mMipmap ( 1.0 , 0.5, 0.25, 0.125 ) - we need to make the size of the halo independent
+    // of postprocessing effect quality.
+
+    return projection.mMipmap*2.0f*marginInPixels/( xLenInPixels>yLenInPixels ? yLenInPixels:xLenInPixels );
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   void compute(long currTime)
