Multiple Lights and Materials

Typically, a scene has many light sources and many surface materials. Normally, you shade one material at a time, but many lights will light that material. We’ll show a shading model where each invocation of the shader selects a material and then applies all of, or a subset of, the lights to light it.

Multiple Lights

Normally, we need to light with multiple lights, while we’ve been writing example shaders for just one. A scene might have a street light, a flashlight, and the moon, for example, with each surface fragment getting a share of light from all three. You’d likely model these three lights as a point light, a spotlight, and a directional light, respectively, and have a single shader invocation perform all ...

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.