Game Development Reference
In-Depth Information
Lighting and Shading
So far, this chapter has covered how the GPU is given a list of vertices as well as
world transform, view, and projection matrices. With this information, it is pos-
sible to draw a black-and-white wireframe of the 3D scene into the 2D color buf-
fer. But a wireframe is not very exciting. At a minimum, we want the triangles to
be filled in, but modern 3D games also need color, textures, and lighting.
Color
The easiest way to represent color in a 3D scene is to use the RGB color space ,
which means there is a separate red, green, and blue color value. That's because
RGB directly corresponds to how a 2D monitor draws color images. Each pixel on
the screen has separate red, green, and blue sub-pixels, which combine to create
the final color for that pixel. If you look very closely at your computer screen, you
should be able to make out these different colors.
Once RGB is selected, the next decision is the bit depth , or the number of bits
allocated to each primary color. Today, the most common approach is 8 bits per
color, which means there are 256 possible values each for red, green, and blue.
This gives a total of approximately 16 million unique colors.
Because the range for the primary colors is 0 through 255, sometimes their values
will be expressed in this manner. In web graphics, for instance, #ff0000 refers to
255forred,0forgreen,and0forblue.Butamorecommonapproachin3Dgraph-
ics is to instead refer to the values as a floating point number between 0.0 and 1.0.
So 1.0 is the maximum value for that primary color, whereas 0.0 is an absence of
it.
Depending on the game, there is also the possibility of a fourth component, known
as alpha . The alpha channel determines the transparency of a particular pixel. An
alpha of 1.0 means that the pixel is 100% opaque, whereas an alpha of 0.0 means
that it's invisible. An alpha channel is required if the game needs to implement
something like water—where there is some color the water gives off in addition to
objects that are visible under the water.
So if a game supports full RGBA, and has 8 bits per component, it has a total of 32
bits (or 4 bytes) per pixel. This is a very common rendering mode for games. Fig-
ure 4.7 demonstrates a few different colors represented in the RGBA color space.
Search WWH ::




Custom Search