Fragment Shaders for Different Light Styles

We’ll next discuss how fragment shaders compute the ambient, diffuse, and speculative amounts for several types of light, including directional lighting, point lighting, and spotlight lighting. These will be complete with a vertex and fragment shader pair built up as we go from simplest to more complex. The later shaders may seem long, but if you start with the simplest and follow the incremental additions, it will be easy to understand.

Note

The comments in each example highlight the change or difference from the previous step, making it easy to look and identify the new concepts.

No Lighting

We’ll start with the simplest lighting—no lighting! By this, we don’t mean everything will be black, but ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.