We've seen shading with a constant color for the entire model, and we've seen shading with a different color for each vertex. Texture mapping enables a different color for each fragment.
This entails the addition of a texture coordinate attribute to the vertex shader, plus a texture coordinate varying to communicate this attribute from the vertex shader to the fragment shader.
precision mediump floatuniform mat4 projectionMatrixuniform mat4 viewMatrixuniform mat4 modelMatrixattribute vec4 vertexPositionattribute vec2 vertexTexCoordvarying vec2 fragmentTexCoordgl_Position ← projectionMatrix · viewMatrix · modelMatrix · vertexPositionThe image reference is then made per-fragment using a sampler uniform.
precision mediump floatvarying vec2 fragmentTexCoorduniform sampler2D modelTexturetexture2D(modelTexture, fragmentTexCoord)gl_FragColor ← modelColor