Else generate custom shader source code the engine itself
348 Chapter 8 Lighting
these approaches and the number of uniforms that must be sent to the shader can be prohibitive for some systems. As a result, it is common for rendering engines to either generate specific shaders for the lighting cases they know they need, or else generate custom shader source code in the engine itself, compiling these shaders at runtime as they are required.
The sheer number of pixels that must be drawn per frame requires that low- to mid-end graphics systems forego computing more expensive lighting equations for each pixel in favor of another method. For example, a sphere that covers 50 percent of a mid-sized 1,280 × 1,024 pixel screen will require the shading system to compute colors for over a half million pixels, regardless of the tessellation. Next, we will discuss some of the more popular methods. Some of these methods will be familiar, as they are simply the shading meth-ods discussed in Chapter 7, using results of the lighting equation as source colors.
8.8 Lighting and Shading 349
Figure 8.14 Sphere lit and shaded by per-triangle lighting and flat shading.


