title: Using a small lookup table in a GLSL shader
body: <p>I have a fragment shader and I would like to build a small loookup table and interpolate on it. My current code is this (sorry for the verbosity):</p>
  
  <pre><code>float inverse_f(float r)
  {
  
      // Build a lookup table on the radius, as a fixed-size table.
      // We will use a vec3 since we will store the multipled number in the Z coordinate.
      // So to recap: x will be the radius, y will be the f(x) distortion, and Z will be x * y;
      vec3[32] lut;
  
      // Flame has no overflow bbox so we can safely max out at the image edge, plus some cushion
      float max_r = sqrt((adsk_input1_aspect * adsk_input1_aspect) + 1) + 0.1;
      float incr = max_r / 32;
      float lut_r = 0;
      float f;
      for(int i=0; i &lt; 32; i++) {
          f = distortion_f(lut_r);
          lut[i] = vec3(lut_r, f, lut_r * f);
          lut_r += incr;
      }
  
      float df;
      float dz;
      float t;
  
      // Now find the nehgbouring elements
      for(int i=0; i &lt; 32; i++) {
          if(lut[i].z &lt; r) {
              // found!
              df = lut[i+1].y - lut[i].y;
              dz = lut[i+1].z - lut[i].z;
              t = (r - lut[i].z) / dz;
              return df * t;
          }
      }
  }
  </code></pre>
  
  <p>I am working with #version 120. However it's not working (all the iterations where this function is called return the same value). So either I am doing something wrong with the array (it's getting filled with the same values) or the return from the for loop does not work because the loop gets unrolled in some way that I don't understand. Is there something that springs to mind that could cause this behavior (the same value returned independently of the passed-in R value)?</p>