6.4.1. Adding vertex coloring

The vertex shader can define a varying col and use it to pass the interpolated vertex color, COLOR, to the fragment shader. The varying col variable is shared with the fragment shader. See Example 6.14:

Example 6.14. Vertex shader passes interpolated color to fragment shader

attribute vec4 POSITION; 
attribute vec4 COLOR;
varying vec4 col;
void main(void)
{
    col = COLOR;
    gl_Position = POSITION;
};

Example 6.15 shows that the actual assignment to the gl_FragColor global color variable is done in the fragment shader:

Example 6.15. Assignment of the color in the fragment shader

precision mediump float; 
varying vec4 col;
void main(void)
{
    gl_FragColor = col; 
};

Copyright © 2010 ARM. All rights reserved.ARM DUI 0527A‑02a
Non-Confidential - Draft - BetaID070710