title: Using a texture for data
body: <p>I asked <a href="https://stackoverflow.com/questions/19529690/index-expression-must-be-constant-webgl-glsl-error/19529963?noredirect=1#comment29054344_19529963">this question</a> before about how to pass a data array to a fragment shader for coloring a terrain, and it was suggested I could use a texture's RGBA values.  </p>
  
  <p>I'm now stuck trying to work out how I would also use the <code>yzw</code> values. This is my fragment shader code:</p>
  
  <pre><code>vec4 data = texture2D(texture, vec2(verpos.x / 32.0, verpos.z / 32.0));
  float blockID = data.x;
  vec4 color;
  
  if (blockID == 1.0) {
      color = vec4(0.28, 0.52, 0.05, 1.0);
  }
  else if (blockID == 2.0) {
      color = vec4(0.25, 0.46, 0.05, 1.0);
  }
  else if (blockID == 3.0) {
      color = vec4(0.27, 0.49, 0.05, 1.0);
  }
  
  gl_FragColor = color;
  </code></pre>
  
  <p>This works fine, however as you can see it's only using the float from the <code>x</code>-coordinate. If it was also using the <code>yzw</code> coordinates the texture size could be reduced to 16x16 instead of 32x32 (four times smaller).</p>
  
  <p>The aim of this is to create a voxel-type terrain, where each 'block' is 1x1 in space coordinates and is colored based on the blockID. Looks like this:
  <img src="https://i.stack.imgur.com/pEqtA.png" alt="enter image description here"></p>
  
  <p>Outside of GLSL this would be simple, however with no ability to store which blocks have been computed I'm finding this difficult. No doubt, I'm over thinking things and it can be done with some simple math.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong><br>
  Code based on Wagner Patriota's answer:  </p>
  
  <pre><code>vec2 pixel_of_target = vec2( verpos.xz * 32.0 - 0.5 ); // Assuming verpos.xz == uv_of_target ?
  
  // For some reason mod() doesn't support integers so I have to convert it using int()
  int X = int(mod(pixel_of_target.y, 2.0) * 2.0 + mod(pixel_of_target.x, 2.0));
  
  // Gives the error "Index expression must be constant"
  float blockID = data[ X ];
  </code></pre>
  
  <p>About the error, I <a href="https://stackoverflow.com/questions/19529690/index-expression-must-be-constant-webgl-glsl-error">asked a question</a> about that before which actually led to me asking this one. :P<br>
  Any ideas? Thanks! :)</p>