Game Development Reference
In-Depth Information
0, // use top level as source for lower levels
D3DX_DEFAULT); // default filter
if(FAILED(hr))
{
::MessageBox(0, "D3DXFilterTexture() - FAILED", 0, 0);
return false;
}
return true;
}
Note that the color constant variables BEACH_SAND , etc., are defined in
d3dUtility.h.
13.4 Lighting
The Terrain::genTexture method makes a call to Terrain::
lightTerrain that, as the name implies, lights the terrain to enhance
the realism. Since we already computed the colors of the terrain tex-
ture, we only need to compute a shade factor that brightens or darkens
areas of the terrain with respect to a defined light source. In this sec-
tion we examine such a technique. You may wonder why we are
lighting the terrain and not letting Direct3D do it. There are three ben-
efits to doing the calculations ourselves:
We save memory by not having to store vertex normals.
Since terrains are static and we won't be moving the light either,
we can precalculate the lighting, thus eliminating the processing
time it would take for Direct3D to light the terrain in real time.
We get some math practice, familiarity with a basic lighting con-
cept, and practice using Direct3D functions.
13.4.1 Overview
The lighting technique we use to compute the shade of the terrain is
one of the most basic and is commonly known as diffuse lighting .We
define a parallel light source that we described by specifying the direc-
tion to the light, which is in the opposite direction of the light rays
being emitted by the parallel light source. So, for example, if we wanted
the light rays to fall straight down from the sky in the direction
lightRaysDirection = (0, -1, 0), then the direction to the parallel light is
given as the opposite direction: directionToLight = (0, 1, 0). Note that
we make the light vector a unit vector.
Team-Fly ®
Search WWH ::




Custom Search