title: GLSL 1.2 floor() issues in Vertex Shader
body: <p>I'm trying to calculate texture coordinates based on the coordinates of an incoming vertex in the Vertex Shader. This is a stripped down version of my attempt:</p>
  
  <pre><code>#version 120
  
  varying vec4 color;
  
  uniform sampler2D heightmap;
  uniform ivec2 heightmapSize;
  
  void main(void)
  {
     vec2 fHeightmapSize = vec2(heightmapSize);
     vec2 pos = gl_Vertex.zx + vec2(0.5f, 0.5f);
     vec2 offset = floor(fHeightmapSize * pos) + vec2(0.5f, 0.5f);
  
     if (fract(offset.x) &gt; 0.45f &amp;&amp; fract(offset.x) &lt; 0.55f 
         &amp;&amp; fract(offset.y) &gt; 0.45f &amp;&amp; fract(offset.y) &lt; 0.55f)
        color = vec4(0.0f, 1.0f, 0.0f, 1.0f);
     else
        color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
  
     // gl_Position = ...
     // ...
  }
  </code></pre>
  
  <p>gl_Vertex is in <code>[-0.5, 0.5]^2</code>, on the XZ-plane. So what I am basically trying to do, is to </p>
  
  <ul>
  <li>first create a float vec2 from the ivec2 heightmapSize, which holds the width and height of the heightmap sampler. </li>
  <li>Then I'm converting the vertex coordinates to the interval <code>[0, 1]^2</code>. </li>
  <li><p>Then I'm calculating the offset in texture coordinates by multiplying the vertex position with the heightmap size. The left part (using <code>floor()</code>) should return the number of texels in each direction.</p>
  
  <blockquote>
    <p>Example: The texure is of size <code>4x4</code>, position is <code>(0.55, 0.5)</code>. This means I would got 2 texels to the right, and two texels upwards -> <code>(2.0, 2.0)</code>. </p>
  </blockquote>
  
  <p>In the right part, I add another <code>(0.5, 0.5)</code> because I want the center of the texel. The <code>(2.0, 2.0)</code> becomes <code>(2.5, 2.5)</code>. <strong>Note:</strong> whatever the coordinates are, the fractional part should be <code>0.5</code> in the end.</p></li>
  </ul>
  
  <p>Now comes the strange part. I'm testing for the result by specifying two colors. If the fractional part of the offset is "close" to <code>0.5</code>, I'm setting the resulting color to green, otherwise red. The image is almost all red. </p>
  
  <blockquote>
    <p><img src="https://i.imgur.com/X6wvt5h.png" alt="Result image"></p>
  </blockquote>
  
  <p>How is it possible, that either <code>fract()</code> does not result in a vector of two integer values (or close to integer because of float accuracy), or the adding of <code>vec2(0.5, 0.5)</code> has no effect? Am I missing something else?</p>