commit 81a0b906f4fd1f6b83c9299ca5fe37ccd0b9a9ce
Author: leszek <leszek@koltunski.pl>
Date:   Tue Feb 28 23:51:05 2017 +0000

    Preparation for shader optimization

diff --git a/src/main/java/org/distorted/library/program/DistortedProgram.java b/src/main/java/org/distorted/library/program/DistortedProgram.java
index 6ea4bc0..4b8f583 100644
--- a/src/main/java/org/distorted/library/program/DistortedProgram.java
+++ b/src/main/java/org/distorted/library/program/DistortedProgram.java
@@ -230,6 +230,8 @@ public class DistortedProgram
       {
       String error = GLES30.glGetShaderInfoLog(shaderHandle);
 
+      //android.util.Log.e("Program", "error compiling :"+error);
+
       switch(shaderType)
         {
         case GLES30.GL_VERTEX_SHADER  : throw new VertexCompilationException(error);
diff --git a/src/main/res/raw/main_fragment_shader.glsl b/src/main/res/raw/main_fragment_shader.glsl
index b5d9085..378a00c 100644
--- a/src/main/res/raw/main_fragment_shader.glsl
+++ b/src/main/res/raw/main_fragment_shader.glsl
@@ -37,43 +37,53 @@ const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 );
 //////////////////////////////////////////////////////////////////////////////////////////////
 // CHROMA EFFECT
 
+#if defined(CHROMA) || defined(SMOOTH_CHROMA)
 void chroma(float degree, int effect, inout vec4 color)
   {
   color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // ALPHA EFFECT (change transparency level)
 
+#if defined(ALPHA) || defined(SMOOTH_ALPHA)
 void alpha(float degree, int effect, inout vec4 color)
   {
   color.a *= (degree*(fUniforms[effect].x-1.0)+1.0); 
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // BRIGHTNESS EFFECT
 
+#if defined(BRIGHTNESS) || defined(SMOOTH_BRIGHTNESS)
 void brightness(float degree, int effect, inout vec4 color)
   {
   color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
   }
-  
+#endif
+
 //////////////////////////////////////////////////////////////////////////////////////////////
 // CONTRAST EFFECT
 
+#if defined(CONTRAST) || defined(SMOOTH_CONTRAST)
 void contrast(float degree, int effect, inout vec4 color)
   {
   color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // SATURATION EFFECT
 
+#if defined(SATURATION) || defined(SMOOTH_SATURATION)
 void saturation(float degree, int effect, inout vec4 color)
   {
   float luminance = dot(LUMI,color.rgb);
   color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
   }
+#endif
 
 #endif
 
@@ -92,16 +102,37 @@ void main()
     diff = (v_Position.xy - fUniforms[2*i+1].xy)/fUniforms[2*i+1].zw;
     pointDegree = max(0.0,1.0-dot(diff,diff));
 
-         if( fType[i]==CHROMA            ) chroma    (sign(pointDegree),2*i,pixel);
-    else if( fType[i]==SMOOTH_CHROMA     ) chroma    (     pointDegree ,2*i,pixel);
-    else if( fType[i]==ALPHA             ) alpha     (sign(pointDegree),2*i,pixel);
-    else if( fType[i]==SMOOTH_ALPHA      ) alpha     (     pointDegree ,2*i,pixel);
-    else if( fType[i]==BRIGHTNESS        ) brightness(sign(pointDegree),2*i,pixel);
-    else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness(     pointDegree ,2*i,pixel);
-    else if( fType[i]==CONTRAST          ) contrast  (sign(pointDegree),2*i,pixel);
-    else if( fType[i]==SMOOTH_CONTRAST   ) contrast  (     pointDegree ,2*i,pixel);
-    else if( fType[i]==SATURATION        ) saturation(sign(pointDegree),2*i,pixel);
-    else if( fType[i]==SMOOTH_SATURATION ) saturation(     pointDegree ,2*i,pixel);
+#ifdef CHROMA
+    if( fType[i]==CHROMA            ) chroma    (sign(pointDegree),2*i,pixel); else
+#endif
+#ifdef SMOOTH_CHROMA
+    if( fType[i]==SMOOTH_CHROMA     ) chroma    (     pointDegree ,2*i,pixel); else
+#endif
+#ifdef ALPHA
+    if( fType[i]==ALPHA             ) alpha     (sign(pointDegree),2*i,pixel); else
+#endif
+#ifdef SMOOTH_ALPHA
+    if( fType[i]==SMOOTH_ALPHA      ) alpha     (     pointDegree ,2*i,pixel); else
+#endif
+#ifdef BRIGHTNESS
+    if( fType[i]==BRIGHTNESS        ) brightness(sign(pointDegree),2*i,pixel); else
+#endif
+#ifdef SMOOTH_BRIGHTNESS
+    if( fType[i]==SMOOTH_BRIGHTNESS ) brightness(     pointDegree ,2*i,pixel); else
+#endif
+#ifdef CONTRAST
+    if( fType[i]==CONTRAST          ) contrast  (sign(pointDegree),2*i,pixel); else
+#endif
+#ifdef SMOOTH_CONTRAST
+    if( fType[i]==SMOOTH_CONTRAST   ) contrast  (     pointDegree ,2*i,pixel); else
+#endif
+#ifdef SATURATION
+    if( fType[i]==SATURATION        ) saturation(sign(pointDegree),2*i,pixel); else
+#endif
+#ifdef SMOOTH_SATURATION
+    if( fType[i]==SMOOTH_SATURATION ) saturation(     pointDegree ,2*i,pixel); else
+#endif
+    {}
     }
 #endif
 
diff --git a/src/main/res/raw/main_vertex_shader.glsl b/src/main/res/raw/main_vertex_shader.glsl
index dcebb81..e66f792 100644
--- a/src/main/res/raw/main_vertex_shader.glsl
+++ b/src/main/res/raw/main_vertex_shader.glsl
@@ -45,9 +45,6 @@ uniform int vType[NUM_VERTEX];       // their types.
 uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
                                      // The first vec4 is the Interpolated values,
                                      // next is half cache half Center, the third -  the Region.
-#endif
-
-#if NUM_VERTEX>0
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // HELPER FUNCTIONS
@@ -214,6 +211,7 @@ void restrictZ(inout float v)
 //        along the force line is.
 //        0<=C<1 looks completely ridiculous and C<0 destroys the system.
 
+#ifdef DEFORM
 void deform(in int effect, inout vec3 v, inout vec3 n)
   {
   const vec2 ONE = vec2(1.0,1.0);
@@ -253,6 +251,7 @@ void deform(in int effect, inout vec3 v, inout vec3 n)
 
   n.xy += n.z*b*ps;
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // DISTORT EFFECT
@@ -309,6 +308,7 @@ void deform(in int effect, inout vec3 v, inout vec3 n)
 // Thus we actually want to compute N(v.x,v.y) = a*(-(dx/|PS|)*f'(|PX|), -(dy/|PS|)*f'(|PX|), 1) and keep adding
 // the first two components. (a is the horizontal part)
 
+#ifdef DISTORT
 void distort(in int effect, inout vec3 v, inout vec3 n)
   {
   vec2 center = vUniforms[effect+1].yz;
@@ -330,6 +330,7 @@ void distort(in int effect, inout vec3 v, inout vec3 n)
   v.xy += d*force.xy;
   n.xy += n.z*b*ps;
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // SINK EFFECT
@@ -337,6 +338,7 @@ void distort(in int effect, inout vec3 v, inout vec3 n)
 // Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P)
 // when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P)
 
+#ifdef SINK
 void sink(in int effect,inout vec3 v)
   {
   vec2 center = vUniforms[effect+1].yz;
@@ -346,6 +348,7 @@ void sink(in int effect,inout vec3 v)
 
   v.xy += t*ps;
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // PINCH EFFECT
@@ -356,6 +359,7 @@ void sink(in int effect,inout vec3 v)
 // with P' = P + (1-h)*dist(line to P)
 // when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P)
 
+#ifdef PINCH
 void pinch(in int effect,inout vec3 v)
   {
   vec2 center = vUniforms[effect+1].yz;
@@ -367,6 +371,7 @@ void pinch(in int effect,inout vec3 v)
 
   v.xy += t*dot(ps,dir)*dir;
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // SWIRL EFFECT
@@ -375,6 +380,7 @@ void pinch(in int effect,inout vec3 v)
 // This effect rotates the current vertex V by vInterpolated.x radians clockwise around the circle dilated
 // by (1-d) around the center of the effect S.
 
+#ifdef SWIRL
 void swirl(in int effect, inout vec3 v)
   {
   vec2 center  = vUniforms[effect+1].yz;
@@ -393,6 +399,7 @@ void swirl(in int effect, inout vec3 v)
                                                                // bitmap some points end up with d2<0 and they disappear off view.
   v.xy += min(d1_circle,d1_bitmap)*(PS - PS2/(1.0-d2));        // if d2=1 (i.e P=center) we should have P unchanged. How to do it?
   }
+#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // WAVE EFFECT
@@ -460,6 +467,7 @@ void swirl(in int effect, inout vec3 v)
 //
 // Generally speaking I'd keep to amplitude < length, as the opposite case has some other problems as well.
 
+#ifdef WAVE
 void wave(in int effect, inout vec3 v, inout vec3 n)
   {
   vec2 center     = vUniforms[effect+1].yz;
@@ -522,9 +530,10 @@ void wave(in int effect, inout vec3 v, inout vec3 n)
       }
     }
   }
-
 #endif
 
+#endif  // NUM_VERTEX>0
+
 //////////////////////////////////////////////////////////////////////////////////////////////
 
 void main()
@@ -537,12 +546,25 @@ void main()
 
   for(int i=0; i<vNumEffects; i++)
     {
-         if( vType[i]==DISTORT) distort(j,v,n);
-    else if( vType[i]==DEFORM ) deform (j,v,n);
-    else if( vType[i]==SINK   ) sink   (j,v);
-    else if( vType[i]==PINCH  ) pinch  (j,v);
-    else if( vType[i]==SWIRL  ) swirl  (j,v);
-    else if( vType[i]==WAVE   ) wave   (j,v,n);
+#ifdef DISTORT
+    if( vType[i]==DISTORT) distort(j,v,n); else
+#endif
+#ifdef DEFORM
+    if( vType[i]==DEFORM ) deform (j,v,n); else
+#endif
+#ifdef SINK
+    if( vType[i]==SINK   ) sink   (j,v);   else
+#endif
+#ifdef PINCH
+    if( vType[i]==PINCH  ) pinch  (j,v);   else
+#endif
+#ifdef SWIRL
+    if( vType[i]==SWIRL  ) swirl  (j,v);   else
+#endif
+#ifdef WAVE
+    if( vType[i]==WAVE   ) wave   (j,v,n); else
+#endif
+    {}
 
     j+=3;
     }
