title: Does the input texture to a fragment shader change as the shader runs?
body: <p>I'm trying to implement the <a href="http://mike.teczno.com/notes/atkinson.html" rel="nofollow noreferrer">Atkinson dithering algorithm</a> in a fragment shader in GLSL using our own <a href="https://stackoverflow.com/users/19679/brad-larson">Brad Larson</a>'s <a href="https://github.com/BradLarson/GPUImage" rel="nofollow noreferrer">GPUImage</a> framework. (This might be one of those things that is impossible but I don't know enough to determine that yet so I'm just going ahead and doing it anyway.)</p>
  
  <p>The Atkinson algo dithers grayscale images into pure black and white as seen on the original Macintosh. Basically, I need to investigate a few pixels around my pixel and determine how far away from pure black or white each is and use that to calculate a cumulative "error;" that error value plus the original value of the given pixel determines whether it should be black or white. The problem is that, as far as I could tell, the error value is (almost?) always zero or imperceptibly close to it. What I'm thinking might be happening is that the texture I'm sampling is the same one that I'm writing to, so that the error ends up being zero (or close to it) because most/all of the pixels I'm sampling are already black or white.</p>
  
  <p>Is this correct, or are the textures that I'm sampling from and writing to distinct? If the former, is there a way to avoid that? If the latter, then might you be able to spot anything else wrong with this code? 'Cuz I'm stumped, and perhaps don't know how to debug it properly.</p>
  
  <pre><code>varying highp vec2 textureCoordinate;
  uniform sampler2D inputImageTexture;
  
  uniform highp vec3 dimensions;
  
  void main()
  {
      highp vec2 relevantPixels[6];
  
      relevantPixels[0] = vec2(textureCoordinate.x, textureCoordinate.y - 2.0);
      relevantPixels[1] = vec2(textureCoordinate.x - 1.0, textureCoordinate.y - 1.0);
      relevantPixels[2] = vec2(textureCoordinate.x, textureCoordinate.y - 1.0);
      relevantPixels[3] = vec2(textureCoordinate.x + 1.0, textureCoordinate.y - 1.0);
      relevantPixels[4] = vec2(textureCoordinate.x - 2.0, textureCoordinate.y);
      relevantPixels[5] = vec2(textureCoordinate.x - 1.0, textureCoordinate.y);
  
      highp float err = 0.0;
  
      for (mediump int i = 0; i &lt; 6; i++) {
          highp vec2 relevantPixel = relevantPixels[i];
          // @todo Make sure we're not sampling a pixel out of scope. For now this
          // doesn't seem to be a failure (?!).
          lowp vec4 pointColor = texture2D(inputImageTexture, relevantPixel);
          err += ((pointColor.r - step(.5, pointColor.r)) / 8.0);
      }
  
      lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
      lowp float hue = step(.5, textureColor.r + err);
  
      gl_FragColor = vec4(hue, hue, hue, 1.0);
  }
  </code></pre>