commit 5f76092f1cdb714e45cdfcdfc572a90b3c622f66
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Apr 2 00:21:10 2019 +0100

    Add (simplified, approximated) shading to the Sink effect, i.e. move the normal vectors.

diff --git a/src/main/java/org/distorted/library/effect/VertexEffectDeform.java b/src/main/java/org/distorted/library/effect/VertexEffectDeform.java
index 6356aae..669502b 100644
--- a/src/main/java/org/distorted/library/effect/VertexEffectDeform.java
+++ b/src/main/java/org/distorted/library/effect/VertexEffectDeform.java
@@ -105,38 +105,38 @@ public class VertexEffectDeform extends VertexEffect
     {
     addEffect( EffectName.DEFORM,
 
-        "const vec3 ONE = vec3(1.0,1.0,1.0);  \n"
-      + "const float A = 0.5; \n"
-      + "const float B = 0.2; \n"
-      + "const float C = 5.0; \n"
+        "const vec3 ONE = vec3(1.0,1.0,1.0);                                 \n"
+      + "const float A = 0.5;                                                \n"
+      + "const float B = 0.2;                                                \n"
+      + "const float C = 5.0;                                                \n"
 
-      + "vec3 center = vUniforms[effect+1].yzw; \n"
-      + "vec3 ps     = center-v; \n"
-      + "vec3 aPS    = abs(ps); \n"
-      + "vec3 maxps  = u_objD + abs(center); \n"
-      + "float d     = degree_region(vUniforms[effect+2],ps); \n"
-      + "vec3 force  = vUniforms[effect].xyz * d; \n"
-      + "vec3 aForce = abs(force); \n"
-      + "float denom = dot(ps+(1.0-d)*force,ps); \n"
-      + "float one_over_denom = 1.0/(denom-0.001*(sign(denom)-1.0)); \n"
-      + "vec3 Aw = A*maxps; \n"
-      + "vec3 quot = ps / maxps; \n"
-      + "quot = quot*quot; \n"                                                 // ( (x/W)^2 , (y/H)^2 ) where x,y are distances from V to center
+      + "vec3 center = vUniforms[effect+1].yzw;                              \n"
+      + "vec3 ps     = center-v;                                             \n"
+      + "vec3 aPS    = abs(ps);                                              \n"
+      + "vec3 maxps  = u_objD + abs(center);                                 \n"
+      + "float d     = degree_region(vUniforms[effect+2],ps);                \n"
+      + "vec3 force  = vUniforms[effect].xyz * d;                            \n"
+      + "vec3 aForce = abs(force);                                           \n"
+      + "float denom = dot(ps+(1.0-d)*force,ps);                             \n"
+      + "float one_over_denom = 1.0/(denom-0.001*(sign(denom)-1.0));         \n"
+      + "vec3 Aw = A*maxps;                                                  \n"
+      + "vec3 quot = ps / maxps;                                             \n"
+      + "quot = quot*quot;                                                   \n"  // ( (x/W)^2 , (y/H)^2 ) where x,y are distances from V to center
 
-      + "float denomV = 1.0 / (aForce.y + Aw.x); \n"
-      + "float denomH = 1.0 / (aForce.x + Aw.y); \n"
+      + "float denomV = 1.0 / (aForce.y + Aw.x);                             \n"
+      + "float denomH = 1.0 / (aForce.x + Aw.y);                             \n"
 
-      + "vec3 vertCorr= ONE - aPS / ( aForce+C*aPS + (ONE-sign(aForce)) ); \n" // avoid division by 0 when force and PS both are 0
+      + "vec3 vertCorr= ONE - aPS / ( aForce+C*aPS + (ONE-sign(aForce)) );   \n"  // avoid division by 0 when force and PS both are 0
 
-      + "float mvXvert = -B * ps.x * aForce.y * (1.0-quot.y) * denomV; \n"     // impact the vertical   component of the force vector has on horizontal movement
-      + "float mvYhorz = -B * ps.y * aForce.x * (1.0-quot.x) * denomH; \n"     // impact the horizontal component of the force vector has on vertical   movement
-      + "float mvYvert = force.y * (1.0-quot.x*Aw.x*denomV) * vertCorr.y; \n"  // impact the vertical   component of the force vector has on vertical   movement
-      + "float mvXhorz = force.x * (1.0-quot.y*Aw.y*denomH) * vertCorr.x; \n"  // impact the horizontal component of the force vector has on horizontal movement
+      + "float mvXvert = -B * ps.x * aForce.y * (1.0-quot.y) * denomV;       \n"  // impact the vertical   component of the force vector has on horizontal movement
+      + "float mvYhorz = -B * ps.y * aForce.x * (1.0-quot.x) * denomH;       \n"  // impact the horizontal component of the force vector has on vertical   movement
+      + "float mvYvert = force.y * (1.0-quot.x*Aw.x*denomV) * vertCorr.y;    \n"  // impact the vertical   component of the force vector has on vertical   movement
+      + "float mvXhorz = force.x * (1.0-quot.y*Aw.y*denomH) * vertCorr.x;    \n"  // impact the horizontal component of the force vector has on horizontal movement
 
-      + "v.x += (mvXvert+mvXhorz); \n"
-      + "v.y += (mvYvert+mvYhorz); \n"
+      + "v.x += (mvXvert+mvXhorz);                                           \n"
+      + "v.y += (mvYvert+mvYhorz);                                           \n"
 
-      + "v.z += force.z*d*d*(3.0*d*d -8.0*d +6.0); \n"                         // thick bubble
+      + "v.z += force.z*d*d*(3.0*d*d -8.0*d +6.0);                           \n"  // thick bubble
       + "float b = -(12.0*force.z*d*(1.0-d)*(1.0-d)*(1.0-d))*one_over_denom; \n"
 
       + "n.xy += n.z*b*ps.xy;"
diff --git a/src/main/java/org/distorted/library/effect/VertexEffectSink.java b/src/main/java/org/distorted/library/effect/VertexEffectSink.java
index d2ad237..8de806c 100644
--- a/src/main/java/org/distorted/library/effect/VertexEffectSink.java
+++ b/src/main/java/org/distorted/library/effect/VertexEffectSink.java
@@ -60,12 +60,22 @@ public class VertexEffectSink extends VertexEffect
     {
     addEffect(EffectName.SINK,
 
-        "vec3 center = vUniforms[effect+1].yzw; \n"
-      + "vec3 ps = center-v; \n"
-      + "float h = vUniforms[effect].x; \n"
-      + "float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h); \n"
+        "vec3 center = vUniforms[effect+1].yzw;            \n"
+      + "vec3 ps = center-v;                               \n"
+      + "float h = vUniforms[effect].x;                    \n"
+      + "float deg = degree(vUniforms[effect+2],center,ps);\n"
+      + "float t = deg * (1.0-h)/max(1.0,h);               \n"
+      + "v += t*ps;                                        \n"
 
-      + "v += t*ps;"
+      + "const float A = 1.6;                              \n" // max amount of change in normal vector when pulling
+      + "const float B = 10.0;                             \n" // when pushing
+      + "vec3 nx = dot(ps,n)*ps;                           \n" // nx = (component of n that's parallel to ps) * |ps|^2 (=dot(ps,ps))
+      + "float dot_ps = dot(ps,ps);                        \n"
+      + "float sign_ps= sign(dot_ps);                      \n"
+      + "nx = (sign_ps*nx)/(dot_ps-(sign_ps-1.0));         \n" // uff! now nx is the parallel to ps component of n, even if ps==0
+      + "float move = deg*(h-1.0)/(h/B+1.0/A);             \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg
+      + "n += move*nx;                                     \n"
+      + "n = normalize(n);"
       );
     }
 
