Color Fragment Shader

The fragment shader is called from every pixel in the primitives drawn to the screen. This time we pass in the varying vColor and use it directly as the pixel color.

147                 var fragmentShaderSource = "precision mediump float;"
148                                            + ""
149                                            + "varying vec4 vColor;"
150                                            + ""
151                                            + "void main()"
152                                            + "{"
153                                            + "    gl_FragColor = vColor;"
154                                            + "}";
(0,1) (-1,-1) (1,-1)

Notes

Does anyone notice anything odd? We pass in red at one vertex, green at another vertex, and blue at the other vertex. Yet, the colors change continuously pixel to pixel. Varying variables values are linearily interpolated between vertices. This yields the continuous color gradient in this example.