The GLSL Tutorial is now available in the new layout. Check it out here.

GLSL Tutorial

Lighting

In OpenGL there are three types of lights: directional, point, and spotlight. In this tutorial we'll start to implement a directional light. First we'll start with an implementation in GLSL that mimics the OpenGL way of lighting.

We'll build the shader incrementally starting with ambient light up to specular lighting.

Ambient

Ambient + Diffuse

Specular

Then we'll move on to lighting per pixel in order to get better results.

Next we'll implement point and spot lights per pixel. These last tutorials are heavily based on the directional lights tutorial because most of the code is common.

Point Light

Spot Light

As mentioned in the toon shader tutorial GLSL offers access to the OpenGL state that contains data for the light setting. This data describes the individual light's setting as well as global parameters.