Directional Light
So far we've been putting the light source near the geometry, giving it a world space position close to the model's. A light source that has a defined position is a point light. Since our lighting model depends on the light direction, we calculate it as the difference between these positions:
vec3 lightDirectionEye = normalize(lightPositionEye - mixPositionEye);
vec3 lightDirectionEye = normalize(lightPositionEye - mixPositionEye);
What if the light source is extremely far away from the geometry? At least one such light source exists: the sun.
We waste GPU cycles by computing the light direction on a per-fragment basis if there's no perceivable difference between the directions. Even giving the light source a position is unnecessary. Why not just describe its direction? A light source that is so far away that its position doesn't matter is a directional light. In GLSL, we define the direction of a directional light as a global constant or as a uniform rather than as a local variable:
const vec3 lightDirectionEye = normalize(vec3(1.0, 1.0, 1.0));
void main() {
// ...
}
const vec3 lightDirectionEye = normalize(vec3(1.0, 1.0, 1.0)); void main() { // ... }
The direction must still have unit length, so we normalize it.