commit c1f892eda1b0ff9c685f2c848679d6cfb4b78346
Author: leszek <leszek@koltunski.pl>
Date:   Fri Aug 4 00:45:07 2023 +0200

    New 'PIPE' vertex effect.

diff --git a/src/main/java/org/distorted/library/effect/EffectName.java b/src/main/java/org/distorted/library/effect/EffectName.java
index 538a5f4..a0cf0ee 100644
--- a/src/main/java/org/distorted/library/effect/EffectName.java
+++ b/src/main/java/org/distorted/library/effect/EffectName.java
@@ -57,6 +57,7 @@ public enum EffectName
   SWIRL            ( EffectType.VERTEX  ,   new float[] {0.0f}           , 1, 4,     3    , VertexEffectSwirl.class        ),
   WAVE             ( EffectType.VERTEX  ,   new float[] {0.0f}           , 5, 4,     3    , VertexEffectWave.class         ),
   DISAPPEAR        ( EffectType.VERTEX  ,   new float[] {}               , 0, 0,     0    , VertexEffectDisappear.class    ),
+  PIPE             ( EffectType.VERTEX  ,   new float[] {1,0f}           , 5, 0,     3    , VertexEffectPipe.class         ),
 
   VERTEX_MOVE      ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     0    , VertexEffectMove.class         ),
   VERTEX_QUATERNION( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 0,     3    , VertexEffectQuaternion.class   ),
diff --git a/src/main/java/org/distorted/library/effect/VertexEffectPipe.java b/src/main/java/org/distorted/library/effect/VertexEffectPipe.java
new file mode 100644
index 0000000..ddd3cf5
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/VertexEffectPipe.java
@@ -0,0 +1,117 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2023 Leszek Koltunski  leszek@koltunski.pl                                          //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// This library is free software; you can redistribute it and/or                                 //
+// modify it under the terms of the GNU Lesser General Public                                    //
+// License as published by the Free Software Foundation; either                                  //
+// version 2.1 of the License, or (at your option) any later version.                            //
+//                                                                                               //
+// This library 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                             //
+// Lesser General Public License for more details.                                               //
+//                                                                                               //
+// You should have received a copy of the GNU Lesser General Public                              //
+// License along with this library; if not, write to the Free Software                           //
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+import org.distorted.library.type.Data3D;
+import org.distorted.library.type.Data5D;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Pull all points around the center of the Effect towards the center point (if degree>=1) or push them
+ * away from it (degree<=1).
+ */
+public class VertexEffectPipe extends VertexEffect
+  {
+  private static final EffectName NAME = EffectName.PIPE;
+
+  private final Data5D mPipe;
+  private final Data3D mCenter;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Only for use by the library itself.
+ *
+ * @y.exclude
+ */
+  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
+    {
+    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
+    return mPipe.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// here, if one tests this with the 'Generic' examples app - and chooses the 'Cubes 3x3x3' mesh,
+// then adds an 'empty' PIPE effect - then two corners of the mesh turn bright.
+// It turns out this is because the points at those corners are very close to being on the
+// line defined by 'center' and 'vect' (so 'ps' is very small)
+// Then by means of some miracle we have
+// dot_ps>0, (sign_ps-1.0)==0.0 and dot_ps-(sign_ps-1.0) == 0.0 !! so n_ps - undef.
+
+  static String code()
+    {
+    return
+
+        "vec3 pc = vUniforms[effect+1].yzw - v;            \n"
+      + "vec3 vect = vUniforms[effect].yzw;                \n"
+      + "vec3 ps = pc - dot(pc,vect)*vect;                 \n"
+      + "float radius = vUniforms[effect+1].x;             \n"
+      + "float deg = max( 0.0, 1.0 - length(ps)/radius );  \n"
+
+      + "float h = vUniforms[effect].x;                    \n" // from this point on, having calculated
+      + "float tmp = (1.0-h)*deg;                          \n" // ps and deg, proceed just like in Sink
+      + "float t1 = tmp*(deg+1.0)/h;                       \n"
+      + "float t2 = tmp/(0.618*(0.618+deg));               \n"
+      + "float t = t2 + (t1-t2)*((sign(h-1.0)+1.0)/2.0);   \n"
+
+      + "v += t*ps;                                        \n"
+
+      + "const float A = 1.6;                              \n"
+      + "const float B = 10.0;                             \n"
+      + "vec3 n_ps = dot(ps,n)*ps;                         \n"
+      + "float dot_ps = dot(ps,ps);                        \n"
+      + "float sign_ps= sign(dot_ps);                      \n"
+      + "n_ps = (sign_ps*n_ps)/(dot_ps-(sign_ps-1.0));     \n"
+      + "float move = deg*(h-1.0)/(h/B+1.0/A);             \n"
+      + "n += move*n_ps;                                   \n"
+      + "n = normalize(n);";
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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()
+    {
+    addEffect(NAME, code() );
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Pull (degree>1) or push away from (degree<1) all points of an infinite 'pipe' shaped region. We
+ * pull (or push) each point in space towards a point in the center of the pipe which is closest to it.
+ * Points located outside of the pipe are not affected (thus this acts kind of like a 'region')
+ *
+ * @param pipe   5-dimensional data describing the effect and kind of including the region in it as well.
+ *               1st: the degree of pull (similar to the one in the sink effect)
+ *               (2nd,3rd,4th) -> the vector along which the 'pipe' points to.
+ *               5th: the radius of the pipe.
+ * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
+ */
+  public VertexEffectPipe(Data5D pipe, Data3D center)
+    {
+    super(NAME);
+    mPipe   = pipe;
+    mCenter = center;
+    }
+  }
diff --git a/src/main/java/org/distorted/library/effect/VertexEffectSink.java b/src/main/java/org/distorted/library/effect/VertexEffectSink.java
index 44e5e7b..4cd5967 100644
--- a/src/main/java/org/distorted/library/effect/VertexEffectSink.java
+++ b/src/main/java/org/distorted/library/effect/VertexEffectSink.java
@@ -62,8 +62,9 @@ public class VertexEffectSink extends VertexEffect
     return
 
         "vec3 ps = vUniforms[effect+1].yzw - v;            \n"
-      + "float h = vUniforms[effect].x;                    \n"
       + "float deg = degree(vUniforms[effect+2],ps);       \n"
+
+      + "float h = vUniforms[effect].x;                    \n"
       + "float tmp = (1.0-h)*deg;                          \n"
       + "float t1 = tmp*(deg+1.0)/h;                       \n"
       + "float t2 = tmp/(0.618*(0.618+deg));               \n"
