title: How does vertex shader pass color information to fragment shader?
body: <p>In a simple hello-world OpenGL program, which simply draws a static triangle on the window,
  when I set the 3 vertex of the triangle to red, green and blue color, the triangle is filled with gradient.</p>
  
  <p>But when I use shaders like this:</p>
  
  <p><strong>Vertex Shader:</strong></p>
  
  <pre><code>attribute vec4 aVertex;
  attribute vec4 aColor;
  
  varying vec4 vColor;
  
  void main(void) {
      gl_Position = gl_ModelViewMatrix * gl_ProjectionMatrix * aVertex;
      vColor = aColor;
  }
  </code></pre>
  
  <p>where the attributes <code>aVertex</code> and <code>aColor</code> comes from a vertex buffer, passed through a call of <code>glVertexAttribPointer</code>.</p>
  
  <p><strong>Fragment Shader:</strong></p>
  
  <pre><code>varying vec4 vColor;
  void main(void) {
      gl_FragColor = vColor;
  }
  </code></pre>
  
  <p>The triangle is still filled with gradient, and here comes the question: </p>
  
  <p>If vertex-shader is calculated per vertex, then each instance of <code>vColor</code> should be assigned with the color of a vertex. And the vertex color should be either red, green, or blue, as set in the vertex buffer. </p>
  
  <p>So where did the gradient come from? </p>
  
  <p>Or, in another word, when did it happen that in the frag-shader, the <code>vColor</code> turns out to be the interpolated color instead of the vertex's? </p>