Color
Litness is a proportion measuring how much a fragment's normal points toward a light source. A value of 1 means the surface receives 100% of the light. This line from the fragment shader effectively reflects all of the received light back into the viewer's eye:
fragmentColor = vec4(vec3(litness), 1.0);
fragmentColor = vec4(vec3(litness), 1.0);
In the physical world, not all light is reflected. Some is absorbed. The proportion of light that a surface reflects is its albedo. In computer graphics, albedo is effectively the surface's base color. A surface with an albedo of \(\begin{bmatrix}1&1&0\end{bmatrix}\) reflects all red and green light and absorbs all blue light. Its base color is therefore yellow.
This fragment shader takes into account a surface's albedo. It applies the litness proportion to the albedo to compute the diffuse term:
uniform vec3 albedo;
// ...
void main() {
// ...
vec3 diffuse = litness * albedo;
fragmentColor = vec4(diffuse, 1.0);
}
uniform vec3 albedo; // ... void main() { // ... vec3 diffuse = litness * albedo; fragmentColor = vec4(diffuse, 1.0); }
The albedo here is a uniform. Sometimes albedo is defined per vertex and comes into the fragment shader as an interpolated value.
Just as a surface's material properties influence the light that reaches the eye, so does the light source itself. The light source generates some combination of red, green, and blue wavelengths. The light color is another set of intensities that should be considered in the diffuse term, just like the albedo:
uniform vec3 diffuseColor;
uniform vec3 albedo;
// ...
void main() {
// ...
vec3 diffuse = litness * albedo * diffuseColor;
fragmentColor = vec4(diffuse, 1.0);
}
uniform vec3 diffuseColor; uniform vec3 albedo; // ... void main() { // ... vec3 diffuse = litness * albedo * diffuseColor; fragmentColor = vec4(diffuse, 1.0); }
In the previous renderers, the light color has been implicitly white. Now we can make the light whatever color we like. The interaction between albedo and light color can be difficult to reason about, however. Consider this torus with a magenta albedo:
The diffuse light color is orange, which cancels out all the blue frequencies from the magenta albedo, leaving only red.