title: apply LUT to an image GLSL
body: <p>I am very new to CG and am trying to implement a fragment shader that applies a png LUT to a picture, but I don't get the expected result, right now my code makes the picture very blue-ish.<br />
  Here is an example LUT :
  [![enter image description here][1]][1]</p>
  <p>When I apply the LUT using the following code to some image the whole picture just turns very blue-ish.<br />
  Code :</p>
  <pre><code>precision mediump float;
  
  uniform sampler2D u_image;
  uniform sampler2D u_lut;
  
  // LUT resolution for one component (4, 8, 16, ...)
  uniform float u_resolution;
  
  layout(location = 0) out vec4 fragColor;
  
  in vec2 v_uv;
  
  void main(void)
  {
      vec2 tiles = vec2(u_resolution, u_resolution);
      vec2 tilesSize = vec2(u_resolution * u_resolution);
      vec3 imageColor = texture(u_image, v_uv).rgb;
      // min and max are used to interpolate between 2 tiles in the LUT
      float index = imageColor.b * (tiles.x * tiles.y - 1.0);
      float index_min = min(u_resolution - 2.0, floor(index));
      float index_max = index_min + 1.0;
  
      vec2 tileIndex_min;
      tileIndex_min.y = floor(index_min / tiles.x);
      tileIndex_min.x = floor(index_min - tileIndex_min.y * tiles.x);
      vec2 tileIndex_max;
      tileIndex_max.y = floor(index_max / tiles.x);
      tileIndex_max.x = floor(index_max - tileIndex_max.y * tiles.x);
  
      vec2 tileUV = mix(0.5/tilesSize, (tilesSize - 0.5)/tilesSize, imageColor.rg);
  
      vec2 tableUV_1 = tileIndex_min / tiles + tileUV / tiles;
      vec2 tableUV_2 = tileIndex_max / tiles + tileUV / tiles;
  
      vec3 lookUpColor_1 = texture(u_lut, tableUV_1).rgb;
      vec3 lookUpColor_2 = texture(u_lut, tableUV_2).rgb;
      vec3 lookUpColor = mix(lookUpColor_1, lookUpColor_2, index - index_min);
      fragColor = vec4(lookUpColor, 1.0);
  }
   
  </code></pre>