commit f89a986ee06390832896e73b19bfb5e1dbab95f9
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Apr 18 15:37:08 2018 +0100

    Order Independent Transparency: some progress

diff --git a/src/main/java/org/distorted/library/main/DistortedEffects.java b/src/main/java/org/distorted/library/main/DistortedEffects.java
index 5f6744a..22abeb1 100644
--- a/src/main/java/org/distorted/library/main/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/main/DistortedEffects.java
@@ -399,7 +399,8 @@ public class DistortedEffects
     GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
 
 
-    //android.util.Log.e("effects", "bufferSize: "+mBufferSize+" numRecords: "+((mBufferSize-surface.mWidth*surface.mHeight)/3) );
+    //android.util.Log.e("effects", "width="+surface.mWidth+" height="+surface.mHeight+
+    //    " bufferSize: "+mBufferSize+" numRecords: "+((mBufferSize-surface.mWidth*surface.mHeight)/3) );
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/res/raw/blit_depth_fragment_shader.glsl b/src/main/res/raw/blit_depth_fragment_shader.glsl
index 5395e45..01a9ba3 100644
--- a/src/main/res/raw/blit_depth_fragment_shader.glsl
+++ b/src/main/res/raw/blit_depth_fragment_shader.glsl
@@ -17,7 +17,7 @@
 // along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
 //////////////////////////////////////////////////////////////////////////////////////////////
 
-precision lowp float;
+precision highp float;
 precision highp uint;
 
 #if __VERSION__ != 100
@@ -60,6 +60,35 @@ void insert( vec2 ij, uint depth, uint rgba )
   {
   uint ptr = atomicCounterIncrement(u_Counter)-1u;
 
+  if( ptr<u_numRecords )
+    {/*
+    uint color;
+    vec2 c = vec2(0.0,1.0);
+
+    uint rgb = ((uint(255.0*c.x))<<16u) + uint(255.0*c.y);
+
+         if(  rgb       ==  0u ) color = (255u<<24u) + (255u<<16u) + 255u;
+    else if( (rgb&255u) ==  0u ) color = (255u<<24u) + 255u;
+    else if( (rgb&255u) <= 50u ) color = (255u<<16u) + 255u;
+    else if( (rgb&255u) == 255u) color = (255u<<16u) + (255u<< 8u) + 255u;
+    else                         color = (255u<< 8u) + 255u;
+*/
+vec4 c= vec4(1.0,1.0,0.0,1.0);
+uint color = ((uint(255.0*c.r))<<24u) + ((uint(255.0*c.g))<<16u) + ((uint(255.0*c.b))<<8u) + uint(255.0*c.a);
+
+    ptr = 3u*ptr + uint(u_Size.x*u_Size.y);
+
+    u_Records[ptr   ] = 0u;
+    u_Records[ptr+1u] = depth;
+    u_Records[ptr+2u] = rgba;
+
+    uint index = uint(ij.x + ij.y * float(u_Size.x));
+
+    u_Records[index] = ptr;
+    }
+/*
+  uint ptr = atomicCounterIncrement(u_Counter)-1u;
+
   if( ptr<u_numRecords )
     {
     ptr = 3u*ptr + uint(u_Size.x*u_Size.y);
@@ -76,7 +105,7 @@ void insert( vec2 ij, uint depth, uint rgba )
       {
       if ( curr==0u || depth > u_Records[curr+1u] )  // need to insert here
         {
-*/
+
         u_Records[ptr] = curr; // next of new record is curr
         memoryBarrier();
         uint res = atomicCompSwap( u_Records[prev], curr, ptr );
@@ -91,7 +120,9 @@ void insert( vec2 ij, uint depth, uint rgba )
         }
       }
 */
-    }
+//    }
+
+
   }
 
 //////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/res/raw/blit_depth_render_fragment_shader.glsl b/src/main/res/raw/blit_depth_render_fragment_shader.glsl
index 06273ae..1f05532 100644
--- a/src/main/res/raw/blit_depth_render_fragment_shader.glsl
+++ b/src/main/res/raw/blit_depth_render_fragment_shader.glsl
@@ -17,7 +17,7 @@
 // along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
 //////////////////////////////////////////////////////////////////////////////////////////////
 
-precision lowp float;
+precision highp float;
 precision highp uint;
 
 #if __VERSION__ != 100
@@ -66,6 +66,18 @@ vec4 blend(vec4 clr,vec4 srf)
 void main()                    		
   {
   uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));
+
+  if( u_Records[index] == 0u ) discard;
+  else
+    {
+    index = u_Records[index];
+    FRAG_COLOR = convert(u_Records[index+2u]);
+    }
+
+  u_Records[index] = 0u;
+
+  /*
+  uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));
   uint curr = u_Records[index];
 
   if (curr == 0u) discard;
@@ -83,9 +95,17 @@ void main()
     if( color.a == 0.0 ) color = vec4(0.0,1.0,0.0,1.0);
     }
 
+
+  if( curr>0u )
+    {
+    curr = u_Records[curr];
+    color= convert(u_Records[curr+2u]);
+    }
+
   gl_FragDepth = TEXTURE(u_DepthTexture, v_TexCoordinate).r;
   FRAG_COLOR = color;
 
 //else
 //  FRAG_COLOR = vec4(1.0,0.0,0.0,1.0);
+*/
   }
\ No newline at end of file
