Pro OpenGL ES for iOS

(singke) #1

28 CHAPTER 1: Computer Graphics: From Then to Now^


Figure 1-11a,b. Changing the vertical scaling in the vertex shader on the left, and coloring in the fragment shader
on the right.

Now for a quick look at the fragment shader, in Listing 1-3. This does absolutely nothing
and is merely a pass-through shader. However, it is here where you can intercept the
calls to each of the ‘‘fragments,’’ something like pixels at this level. Add the line
gl_FragColor.g=1.0; at the end. This will add green to every pixel in the image, looking
something like Figure 1-11b. See? That wasn’t so hard was it? Now you can proudly go
out and tell your friends that you’ve been programming shaders all day and watch the
garlands pile up around your feet.
Listing 1-3. The fragment shader.

varying lowp vec4 colorVarying;

void main()
{
gl_FragColor = colorVarying;
}
Free download pdf