Color

CS 381 Lecture, Dr. Lawlor

Visible light is just electromagnetic radiation--it's exactly the same stuff as X-rays or radio waves.  We've just got builtin detectors for electromagnetic radiation with a wavelength from 400 (blue) to 700 (red) nanometers.

Our perception of electromagnetic radiation is actually amazingly limited.  We can hear continuous tones, and complicated combinations of tones, from 20Hz to 20,000Hz; but you can only see three separate colors--red, green, and blue.  This is suprising--there's clearly a difference between sunlight and flourescent light, but our eyes can't directly perceive it.




You can do spectral analysis using a card with a slit in it and a CD or DVD.  Here's a more complicated spectroscope you can build. Here are some images I took with a slightly better homebrew spectroscope.

Here's a CD diffracting florescent light.  Note the discrete bands--florescents display only a discrete set of wavelengths, like a musical note or chord.

Natural light, like sky light (note the inverted spruce tree sticking up into the red band!) is a continuous range of colors, like the atonal sound of water or wind.

Random asides: humans developed 3-color vision quite recently, as a way of gaining more information about plant health; most other animals see fewer colors.  A tiny fraction of humans have 4-color vision (Readable Guardian Article on tetrachromatism), although the fourth primary color is actually *between* red and green, which is kinda lame.   You can actually use your own unmodified eyes as an infrared camera, by just blocking all visible light.  Some people have only 2-color vision (color blind folks; the most common form is inability to distinguish red and green).  In the dark, we're all 1-color (monochrome) vision.

Color

So the bottom line is that for normal people, you only need three primary colors.  In additive color, they're red, green, and blue (RGB).  In multiplicative color (misleadingly called "subtractive" color), they're cyan, yellow, and magenta (CMY), usually combined with a pure black (CMYK). Here's a GIMP image of the RGB primary colors and CMY primary pigments where you can try this out.







Color in OpenGL

In glColor3f, r, g, and b are floats, with 0.0 as black and 1.0 as white. Values outside the range of [0,1] are "clamped" to lie inside [0,1].

In "fragment.txt", "gl_fragColor" is just a 4-vector containing red, green, blue, and "alpha" (which we'll talk about later).