Game Development Reference
In-Depth Information
lighting equation needs only to consider the light direction and the
attitude of the surface. This kind of light will be your general light
that emits from a source.
Specular Light This type of light travels in a particular direc-
tion. When it strikes a surface, it reflects harshly in one direction,
causing a bright shine that can only be seen from some angles.
Since the light reflects in one direction, clearly the viewpoint, in
addition to the light direction and surface attitude, must be taken
into consideration in the specular lighting equation. Specular light
is used to model light that produces highlights on objects, such as
the bright shine created when light strikes a polished surface.
Specular lighting requires more computations than the other types of
light; therefore, Direct3D provides the option to turn it off. In fact, by
default it is turned off; to enable specular lighting you must set the
D3DRS_SPECULARENABLE render state.
Device->SetRenderState(D3DRS_SPECULARENABLE, true);
Each type of light is represented by a D3DCOLORVALUE structure or
D3DXCOLOR , which describes the color of the light. Here are some
examples of several light colors:
D3DXCOLOR redAmbient(1.0f, 0.0f, 0.0f, 1.0f);
D3DXCOLOR blueDiffuse(0.0f, 0.0f, 1.0f, 1.0f);
D3DXCOLOR whiteSpecular(1.0f, 1.0f, 1.0f, 1.0f);
Note: The alpha values in the D3DXCOLOR class are ignored when
used for describing light colors.
5.2 Materials
The color of an object we see in the real world is determined by the
color of light that the object reflects. For instance, a red ball is red
because it absorbs all colors of light except red light. The red light is
reflected from the ball and makes it into our eyes, and we therefore see
the ball as red. Direct3D models this same phenomenon by having us
define a material for an object. The material allows us to define the per-
centage at which light is reflected from the surface. In code a material
is represented with the D3DMATERIAL9 structure.
typedef struct _D3DMATERIAL9 {
D3DCOLORVALUE Diffuse, Ambient, Specular, Emissive;
float Power;
} D3DMATERIAL9;
Diffuse Specifies the amount of diffuse light this surface
reflects
Search WWH ::




Custom Search