commit fc6d738d53a86fe8cb2b33f34b86438d4e105814
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Dec 16 22:44:46 2022 +0100

    Now the 'stars' animation should fulling work, even on the physical LG phone.

diff --git a/src/main/java/org/distorted/overlays/OverlayStars.java b/src/main/java/org/distorted/overlays/OverlayStars.java
index fe29c901..71c542fa 100644
--- a/src/main/java/org/distorted/overlays/OverlayStars.java
+++ b/src/main/java/org/distorted/overlays/OverlayStars.java
@@ -17,6 +17,8 @@ import android.graphics.Paint;
 
 import org.distorted.library.effect.EffectQuality;
 import org.distorted.library.effect.FragmentEffectAlpha;
+import org.distorted.library.effect.MatrixEffectMove;
+import org.distorted.library.effect.MatrixEffectScale;
 import org.distorted.library.effect.PostprocessEffectGlow;
 import org.distorted.library.effect.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectScale;
@@ -53,7 +55,7 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
    private static final int INDEX = 5;
 
    private ListenerOverlay mListener;
-   private DistortedNode mNode;
+   private DistortedNode mNodeFalling, mNodeCentral;
    private DistortedScreen mScreen;
    private DistortedTexture mTexture;
    private Bitmap mCountBitmap, mStarBitmap;
@@ -148,66 +150,39 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   private DistortedNode createNode(Resources res, int numStars, boolean increase)
+   private void createBitmap(Resources res)
       {
-      // texture /////////////////////////////////////////////////////
-      if( mTexture==null )
-         {
-         mTexture = new DistortedTexture();
-         mStarBitmap = BitmapFactory.decodeResource(res, R.drawable.star);
-         mBmpW = mStarBitmap.getWidth();
-         mBmpH = mStarBitmap.getHeight();
-         mCountBitmap = Bitmap.createBitmap(2*mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
-         mCountCanvas = new Canvas(mCountBitmap);
-         mPaint = new Paint();
-         mPaint.setColor(0xff000000);
-         mPaint.setTextSize(mBmpH*0.28f);
-         mPaint.setAntiAlias(true);
-         mPaint.setTextAlign(Paint.Align.CENTER);
-         renderStars(numStars);
-         }
+      mStarBitmap = BitmapFactory.decodeResource(res, R.drawable.star);
+      mBmpW = mStarBitmap.getWidth();
+      mBmpH = mStarBitmap.getHeight();
+      mCountBitmap = Bitmap.createBitmap(mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
+      mCountCanvas = new Canvas(mCountBitmap);
+      mPaint = new Paint();
+      mPaint.setColor(0xff000000);
+      mPaint.setTextSize(mBmpH*0.28f);
+      mPaint.setAntiAlias(true);
+      mPaint.setTextAlign(Paint.Align.CENTER);
+      }
 
-      // mesh ////////////////////////////////////////////////////////
-      MeshQuad[] mesh = new MeshQuad[mNewStars+1];
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-      Static4D[] mapMain = new Static4D[1];
-      Static4D[] mapStar = new Static4D[1];
+   private DistortedNode createNodeFalling(boolean increase)
+      {
+      DistortedTexture texture = new DistortedTexture();
+      texture.setTexture(mStarBitmap);
 
-      mapMain[0] = new Static4D(0.5f,0.0f,0.5f,1.0f);
-      mapStar[0] = new Static4D(0.0f,0.0f,0.5f,1.0f);
+      MeshQuad[] mesh = new MeshQuad[mNewStars];
 
-      for(int i=0; i<mNewStars+1; i++)
+      for(int i=0; i<mNewStars; i++)
          {
          mesh[i] = new MeshQuad();
-
-         if( i>=mNewStars )
-           {
-           mesh[i].setEffectAssociation(0,2,i);
-           mesh[i].setTextureMap(mapMain,0);
-           }
-         else
-           {
-           mesh[i].setEffectAssociation(0,1,i);
-           mesh[i].setTextureMap(mapStar,0);
-           }
+         mesh[i].setEffectAssociation(0,1,i+1);
          }
 
       MeshJoined wholeMesh = new MeshJoined(mesh);
 
-      // effects: main ///////////////////////////////////////////////
       DistortedEffects effects = new DistortedEffects();
-
-      float scaleM  = mWidth*0.40f;
-      float scaleP  = mWidth*0.15f;
-      Static3D moveM= new Static3D(0,0,1);
-
-      VertexEffectMove mainMove     = new VertexEffectMove(moveM);
-      VertexEffectScale mainScale   = new VertexEffectScale(scaleM);
-      mainMove.setMeshAssociation(2,-1);
-      mainScale.setMeshAssociation(2,-1);
-
-      // effects: moving stars ///////////////////////////////////////
-      VertexEffectScale scaleE = new VertexEffectScale(scaleP);
+      VertexEffectScale scaleE = new VertexEffectScale(mWidth*0.15f);
       scaleE.setMeshAssociation(1,-1);
       effects.apply(scaleE);
 
@@ -215,7 +190,7 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
         {
         Dynamic3D moveP = createRandomMove(increase);
         VertexEffectMove moveE= new VertexEffectMove(moveP);
-        moveE.setMeshAssociation(0,i);
+        moveE.setMeshAssociation(0,i+1);
         effects.apply(moveE);
 
         if( i==0 )
@@ -225,14 +200,29 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
            }
         }
 
-      // main effect queue ///////////////////////////////////////////
-      effects.apply(mainMove);
-      effects.apply(mainScale);
+      return new DistortedNode(texture,effects,wholeMesh);
+      }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   private DistortedNode createNodeCentral(int numStars)
+      {
+      mTexture = new DistortedTexture();
+      renderStars(numStars);
+
+      MeshQuad mesh = new MeshQuad();
+
+      DistortedEffects effects = new DistortedEffects();
+      float scaleM  = mWidth*0.40f;
+      Static3D moveM= new Static3D(0,0,1);
+      MatrixEffectMove move  = new MatrixEffectMove(moveM);
+      MatrixEffectScale scale= new MatrixEffectScale(scaleM);
+      effects.apply(move);
+      effects.apply(scale);
       createAlphaEffect(true);
       effects.apply(mAlpha);
 
-      return new DistortedNode(mTexture,effects,wholeMesh);
+      return new DistortedNode(mTexture,effects,mesh);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -242,8 +232,7 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
       String txt = ""+numStars;
       mCountBitmap.eraseColor(0x00000000);
       mCountCanvas.drawBitmap(mStarBitmap,0,0,null);
-      mCountCanvas.drawBitmap(mStarBitmap,mBmpW,0,null);
-      mCountCanvas.drawText(txt,mBmpW*1.5f,mBmpH*0.64f,mPaint);
+      mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*0.64f,mPaint);
       mTexture.setTexture(mCountBitmap);
       }
 
@@ -262,9 +251,15 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
       mHeight= mScreen.getHeight();
       mIncrease = mNewStars>0;
       if( !mIncrease ) mNewStars = -mNewStars;
-      mNode = createNode(res,mTotalStars,mIncrease);
-      mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
-      mScreen.attach(mNode);
+
+      createBitmap(res);
+      mNodeFalling = createNodeFalling(mIncrease);
+      mNodeFalling.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
+      mScreen.attach(mNodeFalling);
+      mNodeCentral = createNodeCentral(mTotalStars);
+      mNodeCentral.glDepthMask(false);
+      mNodeCentral.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
+      mScreen.attach(mNodeCentral);
 
       return 0;
       }
@@ -291,7 +286,7 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
          glow.setQuality(EffectQuality.MEDIUM);
          mGlowID = glow.getID();
          glow.notifyWhenFinished(this);
-         DistortedEffects effects = mNode.getEffects();
+         DistortedEffects effects = mNodeCentral.getEffects();
          effects.apply(glow);
          renderStars(mTotalStars+(mIncrease ? mNewStars : -mNewStars));
          }
@@ -303,9 +298,12 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
          }
       if( id==mAlphaID )
          {
-         mScreen.detach(mNode);
-         mNode.markForDeletion();
-         mNode=null;
+         mScreen.detach(mNodeCentral);
+         mNodeCentral.markForDeletion();
+         mNodeCentral=null;
+         mScreen.detach(mNodeFalling);
+         mNodeFalling.markForDeletion();
+         mNodeFalling=null;
          mListener.overlayFinished(id);
          }
       }
