Using lights, normals, and materials in the pipeline
We mentioned in Chapter 2, Rendering Geometry, that WebGL buffers, attributes, and uniforms are used as input variables to the shaders and that varyings are used to carry information between the vertex shader and the fragment shader. Let's revisit the pipeline and see where lights, normals, and materials fit in.
Normals are defined on a vertex-per-vertex basis; therefore normals are modeled in WebGL as a VBO and they are mapped using an attribute, as shown in the preceding diagram. Please notice that attributes are never passed to the fragment shader.
Lights and materials are passed as uniforms. Uniforms are available to both the vertex shader and the fragment shader. This gives us a lot of flexibility to calculate our lighting model because we can calculate how the light is reflected on a vertex-by-vertex basis (vertex shader) or on a fragment-per-fragment basis (fragment shader).
Note
Remember that the vertex shader and fragment shader together...