title: Is there a way to optimize this glsl?
body: <p>There is textures array (uSamplerArr), textures coordinates bias(texBiasArr), opacity(alfaArr) and transparent colors array(tcolorArr). </p>
  
  <p>In result - low framerate.</p>
  
  <p>How to optimize this shader?</p>
  
  <p>Vertex shader</p>
  
  <pre><code>attribute vec3 aVertexPosition;
  attribute vec2 aTextureCoord;
  
  uniform mat4 uPMVMatrix;
  
  varying vec2 vTextureCoord;
  
  void main(void) {
  
    gl_Position = uPMVMatrix * vec4(aVertexPosition, 1.0);
    vTextureCoord = aTextureCoord;
  }
  </code></pre>
  
  <p>Fragment shader</p>
  
  <pre><code>precision mediump float;
  precision lowp int;
  
  const int MAX_TEX = 8;
  const float COLOR_DIFF_EPS = 0.4;
  
  varying vec2 vTextureCoord;
  
  uniform int numTex;
  uniform sampler2D uSamplerArr[MAX_TEX];
  uniform float alfaArr[MAX_TEX];
  uniform vec3 tcolorArr[MAX_TEX];
  uniform vec3 texBiasArr[MAX_TEX];
  
  void main(void) 
  {
    vec4 res = texture2D(uSamplerArr[0], texBiasArr[0].z * (vTextureCoord + vec2(texBiasArr[0].x,     texBiasArr[0].y)));
  
    if(numTex &gt; 1)
    {
      vec4 ti;
      for( int i = 1; i &lt; MAX_TEX; i++ ) 
      {
        if( i &lt; numTex ) 
        {
          ti = texture2D(uSamplerArr[i], texBiasArr[i].z * (vTextureCoord + texBiasArr[i].xy));
  
          if( length( ti.rgb - tcolorArr[i] ) &gt; COLOR_DIFF_EPS ) 
          {
            res = mix(res, ti, alfaArr[i]);
          }
        }
        else
        {
          break;
        }
      }
    }
    gl_FragColor = res;
  }
  </code></pre>