Game Development Reference
In-Depth Information
Ambient Specifies the amount of ambient light this surface
reflects
Specular Specifies the amount of specular light this surface
reflects
Emissive This component is used to add to the overall color of
the surface, making it appear brighter like its giving off its own
light.
Power Specifies the sharpness of specular highlights; the higher
this value, the sharper the highlights
As an example, suppose we want a red ball. We would define the ball's
material to reflect only red light and absorb all other colors of light:
D3DMATERIAL9 red;
::ZeroMemory(&red, sizeof(red));
red.Diffuse = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); // red
red.Ambient = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); // red
red.Specular = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); // red
red.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); // no emission
red.Power = 5.0f;
Here we set the green and blue components to 0, indicating that the
material reflects 0% of these colored lights. We set the red component
to 1 indicating that the material reflects 100% red light. Notice that we
have the ability to control the color of light reflected for each type of
light (ambient, diffuse, and specular light).
Also notice that if we define a light source that emits only blue-
colored light, it would fail to light the ball because the blue light would
be completely absorbed and zero red light would be reflected. An object
appears black when it absorbs all light. Similarly, an object is white
when it reflects 100% red, green, and blue light.
Because it is somewhat tedious to manually fill out a material
structure, we add the following utility function and global material con-
stants to the d3dUtility.h/cpp files:
D3DMATERIAL9 d3d::InitMtrl(D3DXCOLOR a, D3DXCOLOR d,
D3DXCOLOR s, D3DXCOLOR e, float p)
{
D3DMATERIAL9 mtrl;
mtrl.Ambient = a;
mtrl.Diffuse = d;
mtrl.Specular = s;
mtrl.Emissive = e;
mtrl.Power
= p;
return mtrl;
}
namespace d3d
{
Search WWH ::




Custom Search