1-7 Lighting and Colors

After drawing a model defined by the mathematical conversions explained thus far, you need to insert a light source (and shading), material properties (such as shininess), and color to make the model appear real. All objects become black in a state of no lighting. This Chapter describes how to implement color, lighting, properties, and shading in your game program.

1-7-1 Color

Colors expressed on a computer are basically composed using the three primary colors of light (red, green, and blue), that can be displayed on a luminous object like a TV screen. Other colors are created by mixing red, green, and blue together.

Figure 1-7-1 Three Primary Colors of Light

Although this illustration shows only eight colors, you can create many more by using different mixes and by changing their brightness. For example, if you slightly reduce the brightness of the mixed color of red, green, and blue, the color becomes light gray. Then, if you increase the brightness of the red, the color becomes pink. In this way, the computer expresses colors by combining three kinds of elements.

1-7-2 Lighting

For our eyes to be able to see an object, the object must be either emitting light or reflecting light. On a computer, it is difficult to represent in real time the situation where an object itself is emitting light, therefore this discussion will focus on showing you how to represent reflected light. To represent reflected light, you need to know the position and direction of light coming from the light source, as well as two other types of light: ambient light and diffuse light. The position and direction are the setting for these, from where and to which direction the source of light emits light. Ambient light and diffused light are difficult to describe, and require a separate explanation.

# Ambient Light
Ambient light is the surrounding atmospheric light. For example, the part of an object that is on the opposite side of a light source is usually not black. The reason for this is that it is lit up slightly by ambient (atmospheric) light. Ambient light occurs because surrounding objects produce irregular reflections. Ambient light has no direction, so if you give a color to ambient light, that light is reflected on everything in the scene.

Figure 1-7-2 Ambient Light

# Diffuse Light
Diffuse light is light that has been scattered through reflection or refraction. For example, transmitting a light through a translucent material diffuses the light. Diffuse lights take on the color of the translucent material that scattered the light.

Figure 1-7-3 Diffuse Light

To implement lighting, you simply set the position and direction of the source light, and also specify appropriate ambient and diffuse lights.

1-7-3 Material Properties

There are three elements that determine the materials of an object. These are ambient light, diffused light, and reflected light.

# Ambient Light
As mentioned earlier, ambient light is the color of the shadow of an object.

# Diffuse Light
Unlike the diffuse light previously mentioned, the color of diffuse light comes from the color of the substance itself. The diffuse light becomes brighter as the incident angle gets closer to a right angle.

# Specular Light
How a substance reflects light affects how shiny the object appears. A substance like chalk reflects light in all directions with equal intensity, so it appears dull. On the other hand, a substance like a mirror reflects light in only a certain direction, so it appears shiny. How shiny or dull a surface appears depends on how that substance reflects light. Shiny surfaces show a shiny spot (specular highlight) that is very bright compared to the surrounded parts because most of the reflected light comes off in a single predominant direction. N64 cannot set these elements, but pseudo-expression is possible.

Example N64 Functions (Lighting)


1-7-4 Shading

Shading is adding shadow to an object by calculating the materials and lighting. N64 implements flat shading and smooth shading (Gouraud shading).

# Flat Shading
In flat shading each surface is shaded uniformly by using the same color as illustrated here:

Figure 1-7-4 Flat Shading

This shading technique calculates the normal vector and the light source of a surface, and applies uniform color to the surface. As a result, objects will appear blocky (like computer graphics).

Figure 1-7-5 Normal Vector and Light Source

Example N64 Functions (Flat Shading)

Function Parameter
gSPSetGeometryMode G_SHADE
gSPClearGeometryMode G_SHADE

# Smooth Shading
The smooth shading technique smoothes out the shading to make it appear more realistic. Note that smooth shading affects the inside shading only; it has no effect on the outline of the object, as you can see in this illustration:

Figure 1-7-6 Smooth Shading

There are many different techniques that you could use to implement smooth shading. One of the most popular is Gouraud shading. Gouraud shading, named for its developer, gives a normal vector to each vertex of the surface. In other words, it calculates both the light source and the normal vector for each vertex. In this way, it interpolates calculated light for each vertex to make the shading appear smooth as illustrated here:

Figure 1-7-7 The difference between flat and smooth shading

By providing shading, you can put colors that are reflected from surrounding objects on your shaded object.

Example N64 Functions (Smooth Shading)

Function Parameter