Game Development Reference
In-Depth Information
typedef struct _D3DMATERIAL9 {
D3DCOLORVALUE Diffuse;
D3DCOLORVALUE Ambient;
D3DCOLORVALUE Specular;
D3DCOLORVALUE Emissive;
float Power;
} D3DMATERIAL9;
Black Objects Everywhere? Set Your Material!
A common mistake with almost any renderer is not to set a material for your
object. Most shaders use multiplication to combine the lights affecting the
object with the object
s color. If that color is not defined, it will typically be
zeroed out to black, and as everyone knows, zero times anything is still zero.
If your game has a black background, objects without a material defined will
completely disappear from your scene!
'
Other than the critical information about needing a default material and texture, the
DirectX SDK documentation does a pretty fair job of showing you what happens
when you play with the specular and power settings. They can turn a plastic ping-
pong ball into a ball bearing, highlights and everything.
The material defines how light reflects off the polygons. In Direct3D, this includes
different colors for ambient, diffuse, specular, and emissive light. It is convenient to
wrap the D3DMATERIAL9 structure in a class, which will be used in the next chapter
to control how objects look, or even if they are transparent. Here is the source code
for the class:
#define fOPAQUE (1.0f)
#define fTRANSPARENT (0.0f)
typedef D3DXCOLOR Color;
Color g_White( 1.0f, 1.0f, 1.0f, fOPAQUE );
Color g_Black( 0.0f, 0.0f, 0.0f, fOPAQUE );
Color g_Cyan( 0.0f, 1.0f, 1.0f, fOPAQUE );
Color g_Red( 1.0f, 0.0f, 0.0f, fOPAQUE );
Color g_Green( 0.0f, 1.0f, 0.0f, fOPAQUE );
Color g_Blue( 0.0f, 0.0f, 1.0f, fOPAQUE );
Color g_Yellow( 1.0f, 1.0f, 0.0f, fOPAQUE );
Color g_Gray40( 0.4f, 0.4f, 0.4f, fOPAQUE );
Color g_Gray25( 0.25f, 0.25f, 0.25f, fOPAQUE );
Color g_Gray65( 0.65f, 0.65f, 0.65f, fOPAQUE );
Color g_Transparent (1.0f, 0.0f, 1.0f, fTRANSPARENT );
 
Search WWH ::




Custom Search