Game Development Reference
In-Depth Information
As you might expect, a position in 3D space is a 3D vector. A normal vector is also a
3D vector, and a texture coordinate is a 2D vector. Three of those define the three
points required to render one triangle on the screen. Next let
'
s dig in to how lighting
and texturing work.
Lighting, Normals, and Color
In DirectX 11 and many other rendering technologies, you can assign colors to verti-
ces yourself, or you can instruct the renderer to calculate those colors by looking at
vertex data and the lights that illuminate the vertex. You can even do both. Everyone
has seen games that show subtle light pools shining on walls and floors
a nice and
efficient effect but completely static and unmoving. Other illumination is calculated
in real time, such as when your character shines a flashlight around a scene. Multiple
lights can affect individual vertices, each light adding a color component to the vertex
color calculation.
One of the simplest kinds of lighting is diffuse lighting, which simply adds a bit of the
light color to the native color of the triangle, depending on how it is oriented to the
light. To understand how this works, you need to know about normal vectors, which
are an important part of the vertex definition that enables lighting calculations.
When light hits an object, the color of light is added to the object
s defined color.
Perform a little experiment to see this in action. Take a playing card, like the ace of
spades, and place it flat on a table lit by a ceiling lamp. The card takes on a color
component that reflects the color of that lamp. If your lamp is a fluorescent light,
the card will appear white with a slight greenish tint. If your lamp is incandescent,
the card will take on a slightly yellowish color.
If you take the card in your hand and slowly turn it over, the brightness and color of
the card face with the spade changes. As the card approaches an edge-on orientation
to the lamp, the effects of the lighting diminish to their minimum. The light has its
maximum effect when the card is facing perpendicular to the light and its minimum
effect when the card is edge-on to the light. This happens because when light hits a
surface at a low angle it spreads out and has to cover a larger area with the same
number of photons. This gives you a dimming effect.
Diffuse lighting attempts to simulate this effect. With the card sitting flat on the table
again, take a pencil and put the eraser end in the middle of the card and point the tip
of the pencil straight up in the air, toward your ceiling lamp. You
'
ve just created a
normal vector. Turn the card as before, but hold the pencil and turn it as well, as if
it were glued to the card. Notice that the light has a maximum effect when the angle
between the pencil and the light is 180 degrees, minimum effect when the angle
'
 
 
Search WWH ::




Custom Search